Some strange characters in the serial port

Hi there

Had connected a serial port RS422 from one pc using hyper terminal to send text string to another pc(Ignition 7.9.1) via serial port RS422 to RS232 converter.

At first I am able to read all the text string received using the following script(the script is run as a client timer script @ 1ms).

import jarray, traceback
from java.lang import String, Thread
from java.util import Date
import system
import sys
import time
import re

port="COM1"
system.serial.configureSerialPort(\
port="COM1",\
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(port)
readLinestring = system.serial.readLine(port, 10000, "UTF8")
print readLinestring

But alas, there is a power trip cause by my colleague and when the two pc started again, when the script is run again, there is an error as follows:
“Serialio Library: version 10.2.3: build 9233
Copyright (c) 1996-2015 Serialio.com, All Rights Reserved.
os.name=“Windows 7” os.arch=“x86”
java.lang.UnsatisfiedLinkError: no jspWin in java.library.path: Native library load failed jspWin trying user’s folder
java.lang.UnsatisfiedLinkError: Can’t load library: C:\Users\stmuser\jspWin.dll: Check that native library jspWin is in proper directory
java.lang.UnsatisfiedLinkError: no jspWin in java.library.path: Check that native library jspWin is in proper directory”

And the serial function did not work any more.

I try running the code on a script console and replacing the “system.serial.readLine” with system.serial.readBytesAsString

However, when the content is printed out, it shows all the funny character as follows:

Then I try to use the hyperterminal (on the Ignition pc) to try to receive the message string from the other pc(hyperterminal), the hyperterminal(on the Ignition pc) is receiving all correctly.

Finally I try using Ignition(on the Ignition pc), and running the timer script, it is working again.

The text string that is sent from another pc hyperterminal is as follows
"

$GPMSK,318.0,A,100,M,245
$PGRME,15.0,M,45.0,M,25.0,M
1C
$GPXTE,A,A,0.67,L,N*6F
"

Would anyone please kindly enlightened me what is going on or what has happended?
And how could I prevent such error from happening?
Or if such error occurs, how to clear or reset the serial port so that it will work again with Ignition?

Thank you

Best regards

A quick google search of the above error brought many results. Check out the link below. It may hold some clue...

Maybe get the Instrument Interface. I like being abstracted from some of the low level details of the Serial Port.
I can talk to Mettler Toledo Scales(Lab Balances), Sotax ST-50’s, Vector Pan Coater(legacy Serial Printer Port).
I think you might be able to get the Instrument Interface on trial like rest of Ignition?

I do use the Unsolicited Read feature and not Polling Feature. Sometimes I parse using the Instrument Interface Parse Template(simple Strings). Other Devices like the Sotax prints a 70 line Header then up to 23 Rows of Sample Data, so I just use Python functions to parse the data.

Don’t worry about that Unsatisfied link error… I see it all the time and use the serial module. Its annoying but not a problem.

First off, 1ms is going to be way too fast… hopefully you meant 1 second?

The output looks like a case of mis-match bitRate or some other serial config. I would double check all your code matches you serial config first.

Thanks for all the kind replies

Just that it is really strange as
1)It was working initially for the serial port and the serial module script.
2)due to some reason, perhaps improper shut down of the Ignition and the PC and the connection of the serial port(because of power trip), after that , it went haywire, readLine doesnt read anything, while readByteAsString gives all the strange characters, plus that “java.lang.UnsatisfiedLinkError” that pops up.
3)when tried again on both PCs to communicate again using hyper terminal on both pcs, it went smoothly
4)after that when tried using the Ignition, same script and same port settings, nothing change, it is working again for both the readLine and the readByteAsString.

Anyway, I always leave the serial port open and didnt close it in any case.

For the Serial module, when the data is sent to the serial port, is it placed in some buffer first before Ignition serial command tries to read from the serial port?
Is there a way to initialise the serial port or to clear the buffer on first startup?

