Hi,
I have an application where I read a serial port data from a barcode
and set the labels on a form. I also have a textbox and button where
you can enter the data and here is the problem. if I use the textbox
and submit using thebutton everything works fine. If I use the
SerialDataReceivedEventHandler method of the serial port, the
application crahes. It seens like that when the serial port triggers
and I call the same routines it is not aware of the form elements and
hence the application hangs up. Any body has ideas on what is the fix?
if I debug, I get the following message on when I go over the label in
the routine
AutoEllipsis = Function evaluation disabled because a previous function
evaluation timed out. You must continue execution to reenable function
evaluation.
Here is the code
namespace ShippingLabel
{
public partial class xxxx : Form
{
SerialPort sp = new SerialPort();
public NDES2()
{
InitializeComponent();
System.Windows.Forms.Control.CheckForIllegalCrossT hreadCalls = false;
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.ReadTimeout = 1500;
sp.DataReceived += new
SerialDataReceivedEventHandler(sp_DataReceived);
sp.Open();
}
void sp_DataReceived(object sender, SerialDataReceivedEventArgs
e)
{
try
{
string ret = "\r";
string ID = sp.ReadLine().Replace(ret, "");
sp.Close();
TheNumber.Text = ID;
Generate_Label(ID);
sp.Open();
}
catch
{
ErrorLabel.Text += "Scanner Communication Failed";
sp.Close();
}
}
public void Generate_Label(string theNumber)
{
myLabel.text = theNumber;
}