0

I am making a C# application that talks to a hardware device using the .NET System.IO.Ports.SerialPort interface (the device is connected to the USB port on my laptop using a serial -> USB converter) and one of the steps my application needs to do is change the baud rate from the factory default (38400) to the the one it will eventually need to be using (19200).

So I open the port using the initializer, set the port's baud rate to 38400; everything connects fine, I get coherent messages from the hardware. When I go to change the baud rate on the device to 19200, again, everything works perfectly, I get back a non-garbled message even though I didn't change the baud rate on the port (on my PC side). I feel like they should be speaking different languages at this point.

But when I manually change the port's settings after I change the device's settings (long after the port is open), I then get garbled messages, even though the baud rates should now be aligned. My question is: does .NET somehow automatically know the baud rate changed on the hardware side? Am I fundamentally misunderstanding how all this works?

speedfranklin
  • 126
  • 1
  • 8
  • Most cases for automatic detection sends a message at each baud rate until an expect results comes back. – jdweng Nov 18 '20 at 15:46
  • Is that happening constantly? I don't see any garbled messages in between the different baud rates – speedfranklin Nov 20 '20 at 01:24
  • Initially the device is not going to send any data until it gets a valid character. The UART has error bits if rate is wrong and device is not going to send any thing until it gets no errors from UART and it see an expected characters followed by a return at end. Once device detects a rate, it stops searching for rate and assumes bad data are errors in transmission and attempts to correct the bad data. – jdweng Nov 20 '20 at 03:11

0 Answers0