[SOLVED] Get NMEA sentence (system.serial)

Hello,

I’m still quite new to Ignition (using 8.0.17), one of the subjects I’m having troubles with is getting NMEA0183 sentences from a sensor. I guess the sensor is connected as it should as I can use the manufacturer utility to read values and it works. The wiring is through a RS422 Half-Duplex serial interface card into a Hatteland screen (Norwegian marine brand) which has a quite unclear documentation.

Now, I’m trying to get those data into Ignition which is much harder. I did call the sensor manufacturer to make sure that all configurations set with configureSerialPort are correct.
I also looked into those topics here on the forum:

  1. How to listen serial data without interruption
  2. readBytesAsString Error
  3. Help with system.serial.readUntil

I’m trying to validate the code into the script console without much success, here’s the code (I tried system.serial.configureSerialPort and with system.serial.port) :

I should maybe mention that the first line in the interpreter (on the right) doesn’t appear while using with system.serial.port code, probably normal though. I tried reading with either one of the lines in the picture but I couldn’t get any positive results from that.

I tried everything I could think of and I still fall short of a solution. In all I could find about the serial communication scripting on the forum, I did not see much people having issues connecting in the first place so I guess I should ask for help connecting :slight_smile:

Can this kind of code be tested in the Script Console?

Thank you very much for your help.

I think would need more info to start to help.

  1. Are you connected to the gateway? This will not work from a client.
  2. The try and except stops the console from saying what part of your code is causing the issue. What does it show if you try it without the try/except.
  3. What should the data from your serial device look like?
  1. Yes, I am connected to the gateway. I actually only have one client that is on the gateway.
  2. Didn’t try without the try/except, will do!
  3. Example lines from the documentation shows:
    $IIMWV,266.0,R,000.0,N,A*0B or $WIXDR,C,022.0,C,,*52

By the documentation, I don’t think system.serial.readLine() will work for you. Its says it is looking to be terminated by a line feed or carriage return. Unless it sends one but the document doesn’t show it, I don’t believe this one will work for you.

I’d try the line you commented out for system.serial.readUntil but I’d use chr(42) to look for the *. See if that pulls back anything. If it does, then you can use split functions to pullout the section of the string you want.

Actually it does end with CR,LF according the sensor documentation:

I tried the readUntil with chr(10), chr(13) and chr(36) and none of them returned something other than the error in the picture in my first post.

I already wrote the code with the split and it doesn’t worries me too much, I know it will work with few experimentations. I just removed thqt as it was generating other errors since the reading doesn’t work.

I’ll try right now, the script without the try/except and report back.

Thanks for your help :slight_smile:

Here is the error below with out the try/except but it seems the problem is opening the port for some reason.
I did validate that I am connected to port COM6 I asked the manufacturer yesterday if my port parameters were correct and they are according to them.

com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule$SerialConfigurator@2381540a
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 10, in <module>
	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.openSerialPort(SerialScriptModule.java:258)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: failed to open port: COM6


	at org.python.core.Py.JavaError(Py.java:552)

	at org.python.core.Py.JavaError(Py.java:543)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)

	at org.python.core.PyObject.__call__(PyObject.java:480)

	at org.python.core.PyObject.__call__(PyObject.java:484)

	at org.python.pycode._pyx43.f$0(<input>:12)

	at org.python.pycode._pyx43.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.io.IOException: failed to open port: COM6

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.openSerialPort(SerialScriptModule.java:258)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)

	... 19 more

Traceback (most recent call last):
  File "<input>", line 10, in <module>
	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.openSerialPort(SerialScriptModule.java:258)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: failed to open port: COM6

EDIT:
It seems now it is working without changing the code to test. I just tried stopping the COM port and restarting it. Looks a bit like victory and I must run as it is late here in France.
I’ll update the topic with further developments and eventually the code that works for me in case it helps others.

That’s it for now, thanks bpreston!

It seems that I’ve got an other problem, my serial module is in trial and it seems to cause an issue.
Could anybody confirm that it is required to get a license to have this working?

