Question

When I go into the serial settings, the serial connection is closed. If I select the wrong baud rate for the serial coming in the app freezes and I can't even get any debug since it is still working but I am unsure what it is doing.

Ultimately, my question is how to check if the baud rate selected is correct and how to make sure the serial does not freeze my application.

Was it helpful?

Solution

I finally got it to throw an error. When it is trying to call sp.ReadLine(); it says that ReadLine() has timed out. I have the timeout at 500.

I just used:

try {
  data = sp.Readline();
}
catch (TimeoutException errorEvent)
{
  //Write to console the errorEvent (This operation has timed out)
  //Message to user to pick correct baud
  tbConsole.AppendText(Environment.NewLine);
  tbConsole.AppendText("Incorrect Baud Rate: Please select a new baud rate");
  tbConsole.AppendText(Environment.NewLine);
  tbConsole.AppendText(errorEvent.Message);
  tbConsole.ScrollToEnd();
  //Show baud rate settings dialog
}

OTHER TIPS

Unfortunately selecting the incorrect Baudrate is a PEBKAC because you can't stop the user from doing the wrong thing if you are allowing them to select it.

I think the only real way to make sure they select the correct baud rate, is to not let them select it if you have control of the hardware, give them a choice of the hardware they are using and configure the baud, dts, xon etc from that rather then let them specify.

If I recall correctly, the SerialPort runs on another thread and Posts events back to your UI. So if your baud rate is not correct it's possible that you may be getting incorrect data because of this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top