[fpc-pascal] Reading Serial Hex Data

Bo Berglund bo.berglund at gmail.com
Sun Dec 27 23:08:00 CET 2020


On Sun, 27 Dec 2020 10:47:59 -0500, James Richters via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:

>I'm trying to figure out how to read a packet of HEX Bytes of an unknown
>length that have no specific termination character over a serial port as
>efficiently as practical.

What exactly do you mean by HEX Bytes?
Hex transfers using two characters for each byte? like 1F A4 etc?

>The packet ends when there is just no more data to read.
>
>I have something that is working that I wrote using SerRead from the Serial
>unit in FPC, and it works at 9600bps,

If you use the serial unit and just read the data coming in using
blocking calls you will not miss anything, what you do not read will
stay in the input buffer until you read again.
If you need to do something inbetween then you can put the reading in
a thread so that is handled there and then transfer the data to the
main thread via a synchronize call to a receive function there.

Is your program a console or GUI program?


-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list