com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule$SerialConfigurator@692b84de
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 10, in <module>
	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.checkTrialExpired(SerialScriptModule.java:154)

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.readLine(SerialScriptModule.java:428)

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.readLine(SerialScriptModule.java:402)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

com.inductiveautomation.ignition.modules.serial.scripting.TrialExpiredException: com.inductiveautomation.ignition.modules.serial.scripting.TrialExpiredException: Serial module trial period has expired.


	at org.python.core.Py.JavaError(Py.java:552)

	at org.python.core.Py.JavaError(Py.java:543)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)

	at org.python.core.PyObject.__call__(PyObject.java:497)

	at org.python.core.PyObject.__call__(PyObject.java:501)

	at org.python.pycode._pyx60.f$0(<input>:13)

	at org.python.pycode._pyx60.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: com.inductiveautomation.ignition.modules.serial.scripting.TrialExpiredException: Serial module trial period has expired.

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.checkTrialExpired(SerialScriptModule.java:154)

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.readLine(SerialScriptModule.java:428)

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.readLine(SerialScriptModule.java:402)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)

	... 19 more

Traceback (most recent call last):
  File "<input>", line 10, in <module>
	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.checkTrialExpired(SerialScriptModule.java:154)

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.readLine(SerialScriptModule.java:428)

	at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.readLine(SerialScriptModule.java:402)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

com.inductiveautomation.ignition.modules.serial.scripting.TrialExpiredException: com.inductiveautomation.ignition.modules.serial.scripting.TrialExpiredException: Serial module trial period has expired.

To sum up the resolution, I had a problem because the COM port was occupied and then I got the failed to open port: COM6.

Once the COM port is available, I did reset the module trial in the webserver (http://localhost:8088/web/config/system.modules?) and then started again with the following script:

system.serial.configureSerialPort(\
port = "COM6",\
bitRate = system.serial.BIT_RATE_4800,\
dataBits = system.serial.DATA_BITS_8,\
handshake = system.serial.HANDSHAKE_NONE,\
hardwareFlowControl = False,\
parity = system.serial.PARITY_NONE,\
stopBits = system.serial.STOP_BITS_1)
system.serial.openSerialPort("COM6")
#sentence = system.serial.readLine("COM6", 10000)
#sentence = system.serial.readUntil("COM6", chr(10), False, 10000)
sentence = system.serial.readBytesAsString("COM6",242,500)
system.serial.closeSerialPort("COM6")
print(sentence)

#with system.serial.port("COM6", bitRate = system.serial.BIT_RATE_4800, dataBits = system.serial.DATA_BITS_8,
						#handshake = system.serial.HANDSHAKE_NONE, hardwareFlowControl = False,
						#parity = system.serial.PARITY_NONE, stopBits = system.serial.STOP_BITS_1) as COM_port:
	#sentence = COM_port.readLine("COM6", 10000)
	#sentence = COM_port.readUntil("COM6", chr(10), False, 10000)
	#sentence = COM_port.readBytesAsString("COM6",242,500)
	#print(sentence)

For reference, both system.serial.configureSerialPort() and with system.serial.port() as port: works. I entend to use the later but used the first helped me to make sure I close the port while debugging.

To clear things a bit, I chose to get 242 characters because it is twice the length sent by the sensor and then I locate the beginning of the sentence I’m looking for so I’m sure the sentence is complete. All is required from there is to keep the desired length.

The result in the interactive interpreter looks like this:

com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule$SerialConfigurator@692b84de
$PLCJ,6500,65FF,AA,4343,4343

$PLCJE86C8,6DA7,2B00,2165,9D,

$IIMWV,269.0,R,000.6,N,A*36

$WIXDR,C,032.0,C,,*53

$PLCJ,6400,64FF,AA,4343,4343

$PLCJE86C8,6DA7,2B00,2165,9D,

$IIMWV,269.0,R,000.6,N,A*36

$WIXDR,C,032.0,C,,*53

$PLCJ,6400,65FF,
>>>

Hope this will help anybody who has issues with this.

1 Like