flutter_packages icon indicating copy to clipboard operation
flutter_packages copied to clipboard

[linux_serial] unclear timeout behaviour

Open Markus43 opened this issue 6 months ago • 3 comments

I have a usecase where I need to communicate with devices to identify them, and I can't rule out that sometimes a device doesn't give me replies at all. This is where the timeout behaviour of the serial port becomes important, in order to not loose time and get performant behaviour. So I tried to find out how this library behaves regarding timeouts. In makeRaw you are setting:

    ptr.ref.c_cc[VMIN] = 0;
    ptr.ref.c_cc[VTIME] = 0;

In makeRawAndSetBaudrate you are setting:

    ptr.ref.c_cc[VMIN] = 1;
    ptr.ref.c_cc[VTIME] = 100;

According to https://man7.org/linux/man-pages/man3/termios.3.html -> noncanonical mode, the first case means polling read (give back what is available) while the second case means to block until the first character was received and then to have 10 seconds (unit is tenth's of seconds) timeout between characters. The second case is used as soon as a baudrate has been configured.

I'd like to understand the reasoning behind these settings - what did you have in mind here? Would you consider adding a configurable timeout to this library, or would you at least accept a PR that implements such a feature?

Markus43 avatar Dec 13 '23 15:12 Markus43