bugst / go-serial

A cross-platform serial library for go-lang.
BSD 3-Clause "New" or "Revised" License
617 stars 188 forks source link

[Question] How to check whether Write has completed transmitting the buffer? #143

Open markandpathak opened 1 year ago

markandpathak commented 1 year ago

TL,DR: Does write function block till complete message is transmitted? if not How can we check whether the complete write buffer has been transmitted or not? and if write is pending how may bytes have been sent or remaining?

There are generally two buffers in the Linux based hardware. One is the hardware buffer and other one is the buffer provided by kernel. Certain applications require to perform a task once data is sent and where RTS/CTS lines are not available. i.e controlling transceiver IC through transmit enable line(DE). We have to control DE line through GPIO as board UART port does not have RTS/CTS lines. Immediately changing state of DE line after write call may cause partial transmission if write is nonblocking.

If write function blocks until complete buffer is transmitted then it is not a concern. But if not, how can I ensure complete message delivery? Calculating time delay based on baud-rate is one option but I'm looking for more robust way.

Using library on Linux.

KiddoV commented 2 months ago

Sounds like this method p.Drain() is what you are looking for?