SerialPort.Read(…) does not respect ReadTimeOut

前端 未结 1 551
暖寄归人
暖寄归人 2021-01-20 01:54

Got a bug in some legacy code which communicates with a payment terminal.

Just before a new payment is started, the code attempts to clear the internal read buffer o

相关标签:
1条回答
  • 2021-01-20 02:36

    maybe adding a test on port's 'bytes to read' may help steer clear of badly coded drivers:

    length = (_serialPort.BytesToRead > 0) ? _serialPort.Read(buffer, 0, 512) : 0;
    

    better still, use

    _serialPort.DiscardInBuffer();
    

    instead!

    0 讨论(0)
提交回复
热议问题