Currently I put a script in gateway startup script to call a few scripts and run different threads in the background. Got the inspiration from Phil’s clientserial.py
(How to listen serial data without interruption)
Now, am trying to use the following command to read continuously from a serial port whereby some sensors will send some NMEA 0183 protocol sentences continuously via RS422 serial port :
system.serial.readUntil(port, chr(36), False, 1000)
So far had been able to read correctly if the sentences are good.
However, i encountered two cases which need advice.
1)In the event that the sensor does not send anything, an exception occurs as such
ERROR:root:java.io.IOException: Delimiter not matched before timeout/EOS. 16:14:12.185 [MainThread] ERROR com.inductiveautomation.factorypmi.application.script.builtin.ClientSystemUtilities$4$1 - <HTML>Error running function from <code>fpmi.system.invokeAsynchronous</code> com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "<event:actionPerformed>", line 190, in serialProcess at com.inductiveautomation.ignition.modules.serial.scripting.SerialScriptModule.readUntil(SerialScriptModule.java:402)
Wonder, how could I bypass this error?
Because I wish the program to be able to continue to continuously read from the serial port until something appears or perhaps until x seconds later, if still didnt receive anything, then it will stop reading.
2)In the event that a very long string without $, that is sent from some unknown device or say the sensor is spoilt, the system.serial.readUntil will keep on reading non stop even though after several minutes. It keeps on reading the very long string that is without $, and the program wont execute the next line of the program,
Wonder how is it possible to stop it from reading after some time when it cannot find the delimiter ? Is there an interrupt or use another thread to set a timer or something such that after x seconds later, then it will stop reading since it cannot find the $ ? I am not sure how it can be done.
Greatly appreciate for any kind advises