Serial Port error while sending message

Just downloaded, so will look at it. Thank you

1 Like

You said you’re getting error 103. Error 103 is “Hardware detected a break condition."

I’m a little late to the game here, but perhaps I have some insight might be useful.

Resetting microcontrollers can be a little tricky since, in most cases, the serial port associated with then actually disappear briefly. When that happens, there will be no event that one could use to detect such a situation. What that means, on Windows for example, is that your COM port ceases to exist for a little while, and your SerialDevice is no longer valid (but not nil), and trying to do anything with the port will result in an error. I don’t remember if simply closing and connecting the port works. I have a feeling that it doesn’t, otherwise I would probably do that in CoolTerm (it’s been a while since I’ve had to deal with that :grinning:). To get around this reliably, you should re-acquire your serial connection (with SerialConnection1.Device = 
 ) and then connect. That’s what CoolTerm does. Note that SerialDeviceAt() might not work since any new port usually appears at the end of the list. I.e. the port index of the port you previously selected may no longer be the same after it reappears. SerialDevice.WithName() should be more reliable since the port name usually doesn’t change when a device disappears and then comes back.

Now, there are things you can do to detect if a port disappears or re-appears. In CoolTerm, I’m using a 200ms timer that monitors SerialDevice.Count, and if that changes, acts accordingly:

  • when a port disappears, it checks if the port is used by any open terminal windows, and if the port is currently connected, it closes the connection.
  • when a port appears, it checks if that port was previously in use by any of the open windows, and if so, it reconnects if it was previously connected before the port disappeared.

Adding this simple mechanism solved a lot of headaches for CoolTerm users with microcontrollers, such as Arduino, ESP32’s etc. Resetting an attached microcontroller causes CoolTerm to temporarily close the connection until the controller reboots and the serial port appears again. This also works, when someone unplugs their USB/serial adapter and then plugs it back in.

1 Like

Coding defensively and anticipating a disconnect is so important. In my ERP software, you could literally reboot the database server and the users would most likely not even notice.

2 Likes

Thanks for the input, this is a side project so it may take some time to get back into but definitely will give a try.