B4J Question Async streams - buffer size

rspitzer

Active Member
Question about the async streams when using a serial port.

What is the received buffer sizer? Is there a way of setting this, or what is the default?
 

rspitzer

Active Member
I have a concern about the Jserial library as written. I work in machine control, unfortunately in my world there are millions of legacy controllers still using the standard RS232 serial port. I write programs as front ends for operators of industrial control equipment, and the serial ports are in a constant state of transmission on all the platforms. At 9600 baud a bit is transmitted every .000104 microsecond, and a byte at 000833 microseconds. Which would technically mean the Async Streams are being interrupted with a new byte every .000833 microseconds. The Jserial Library contains ReadingThreadInterval, this interval is defaulted to 10 milliseconds, which is aproximately 12 bytes of data at 9600 baud. I will be experimenting with this setting, since my reads of the serial port should be when I receive at least 60 bytes of data. This should at least in theory prevent unnecessary interruptions. My concern is that there seems to be no error checking? Since I don't know anything about the receive buffer size, if the foreground program is busy with some other event or Async Stream, there is no way to check for a buffer overrun error and of course parity errors. I have written programs using the compact framework that monitors 6 continuous serial ports and two network ports (TCP data) and also gives the operator the ability to write his own control programs for various PLC's.
Is there a error check that I have missed, since none is implemented in JSerial, and I may have missed something in the Async Streams?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is very difficult to read your post.

AsyncStreams, in non-prefix mode (which is not relevant here), doesn't do any error checking or internal buffering. However data will never be lost. You will always receive all the data that was read.

Check B4XBytesBuilder from B4XCollections. It will help you collect the incoming data and analyze it.
 
Upvote 0

rspitzer

Active Member
I apologize for the difficulty in reading my post. If there is anything I can do to clear the post up let me know, what you are having difficulty with. As far as your suggestion on using B4XBytesBuilder, I am already using it, a very nice method to gather the data.

The real issue, is "Data will never be lost" statement, unfortunately in the real world of control systems, this is not the case. I have worked on some systems that are considered OSHA and EC hazardous. To me it would have been nice to have Jserial implement common error checking techniques for serial ports (Industry Standards) , I don't like being put in the position to trust data without some type of hardware verification. Anyway, thank you for the response.
 
Upvote 0

rspitzer

Active Member
I understand what you are saying, the issue still is that even though the data is not lost, is the data correct? That's what serial port error checking is about. The hardware will check the received bytes for parity issues, stop bits issues, buffer over run issues etc, the hardware will report this if a method is there to the serial port handler. Anyway, this is not implemented in the current Jserial method, so that what it is.
 
Upvote 0
Top