Noted that the client timer script @ 1ms is too fast. The devices actually is 1s and 10ms but i dont have those actual devices/sensors. The devices are actually some sensors sending out in NMEA0183 protocol ascii string format to Ignition pc serial port.

So what i did is that i have collected the actual data from the actual devices via hyper terminal laptop. Then I tried to simulate it by putting all those sentences in hyperterminal and sent it all at one go from another pc’s serial port to the Ignition server pc serial port.

The problem in doing so, it seems somehow, the readLine is missing some characters starting from the second line and subsequent line onwards. Only the first line reads perfectly and printed out all the characters string on the console correctly, from the second line onwards, the sentences printed on the console are missing some characters. Eg the second line maybe the first and/or second character missing, the third line maybe subsequent characters missing and so on, so the lines became shorter and shorter and then comes a time it will read the whole sentence (all the characters are there) and again after that line, some characters missing again. That is why i put the timer as 1ms but still it doesnt solve the problem. refer to below screenshot to see what i meant.

I have not tried putting the readLine data in a dataset or list to check if all the data (that is read from the serial port) are there or not.

Wonder what could be the caused of the problem and to solve it?

Also I need to store all those data. What is the best way of storing the data for a few months? Do I put it in dataset or a list and then transfer it to database? Or put it in a memory tag that is a dataset type?

The serial port(trying to read those incoming data) as follows:

$GPMSK,318.0,A,100,M,245
$PGRME,15.0,M,45.0,M,25.0,M
1C
$GPXTE,A,A,0.67,L,N6F
$GPMSK,318.0,A,100,M,2
45
$PGRME,15.0,M,45.0,M,25.0,M1C
$GPXTE,A,A,0.67,L,N
6F

By the way, there are about 20 serial input ports that I am trying to monitor and read from with a time out of 10s.

Does it mean that i need to have 20 different timer script(with different port settings/configuration) to read all the 20 input ports?
Or is there any better way to do this?

Thank you

best regards
Mic

Is it NOT possible to Publish this data as MQTT payload and consume it in Ignition?.

With the pace you are suggesting, you probably need a background task, not a timer event. Something like this:

Thanks for all the kind replies

Noted that timer event might not be the way to go.

Not sure if MQTT payload could be used as the data that are coming in are in ascii text strings format and not in binary bytes and there isnt any acknowledgement from the devices.

Will take a look at the background thread even though not familiar with thread( and background thread) and also I’m not using Instrument Interface

Thank you

A node-serialport implementation using an MQTT client for sending and receiving serial data.:

Hello pturmel,

I would really appreciate some help in order to reproduce clientserial.py code.
My question basically is where to put import and logger declarations.

Getting following error: “NameError: global name ‘Thread’ is not defined”

This is my ClientStartup Script:

if ipAddr in ['192.168.32.135']:

system.tag.write('[Client]someFolder/Port', 'COM1')
toledoHeaders = ["t_stamp", "Weight", "PrevWeight"]

import sys, jarray, traceback
from java.lang import String, Thread
from java.util import Date
from org.apache.commons.lang3 import StringEscapeUtils

logger = system.util.getLogger('project.clientserial')

project.clientserial.background(project.clientserial.monitorToledo, 'someFolder')

Place the entire contents of clientserial.py into a project script module.

Thanks for your reply pturmel,
I’m sorry if maybe asking for something trivial.
I placed the entire contents of clientserual.py into a project script called ‘clientserial’
Calling the function from a button script:

system.tag.write('[Client]someFolder/Port', 'COM1')
clientserial.background(clientserial.monitorToledo, 'someFolder')

The client session crashes after pressing the button.
Trying to realise if something else is missing.
Since I don’t have acces to Help->Diagnostics;
What would be the best way to debug this kind of issue?

clientserial.background() must be run in its own thread via invokeAsynchronous. That post was intended as inspiration for a solution–it isn’t complete on its own, and the details are very application dependent.