I am preparing a project where I will use RS-232 to control a device using Arduino Uno. I am just wondering if there is any logic already built-in to auto-reconnect in case the serial connection is lost with the device? Should I build some logic around this (move Serial.begin within loop() for example)?
pdube:
...logic already built-in to auto-reconnect in case the serial connection is lost with the device?
No.
The Arduino will not care if anything is 'listening' to the serial TX output or not.
The only way you can tell if your 'serial connection is lost' is by some handshake with that device.
i.e. you send it something and expect it to reply. If it does not reply within some timeout period, then you could presume it is 'lost' and try again.
You do not need to call Serial.begin() again.
However, if you are going to be using the USB serial, the Arduino is RESET when USB is reconnected.
pdube:
I am preparing a project where I will use RS-232 to control a device using Arduino Uno. I am just wondering if there is any logic already built-in to auto-reconnect in case the serial connection is lost with the device? Should I build some logic around this (move Serial.begin within loop() for example)?
TIA
RS-232 is not used to control a device. The data sent/received may be used to control something.
Perhaps if your were a little more specific, you would get a better answer. RS-232 is an electrical connection protocol. Are you asking if the electrical connections are open, can the Arduino recognize this? Answer is no, as already given.
Or are you asking if the Arduino can determine if the device on the other end of the RS-232 is powered and ready to operate? The answer is maybe. If your data protocol is written to always expect a response to a transmission and nothing is received, then you know the logical connection is broken or perhaps the electrical connection is broken.
TonyWilk:
No.
The Arduino will not care if anything is 'listening' to the serial TX output or not.
The only way you can tell if your 'serial connection is lost' is by some handshake with that device.
i.e. you send it something and expect it to reply. If it does not reply within some timeout period, then you could presume it is 'lost' and try again.
You do not need to call Serial.begin() again.
However, if you are going to be using the USB serial, the Arduino is RESET when USB is reconnected.