Check if serial port is listening

I have instructions to send and receive Arduino using a Python script through the serial port.

Arduino accepts the state of the button, and when it is pressed, it will send a message through the serial port to a Python script and wait for a response. (through Serial.available()). It works quite well.

However, if the Python script crashes for some reason (ideally it will work in the background, so it cannot be easily checked), Arduino will always wait and will be unavailable even for a restart script.

Is there a way so that my Arduino can check if there is something listening on the serial port? (and warn me with blinking lights, etc. if not), or is that not how the series works? Worst case, I think I could use a timeout, although this is not ideal.

+5
source share
3 answers

You have limited ability to determine if there is something listening on the other hand using DSR / DTR pins.

When you open the serial port on the computer on which your scripts are running, it should raise its DTR output (or you must convince it of this: the library documentation that you use to control the COM port should indicate how).

, Arduino, DSR (, - , DTR DSR + CD Arduino) , " ", , .

, script , / , DTR , - . , script Arduino - .

always - : , , ( ).

( , DSR ), , .

+6

Arduino DSR , , .

+1

mdb , -, , /, , -. ( ircd Ping-Pong).

0

All Articles