COM port Transmit Buffer - Bytes Remaining ?

For issues with communication ports, protocols, etc.
jmg
Posts: 79
Joined: Mar 11, 2009 3:42

COM port Transmit Buffer - Bytes Remaining ?

Postby jmg » Jul 10, 2015 11:12

Hi,
I have a FreeBasic app all working, but I found it was dropping characters, and tracked that down to
too little time from last PUT to CLOSE.
Test show the added forced delay time needed varies with BAUD, but I find 95ms is OK for 57600 and 25ms is ok for 250000 Baud.
That's roughly the time to send 512 bytes, which is about the USB HW buffer size.

The problem is, using a fixed delay is clunky, and I'd rather (somehow?) check the Transmit process and wait till done.
I cannot find any FreeBasic or even windows calls that report how many bytes are left ?.

To complicate this, most modern serial ports are USB, and there are multiple buffers in play.

The outermost hardware buffer, Windows probably cannot even see, and that is not fixed size, but varies with Hardware Device.

Has anyone found a better way to manage timing of CLOSE so the stream is not truncated early, dropping chars ?
SeaVipe
Posts: 26
Joined: Dec 22, 2015 19:13

Re: COM port Transmit Buffer - Bytes Remaining ?

Postby SeaVipe » Jan 04, 2016 19:19

jmg wrote:Hi,
I have a FreeBasic app all working, but I found it was dropping characters, and tracked that down to
too little time from last PUT to CLOSE.
Test show the added forced delay time needed varies with BAUD, but I find 95ms is OK for 57600 and 25ms is ok for 250000 Baud.
That's roughly the time to send 512 bytes, which is about the USB HW buffer size.

The problem is, using a fixed delay is clunky, and I'd rather (somehow?) check the Transmit process and wait till done.
I cannot find any FreeBasic or even windows calls that report how many bytes are left ?.

To complicate this, most modern serial ports are USB, and there are multiple buffers in play.

The outermost hardware buffer, Windows probably cannot even see, and that is not fixed size, but varies with Hardware Device.

Has anyone found a better way to manage timing of CLOSE so the stream is not truncated early, dropping chars ?


Hi jmg,
Did you resolve this issue? I have a similar problem with RS232 data.
jmg
Posts: 79
Joined: Mar 11, 2009 3:42

Re: COM port Transmit Buffer - Bytes Remaining ?

Postby jmg » Jan 04, 2016 19:32

Hi jmg,
Did you resolve this issue? I have a similar problem with RS232 data.

Only with the work-around, of doing a (Baud+Data) variable delay.
That seems to work well, with a minimum value plus some usual OS wobble.

Even on systems that can check for TxBuffer, that is only the Windows value, and the UART Bridge devices have their own buffers too.

I tried a handshake echo, but even there the handshake is not fully sync'd with data, on all UART bridges, and using handshakes costs quite a bit of time due to USB packet quanta.
SeaVipe
Posts: 26
Joined: Dec 22, 2015 19:13

Re: COM port Transmit Buffer - Bytes Remaining ?

Postby SeaVipe » Jan 04, 2016 23:55

Thanks jmg, very helpful.
Dinosaur
Posts: 975
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: COM port Transmit Buffer - Bytes Remaining ?

Postby Dinosaur » Jan 05, 2016 20:25

Hi All

I have found many issues with Tx & Rx buffers in FB, but simplicity is the best solution.
If you are communicating with a device that sends replies, then save yourself the waiting time.
Simply send a command that requires a very short reply, and immediately close the port after you receive a valid reply.
That is IF you even need to close the port for whatever reason.

Regards

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest