I am facing issue with the serial port communication issue, actually it was working till yesterday but now its giving me error, you can see the code in below. Actually the error is generating during calling method.
this.serialPort1 = new SerialPort("port1", 9600, Parity.None, 8, StopBits.One);
if (!this.serialPort1.IsOpen)
{
this.serialPort1.Open();
this.serialPort1.DataReceived += new SerialDataReceivedEventHandler(this.scannerSerialPort_DataReceived);
}
The method you can see in below :-
public void scannerSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
frmRegistrationStickerPrinting _frmRegistrationStickerPrinting = this;
_frmRegistrationStickerPrinting.scan = string.Concat(_frmRegistrationStickerPrinting.scan, this.serialPort1.ReadExisting());
if (this.scan.EndsWith("\r\n"))
{
this.scan = this.scan.Substring(0, this.scan.Length - 2);
Control activeControl = base.ActiveControl;
if (activeControl.InvokeRequired)
{
activeControl.Invoke(new MethodInvoker(() => activeControl.Text = this.scan));
}
Control nextControl = base.GetNextControl(activeControl, true);
if (nextControl.InvokeRequired)
{
nextControl.Invoke(new MethodInvoker(() => nextControl.Focus()));
}
this.scan = "";
}
}


Nilesh SawardekarRank #648 · 3.7K reputationPosted Aug 6, 2016, 9:19 AM EDT
Suraj Binorkar122 reputationPosted Aug 22, 2016, 1:50 AM EDT