본문 바로가기

카테고리 없음

Python Serial Readline Example Java

Java readline example

Hi thereHad 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). 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. 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,2 45$PGRME,15.0,M,45.0,M,25.0,M1C$GPXTE,A,A,0.67,L,N 6F$GPMSK,318.0,A,100,M,245$PGRME,15.0,M,45.0,M,25.0,M 1C$GPXTE,A,A,0.67,L,N6FBy 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 youbest regardsMic.

Python Serial Readline Example Java

Serial Readline Python

Import serial# this port address is for the serial tx/rx pins on the GPIO headerSERIALPORT = '/dev/ttyAMA0 '# be sure to set this to the same rate used on the ArduinoSERIALRATE = 9600def main:ser = serial.Serial( SERIALPORT, SERIALRATE)while True:# using ser.readline assumes each line contains a single reading# sent using Serial.println on the Arduinoreading = ser.readline.decode( 'utf-8 ')# reading is a string.do whatever you want from hereprint(reading)if name 'main ':main.