Hello;
I am using an application which is written in C#. this application supposed to run in a smart phone and communicates with two devices via 2 bluetooth using serial ports. First, the code was written to communicate with one device, and the in the application by choosing the correct com port, I could receive data nicely. Now I duplicate the code for the second serial port. but this caused a problem. There is no any error in compiling the code, the crash caused when I run the application in the smart phone and choose the ports and start to communicate! I could figure out which part of code caused a problem:
// This is for the first port
private void spPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{ //MessageBox.Show("Data is Flowing 1 ...", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
//this.Invoke(new InvokerDelegate(ShowNewData), new object[] { spPort.ReadExisting() }); this.Invoke(new InvokerDelegate(ShowNewData));
}//This is for the second port
private void spPort2_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) {
//MessageBox.Show("Data is Flowing 1 ...", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk,
MessageBoxDefaultButton.Button1);
//this.Invoke(new InvokerDelegate(ShowNewData), new object[] { spPort2.ReadExisting() }); //this.Invoke(new InvokerDelegate(ShowNewData)); //if this be uncommnet, cause a crash!
}If I comment out the last line, then there is no any crash on the smart phone. and just I can open and close the second port without receiving any data.
By reading forums, I understand there is a problem in communication with Multu serial port in the C#, and i read some where by adding the begin before Invoke, I should be fine!
this.BeginInvoke(new InvokerDelegate(ShowNewData));It is true, by there is a long delay in receiving data! I want to be in the real time, no delay!!
Is any body can helpme, i can upload whole of my code if necessary.
I also appreciate if you introduce me any book regarding this issue (multi -Serial port)
Thanks in advanced;