-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method to wait until all data is physical sent by the driver #119
Comments
Thanks for the report. Flushing the driver has a few problems, which is why the original design doesn't do this. I could make a new API as opt-in. The biggest problem when flushing at hardware level is when hardware flow control is active. I've seen quite a few drivers just hang, ignore timeouts completely and unblockable thus leading to deadlocks that I can't recover from. If I create a new API, this will be a big caveat, that timeouts may be ignored. |
Meanwhile I've subscribed with reflection to TX_EMPTY event from your library but it doesn't help :). |
I've implemented a new API called |
Thank you very much! I will try to test it out next days in my RS485 communication. I will let you know the results. |
I have tested and it doesn't seem to work properly... |
Hmm, then MS Docs don't work as advertised. Looking here PurgeComm, it says
So I use FlushFileBuffers. This could indicate a problem in the driver itself? But I've seen FTDI implement pretty good drivers. |
Have you been able to investigate further? I looked at the PDF you recommended. My implementation is already using an I/O thread that uses overlapped I/O. The flush implementation first waits for the software buffer to be empty (the same implementation for Are you able to try with different serial devices, or provide sample code you use to test, that I might be able to translate for testing with a normal RS232? |
Closing, as there hasn't been any activity. Unfortunately, my changes made as per MSDN documentation didn't work as expected. |
Hello,
This post might be duplicated with #99 . I'm implementing a RS485 protocol for long distance communication. I have a master and multiple slaves and I use the RtsEnable pinout from my FT232RL USB cable to set the MAX485 into Write or Read mode. So the flow is something like: I put master in Write mode, I write X bytes, then I put master in Read mode waiting for slave to answer.
Everything works fine but I just realized that if I write more bytes (let's say 64 bytes on a 9600 BAUD), even if I call .Flush, the Flush seems to only copy the bytes from local SerialPortStream class memory buffer to the OS driver buffer. At 9600 BAUD we have 1 byte sent every 1 ms (10 bits per byte). So I have to sleep another 64 ms to make sure that the bytes are actually sent from OS driver on the physical wire. But the thing is that in some languages (I use C#) sleep is not very accurate. Even SpinWait is slightly inaccurate these days with variable CPU frequency.
I was thinking that maybe you can implement a method which will wait for the bytes to be physically sent over the wire from the OS driver buffer (probably tcdrain from #99 post).
Thanks a lot for this library!
The text was updated successfully, but these errors were encountered: