Hi, I have a very weird problem here, maybe you guys can help me out. I have a Windows CE 6 device that uses a barcode card reader connected through a serial port. I'm using the Compact Framework's (v2.0) SerialPort class to handle this, and everything has been working fine.
There's one problem, however. If a card is swiped at any point before the serial port is opened, the entire system freezes at the Open() call. No exceptions, no warnings, just a complete system freeze for no reason. I tried clearing the buffers before opening the port but apparently that method can only be used after the port has been opened because I got an InvalidOperationException.
I made a simplified version of the code to see if the complexity had anything to do with it, but a simple form with a button that opens the port will freeze in the same way. Here's the simplified code:
private void btConnect_Click(object sender, EventArgs e)
{
try
{
this.serialPort = new SerialPort(this.txName.Text, Convert.ToInt32(this.txBaud.Text));
this.serialPort.RtsEnable = this.chRTS.Checked;
this.serialPort.Open(); //it freezes here
this.btConnect.Text = "Disconnect";
this.txName.Enabled = false;
this.txBaud.Enabled = false;
this.chRTS.Enabled = false;
}
catch
{
MessageBox.Show("Failed to open port. Please check your settings and try again.", "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}}
I can't see what I'm doing wrong, I'm starting to think that it's a bug in the compact framework. The card reader sends packets such as F03030DKD03003\r\n. Any ideas? Thanks in advance.