Buffer limit in the Serial module or system.serial.readBytesAsString or where is the limit?

Hi there
Good day

Wondering if there is a buffer size limit to the Ignition Serial module ? Is it possible to increase it?
What is the maximum number of bytes that can read using system.serial.readBytesAsString ? Is it possible to increase it?
https://docs.inductiveautomation.com/display/DOC79/system.serial.readBytesAsString

Because when a string of lines(ASCII format) is sent from one pc via the hyperterminal through RS422 serial COM port to the other pc with Ignition application running the following code to read from the serial port,
the string of lines(ASCII format) was broken up into 4 different parts. Had tried sending for every second the same amount of lines - and to read it.
I tried running the script as client timer script. Also i tried running it as a thread from a button click and keep running to read the serial port.
Both methods yield the same result - what was read was broken into 4 parts.

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)
readstring = system.serial.readBytesAsString(port, 500, 1000)
print readstring

The few lines of sentences sent are as follows:

$GPRTE,,,,,*78
$GPDTM,W84,,00.0000,N,00.0000,E,,W84*41
$GPGGA,032014.00,0118.7595,N,10401.3918,E,1,11,1.6,29,M,,M,,*55
$GPDTM,W84,,00.0000,N,00.0000,E,,W84*41
$GPGLL,0118.7595,N,10401.3918,E,032014.00,A,A*6C
$GPDTM,W84,,00.0000,N,00.0000,E,,W84*41
$GPRMC,032014.00,A,0118.7595,N,10401.3918,E,0.0,284.8,200718,0.2,E,A*38
$GPVTG,284.8,T,284.6,M,0.0,N,0.0,K,A*2D
$GPZDA,032014.00,20,07,2018,-08,00*49

But what was read/printed onto the output console is as follows

$GPRTE,,,,,*78
$GPDTM,W84,,00.0000,N,00.0000,E,,W84*41
$GPGGA,032014.00,0118.7595,N,10401.3918,E,1,11,1.6,29,M,,M,,*55
$GPDTM,W84,,00.0000,N,00.0000,E,,W84*41
$GPGLL,0118.7595,N,10401.3918,E,032014.00,A,A*6C
$GPDTM,W84,,00.0000,N,00.00
00,E,,W84*41
$GPRMC,032014.00,A,0118.7595,N,10401.3918,E,0.0,284.8,200718,0.2,E,A*38
$GPVTG,284.8,T,284.6,M,0.0,N,0.0,
K,A*2D
$GPZDA,032014.00,20,07,2018,-08,00*49

In the script, after the code system.serial.readBytesAsString, i added another line of code
print “Completed read”

So the result became very obvious that is it split into 4 parts.

$GPRTE,,,,,*78
$GPDTM,W84,,00.0000,N,00.0000,E,,W84*41
$GPGGA,032014.00,0118.7595,N,10401.3918,E,1,11,1.6,29,M,,M,,*55
Completed read
$GPDTM,W84,,00.0000,N,00.0000,E,,W84*41
$GPGLL,0118.7595,N,10401.3918,E,032014.00,A,A*6C
$GPDTM,W84,,00.0000,N,00.00
Completed read
00,E,,W84*41
$GPRMC,032014.00,A,0118.7595,N,10401.3918,E,0.0,284.8,200718,0.2,E,A*38
$GPVTG,284.8,T,284.6,M,0.0,N,0.0,
Completed read
K,A*2D
$GPZDA,032014.00,20,07,2018,-08,00*49
Completed read

But i check that usually for windows , the serial buffer is 4096 bytes.
Also I checked that the above original string, the number of bytes is around 463.

Had tried changing to
readstring = system.serial.readBytesAsString(port, 1000, 1000) but it is still the same

Thus wonder what could be the reason that after receiving/read from the serial port, the chunk of sentences is split into 4 parts?

Wonder where is the limitation? Or what is the cause ?
How is it possible to increase or set the buffer size?

Thank you very very much for any advises or reply

Try increasing the timeout (second parameter).

The function should return when you’ve read either the number of bytes asked for or the timeout elapses, whichever first.

2 Likes

You are almost certainly not going to succeed with this approach. You will need to maintain a buffer for any partial line between reads, and passing completed lines to a nested function. No matter what buffer size the OS or Ignition sets.

Hi Kevin
Thanks for your reply
Had already tried increasing the timeout to 10s ie 10000 but it still unable to read the whole chunk in one go, it still breaks it up into 4 parts except that it takes longer time to do that because of the increase in time out.

Hi Phil

Thanks again for your kind reply.

Beg your pardon but i dont really understand what do you mean by [quote=“pturmel, post:3, topic:19656”]
need to maintain a buffer for any partial line between reads
[/quote]

Where about is the buffer(as in is it referring to the windows buffer)? how to access and store to the buffer? Could not seems to find anything or reference to buffer in the Ignition 7.9 user manual.
Wonder how could it be done or implemented in Ignition?

Would appreciate any kind advise or pointers.

Thank you very much

If you are using a loop in a thread to do all the reading, the buffer can just be a jython variable initialized to an empty string before the loop. You concatenate that with the result from readBytesAsString() to build up your incoming lines, and then split off complete lines from the beginning of that variable to pass on to your line parsing code. An incomplete line is left in the buffer to be processed the next time through the loop.

If you aren’t using a loop, you’ll have to retrieve the previous partial line from a memory tag or other persistent location each time your timer is called, process however many complete lines you end up with, then save any remaining fragment back to the persistent location.

1 Like

Dear Phil

Thanks
Currently, using a loop running in a thread to do all the reading.

I got what you mean. Somehow seems to get it to work using this method(using the buffer for any partial line between reads).

Thank you so much for all your advises and attention.