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

Baud Rate Configuration fails silently #51

Closed
benjaminpaik opened this issue May 5, 2022 · 2 comments
Closed

Baud Rate Configuration fails silently #51

benjaminpaik opened this issue May 5, 2022 · 2 comments

Comments

@benjaminpaik
Copy link

benjaminpaik commented May 5, 2022

I'm currently porting an app from Java/Swing to Flutter that running on Windows 11 that communicates with devices via serial. For the most part, everything works as expected. Occasionally, however, the baud rate doesn't set correctly. No errors are reported and calling the baud rate getter after opening the port returns the intended baud rate. Measuring the baud rate with an oscilloscope shows 9600 regardless of what I actually set the baud rate to in the code. The problem persists even after closing and reopening the app, restarting my PC, swapping USB/Serial converters, and changing which USB port the converter is plugged into. Interestingly, I can resolve the issue by opening the COM port in Putty (or any other application that uses the serial port). Once I have done this, the Flutter app again works as expected (for a couple of days) before the issue arises again. I've posted a snippet of my initialization code below for reference. (This was done with flutter_libserialport version 0.2.3).

try {
  comPort = SerialPort(serialPort);
  comPort.config = SerialPortConfig()
       ..baudRate = baudRate
       ..parity = parity
       ..bits = bits
       ..stopBits = stopBits;
  comPort.openReadWrite();
 } catch (e) {
     print(e.toString());
}
@mortenboye
Copy link

See #29 for a possible solution:
UPD: As I seen in libserialport examples, seems the config should be set after opening the port.

@benjaminpaik
Copy link
Author

Thanks. It looks like your suggestion worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants