C# – How to properly timeout when communicating with a serial-port device

cserial-porttimeout

I am using a serial port communication C# windows application. I wrote a program to get the data from the port, to manipulate it and write through the serial port.

My question is in case the unit is not powered on, the power supply is disconnected, or the unit is not responding to commands for a long time, how will I know? In my program, I have written for normal flow of execution. But in case there is no response for long time, the program keeps on waiting for a long time. I used a timer but it doesn't work properly.

Can anyone help me please?

Best Answer

If you are using the "SerialPort" object in C#, then you can use the ReadTimeOut and WriteTimeOut Properties.

Related Topic