Skip to content
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

flush() does not work for Windows and Linux #161

Open
vasek-cz opened this issue Oct 3, 2017 · 4 comments
Open

flush() does not work for Windows and Linux #161

vasek-cz opened this issue Oct 3, 2017 · 4 comments

Comments

@vasek-cz
Copy link

vasek-cz commented Oct 3, 2017

According to your documentation the flush() function should flush both input and output buffers. However both for Windows and Linux platforms it doesn't work properly - buffers are not cleared.

Correct and tested implementation:

Windows
PurgeComm(fd_, PURGE_RXCLEAR | PURGE_TXCLEAR);

Linux
tcflush(fd_, TCIOFLUSH);

@sirop
Copy link

sirop commented Nov 16, 2017

Because of

If hFile is a handle to a communications device, the function only flushes the transmit buffer.

in case of BOOL WINAPI FlushFileBuffers( In HANDLE hFile )
and

The tcdrain() function shall block until all output written to the object referred to by fildes is transmitted.

in Linux case?

@sirop
Copy link

sirop commented Nov 16, 2017

Confirmed on Windows 8.1:

// port, baudrate, timeout in milliseconds
  serial::Serial my_serial(port, 38400, serial::Timeout::Timeout(0,1,0,0,0));

  if(my_serial.isOpen()) {
    cout << port << " opened? " << " Yes." << endl;
    my_serial.flush();
    string result = my_serial.read(72);
    if (result.length()>0) 
        std::cout << result.length() << endl;
   }

always yields 72, which means that my_serial.flush(); does not function as new 72 bytes cannot be delivered within 1 ms read timeout if the flush was successful before.

sirop added a commit to sirop/serial that referenced this issue Nov 19, 2017
sirop added a commit to sirop/serial that referenced this issue Nov 19, 2017
sirop added a commit to sirop/serial that referenced this issue Nov 24, 2017
sirop added a commit to sirop/serial that referenced this issue Nov 24, 2017
@wjwwood
Copy link
Owner

wjwwood commented Jan 13, 2018

Thanks for reporting the issue and for trying to confirm it with an example.

It sounds like you have a suggested solution, please open a pull request:

https://help.github.com/articles/creating-a-pull-request/

Thanks!

@sirop
Copy link

sirop commented Jan 14, 2018

@wjwwood
If I am addressed, please give me a day or two,

alextoind added a commit to alextoind/serial that referenced this issue Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants