CodingHero
Programmer
I'm using the SerialPort class to help simplify communications between a PC GUI and an external embedded device I'm working on. My main form is subscribed to the data receive event (SerialDataReceived) of the SerialPort class so I can process messages asynchronously. I've noticed that I occasionally get a "zero length packet" even though I've set a minimum receive threshold of two bytes. Setup code is as follows:
I suppose this isn't an out-and-out problem, as I can just examine the BytesToRead property of the SerialPort and discard a zero length message, but does anyone know what would cause this to occur?
As some added information, my embedded device is actually connected via USB, but identifies as a virtual COM port using the usbser.sys driver that ships with Windows XP. Perhaps it's just a bug with that but I haven't seen anything searching Google to confirm or deny that.
Thanks in advance for any help!
Code:
mySerialPort = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.One);
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(mySerialPort_DataReceived);
mySerialPort.ReceivedBytesThreshold = 2;
I suppose this isn't an out-and-out problem, as I can just examine the BytesToRead property of the SerialPort and discard a zero length message, but does anyone know what would cause this to occur?
As some added information, my embedded device is actually connected via USB, but identifies as a virtual COM port using the usbser.sys driver that ships with Windows XP. Perhaps it's just a bug with that but I haven't seen anything searching Google to confirm or deny that.
Thanks in advance for any help!