# Read Serial Port Continuous, Timer Script and Instrument Interface

**URL:** <https://forum.inductiveautomation.com/t/read-serial-port-continuous-timer-script-and-instrument-interface/16945>\
**Category:** Ignition\
**Created:** [February 9, 2018, 9:39pm UTC](https://forum.inductiveautomation.com/t/read-serial-port-continuous-timer-script-and-instrument-interface/16945 "2018-02-09T21:39:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dano38291](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dano38291](https://forum.inductiveautomation.com/u/dano38291)\
**Post date:** [February 9, 2018, 9:39pm UTC](https://forum.inductiveautomation.com/t/read-serial-port-continuous-timer-script-and-instrument-interface/16945/1 "2018-02-09T21:39:51Z")

</div>

This Project file is far from complete. It can be used as a starting point for others. I have some questions below. My goal is to write a Ignition Client so a User can plug their laptop into a Mettler Toledo XS lab scale using an USB to Serial converter. There's a Reset Scale button that sends a "@" to reset the Scale. Also a Weight Button to send a "SIR" to make the scale report its weight continuously.

**I did not know how to make Ignition event driven based on new data at Serial Port. With Rockwell PLC instructions I can test the Serial buffer for CR, then Read the entire buffer including the CR. Is there a similar Serial Buffer Test in Ignition or in the Instrument Interface?** So I had to use a Timer script, the 1-10ms interval appears to work.The Timer script uses a readUntil('\r',0,100) to read until the CR that the [SerialTest (2018-02-09)Timer Script.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/34547e2a2b39948b9bc6f3d6dee89232281fa46e.proj) (17.7 KB)

At least this project handles Opening, Closing of Serial Port and a few buttons to handle Resetting Scale or making it Report its weight Continuously.

**I need to figure out the console exceptions it throws below based if data is not at Serial port it will throw the following**

> _Caused by: java.lang.Exception: Exception encountered while reading from serial port: Delimiter not matched before timeout/EOS._  
> \_ at com.sepasoft.parse.components.PMISerialController.readUntil(PMISerialController.java:634)\_  
> \_ at sun.reflect.GeneratedMethodAccessor126.invoke(Unknown Source)\_  
> \_ at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\_  
> \_ at java.lang.reflect.Method.invoke(Unknown Source)\_  
> \_ at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:186)\_  
> _... 14 common frames omitted_

I could live with the Above Exception on the console. I need to write some other code to check for Serial Port is Open or Closed before I try to write out of that port.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 10, 2018, 4:41pm UTC](https://forum.inductiveautomation.com/t/read-serial-port-continuous-timer-script-and-instrument-interface/16945/2 "2018-02-10T16:41:06Z")

</div>

For others finding this topic, see [this older thread](http://forum.inductiveautomation.com/t/how-to-listen-serial-data-without-interruption/15709).

---

<div class="post-metadata">

**Author:** ![dano38291](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dano38291](https://forum.inductiveautomation.com/u/dano38291)\
**Post date:** [February 12, 2018, 3:20pm UTC](https://forum.inductiveautomation.com/t/read-serial-port-continuous-timer-script-and-instrument-interface/16945/3 "2018-02-12T15:20:00Z")

</div>

Thanks Turmel. I will have to dig into that code you posted.

I was hoping some one would get back to me on how to configure the Instrument Interface to do this Continuous Serial Port monitoring. I believe its a feature(Accept Unsolicited Request) of Instrument Interface based on what I heard at the 2:00 min mark from this video. [http://www.sepasoft.com/video-library/5-1-2-serial-settings/](http://www.sepasoft.com/video-library/5-1-2-serial-settings/)

The company I work for has already purchased an Instrument Interface license, I will try to give Sepasoft a call. See if they solved this problem or I have to do the custom code solution.

---

<div class="post-metadata">

**Author:** ![dano38291](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dano38291](https://forum.inductiveautomation.com/u/dano38291)\
**Post date:** [February 13, 2018, 7:21pm UTC](https://forum.inductiveautomation.com/t/read-serial-port-continuous-timer-script-and-instrument-interface/16945/4 "2018-02-13T19:21:36Z")

</div>

I got some help from SepaSoft and they pointed me in the direction of using Unsolicited Reads to constantly monitor the serial port. They also recommended to make sure I do not have Polling turned on. I dropped some code into the onReceive() event in the Serial Controller based on SepaSoft recommendation. The event.stringData was what I was missing.[SerialTestUnsolicited (2018-02-13).proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c76ff54da052ad38fa5543fce94db2f8a15c4972.proj) (32.1 KB)

> rr = event.stringData  
> system.tag.write('ScaleString',rr)  
> print rr

I have attached a Demo project to pull data from a Mettler Toledo XS Balance. This demo project should work with any Mettler Toledo scale that uses the MT-SICS command set. The project uses the @, SIR, UPD commands to Reset, Continuously Output, and Change Update Rate.

I had to turn down the Update Rate on the Scale from 10 Updates a Second to 4.5 Updates a second so that the Instrument Interface could read in each weight string as an individual string and not a long string of multiple weights.
