-
Notifications
You must be signed in to change notification settings - Fork 143
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
Flushing read buffer on Open #172
Comments
So I modified the above code by adding a function to "eat" any messages at the start. There has to be a better way then random 500 counter in my example.
|
Hi @mrspirytus , there are indeed a few methods in addition to what you have identified to flush the hardware buffers, although I'm not quite sure why calling
|
Helllo again @mrspirytus , after you call |
I am going to try your suggestion in a min and get to you in a few. But so you know about your second comment. My GPS data is coming at 1Hz. When I open same port with GTKSerial and moserial app I get the same behavior. as your library. And, based on GPS data being publish 1Hz if I wait 10sec and start program I get 10 messages right away and so on. I am not sure what the upper limit is, but based on my earlier test trying to eat them on start I did see as much as ~470 |
Ok, so I added this line to my last example
So I still see readStaleData() getting about 77 messages before it times out EDIT: Btw, I am testing on Ubuntu 20.04 (Linux spirytus 5.4.0-52-generic 57-Ubuntu) Here are parameters I am using
|
Hello @mcsauder I also found another strange issue. Not sure if you want me to open a new ticket. Let me know. nmeaString are more often than with Here is pgk version I am using
|
EDIT: @mrspirytus , I misread what your wrote above. Can you check that '\r' and not '\n' or '\r\n' is the line ending you are actually receiving? |
@mcsauder I am little puzzled by your comment. I am using '\r'. Should this make it better with my solution to "eating" stale data on start? |
@mcsauder Ok so I did the first run. I replaced |
Hi @mrspirytus , I'm still not sure what's going on with your setup. There is a unit test in place to test flushing the input buffer, libserial/test/SerialPortUnitTests.cpp Line 233 in 1d1e47a
Let us know if you have any other thoughts or details that might be useful. |
Yup, I have a scope with logic. Just so you know. The module I am using is a USB to the serial version. I did enable (programmed) the module to start sending GPS points when it is powered on. |
Cool. What I want to know is if it's been sending data the whole time uninterrupted, or if there is a burst of data when the port is opened. If there is no change in the data send rate when the port is opened, then we know the hardware buffer is not obeying the posix command to flush. |
Hi @mrspirytus , were you able to determine when data is being transmitted per my comment above? Is this still an issue for you? |
Opps, sorry I dropped the ball. I got a work around to read bunch of messages and dropping them until first timeout. That seems to work well. Of course not optimal solution but I had to move on to other tasks. I should revisit this again. Do you have any suggestions what and where I should look at? Just wondering. |
I seems like your hardware isn't honoring the posix command and is not actually flushing the buffer to me. Without knowing your hardware setup it is tough to know, however. If you have an oscilloscope, just watch the data lines to verify that your device is just sending data at its' given rate. If that is the case your hardware buffer isn't actually flushing when being commanded to do so by the OS. |
I am using SerialDevice. I have same behavior on rPI4 Ubuntu server 20.04 and NVIDA Nano 18.04. I believe I had same issue on my workstation also running 20.04. |
There is no class named SerialDevice in libserial. Can you clarify? |
Correction: SerialPort |
Update. I will be working on a different project so I can revisit this again. In this case, it will be reading binary vs ASCII data. But I can look with scope to original issue |
@mcsauder I will start looking at this issue. Just letting you know I did not forget :) I am reading from GPS device (USB to serial). Each NMEA string is terminated with "\r\n". Once in a while, I am getting a garbage line. Looks like one-two incomplete NMEA strings on top of each other. The strange thing is that I used moserial app and I do see the same behavior once a while. The strange this is that with minicom I do not? Hmm. I am capturing all data using minicom -C to file and will look closer. The only change in the initial source example above is
To read on proper message boundaries. Let me know if you ever experienced this and if you want me to open a new ticket. I will post later on my findings of minicom recordings. |
So I captured 56304 GPS points using minicom and no issue. |
Hmmmm. It's possible that libserial is causing an issue, but it's also possible that minicom is not reporting one.... I'll see what I can replicate. Would you be willing to try again with picocom? |
I just installed it and running test. Will let you know soon
|
So I collected 44132 NMEA strings
|
I am still looking and testing... |
Hello,
I am using version 1.0 and noticed something I was hoping there is a built int solution? or if you can suggest a solution.
I have a GPS device sending data every 1Hz to ttyUSB0. I can process data just fine.
Problem:
When I start my test application I get sometimes a lot (what is queued up messages) after Open(). I do start reading data after open without any delay.
When I quit and restart my application right away I do not see any data queued up.
When I quit my test app and wait a minute and start I right away see a bunch of messages and then I get updates 1Hz expected.
Is there a way to "eat" all messages right after Open() so I do not read stale data and start processing the latest data? I did try to use _tty.FlushIOBuffers() but that did not help
I get the value of 0 for the above prints, but when I got to reading I get a bunch of then and then to 1Hz update. Is FlushIOBuffers() the right call to use? If not what is the best way to handle it and what is the purpose of FlushIOBuffers() since we are on this subject as well :)
The text was updated successfully, but these errors were encountered: