So basically I have a console application running in background listening to a specified serial port (device: barcode-scanner connected via USB, mapped as serial port). The attached SerialDataReceivedEventHandler works as supposed. However, as soon as the computer goes into stand-by/hibernate and re-activates, apparently no data is sent anymore (SerialDataReceivedEventHandler does not trigger). If I check the SerialPort object, everything seems to be fine (same attributes, same event handler, connection still open). I also noticed that the connection seems to timeout (after several hours) anyway.
Connection
...
{
SerialPort serialPort = new SerialPort(port);
serialPort.BaudRate = 9600;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.DataBits = 8;
serialPort.Handshake = Handshake.None; // tried RequestToSend as well, no difference
serialPort.DataReceived += new SerialDataReceivedEventHandler(MySerialPortHandler);
serialPort.Open();
...
}
static void MySerialPortHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort serialPort = (SerialPort)sender;
string inData = serialPort.ReadExisting();
...
}