[fpc-pascal] Reading Serial Hex Data

José Mejuto joshyfun at gmail.com
Mon Dec 28 17:23:57 CET 2020


El 28/12/2020 a las 2:02, James Richters via fpc-pascal escribió:
> I think I figured out why my writeln's are causing an issue.. they are introducing a delay between the SerWrite and SerRead...
> and the device I am reading is timing out and sending it's response a second time.

Hello,

None of the serial devices I have seen do something like that, in fact 
usually they do exactly the opposite, fire and forget, or in other words 
send a message and do not check for errors unless they wait for an 
answer from the host.

Your problem seems to be or a documentation misinterpretation or the 
connection or the device is not using any kind of flow control.

> I was under the impression that there was a hardware buffer on the serial ports, my packets are very small,
> some only a few bytes, but even those are not going into any kind of a hardware buffer.

Hardware buffers in serial device is 16 bytes (In fact 14 for receive) 
at most and it is managed by the Windows serial driver to garantee no 
byte is lost. The operation scheme is something like:

1- Serial byte received
2- IRQ signal issued
3- Windows serial driver read serial port and copy byte(s) to driver buffer.
4- Signal IRQ as handled.

The 16 bytes hardware (FIFO) buffer is present to garantee that if steps 
between 2 and 4 takes too much time (this is time scaled in 1990's CPU 
power) no byte is lost. If an Intel 8088 can read 115200bps without any 
byte lost think what a today computer can read.

In order to perform tests there are programs where you create an hex 
string to be sent and inspect the answer from the device. Read 
documentation about how to open the port, specially about the flow 
control sync. XOn/XOff, RTS/CTS. In example some need that you raise the 
RTS line and wait for CTS line to be high before write, if you do not 
wait the device can misinterpret your request and hang or answer 
something stupid, this is automatically done by the Windows serial 
driver if you select the RTS/CTS flow control when open the port.


Have a nice 2021!

-- 



More information about the fpc-pascal mailing list