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

Bo Berglund bo.berglund at gmail.com
Fri Sep 8 14:54:33 CEST 2017

On Fri, 8 Sep 2017 13:06:16 +0100, el es
<el.es.cr at gmail.com> wrote:

>I would decouple the log display from the serial handling routines -
>by delegating the serial task to a thread, only display of log is handled in
>the main thread (this is true whether your application is cli-only or gui - 
>have the tasks that should not be interrupted, like bulk serial communication, 
>handled by a thread, and whatever the thread wants to display, use a buffer (like TThreadList) to
>communicate to the main thread.

Yes, when I saw this I figured that the data handling should be done
in a thread.
However, I am not at all sure how this can be accomplished.
Basically all of the activity is handled inside my RelayData()
function. This is where the Tcp and RS232 data are crossfed and also
where I call the logging function.

But if I create a thread and put this function into it, how would that
work concerning access to the IdTcpClient and Serial objects? They
were set up and connected in the main application and nothing but the
actual data handling needs to be put inside the thread if it can
communicate the logging info in a way that makes it non-disturbed.

But how?
I have 4 TStaticText controls that show the accumulated byte counts in
the Rx and Tx channels of the socket and comport. These are updated in
RelayData(). And of course I have the listbox displaying the data
going back and forth. I think that the problem is in the listbox,
which will get more and more data as time goes by...
Probably I should have some other logging/display system here.

I have very limited experience with threads and then these did not
interact at all with any GUI functions.

Bo Berglund
Developer in Sweden

More information about the fpc-pascal mailing list