[fpc-pascal] Using Serial in a TCP/RS232 gateway, how to set buffer sizes?

Bo Berglund bo.berglund at gmail.com
Wed Sep 6 20:35:29 CEST 2017


I have created a simple application which relays data from an
application I am debugging in Windows7 to/from a remotely located
embedded data system.
I use the built-in fpc Serial unit to handle the serial data and an
Indy10 TIdTcpClient for the network part.
Data coming in on the serial port are mirrored out to the remote TCP
server and data returned from that server are mirrored to the serial
port.
The Windows application only uses RS232 for this type of
communication.
At the remote location I have a Raspberry Pi uint where I have
installed and configured ser2net to do the same job in the remote
location.

My relaying application displays the number of bytes received and
transmitted on the interfaces so I can see what is going on.

This scheme has worked fine for most commands and data transfers I
have checked, but now I have run against a brick wall...

There is a pair of commands designed to read and write a large section
of the system CMOS RAM memory (where the data file system resides).
When I try to write a 1 Mbytes big buffer the byte count in my relayer
does not reach the correct number. The Windows application I am
debugging sends all of the bytes out the serial port (I have logged
this), but the relayer seems to lose some data and therefore the
transfer fails. The binary protocol specifies at the start how many
bytes are to be transferred (0x0FF000 or 1044486 decimal), then it
sends the data followed by a two-byte checksum. The data system shall
respond with NAK or ACK depending on the outcome of the checksum
verification.
The problem is that when the Windows app is done sending the data
system is still missing many kilobytes....
So no ACK is returned, it is still in receive mode.

Now I am looking at the Serial unit in order to figure out how buffer
sizes influence the performance. Apparently both Tx and Rx buffers are
set (hardcoded) to 2048, which feels like a bit low to me.

Is there some hidden property that makes it possible to increase this
value?
What is the maximum size one can set it too?


-- 
Bo Berglund
Developer in Sweden




More information about the fpc-pascal mailing list