COM port Transmit Buffer - Bytes Remaining ?

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

COM port Transmit Buffer - Bytes Remaining ?

Post by jmg »

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: 28
Joined: Dec 22, 2015 19:13
Location: Western Canada
Contact:

Re: COM port Transmit Buffer - Bytes Remaining ?

Post by SeaVipe »

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: 89
Joined: Mar 11, 2009 3:42

Re: COM port Transmit Buffer - Bytes Remaining ?

Post by jmg »

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: 28
Joined: Dec 22, 2015 19:13
Location: Western Canada
Contact:

Re: COM port Transmit Buffer - Bytes Remaining ?

Post by SeaVipe »

Thanks jmg, very helpful.
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: COM port Transmit Buffer - Bytes Remaining ?

Post by Dinosaur »

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
Post Reply