Home > Net >  C # serial port to receive the barcode scanner sweep to the incomplete data and print the data
C # serial port to receive the barcode scanner sweep to the incomplete data and print the data

Time:09-24

I'm doing a serial port project code scanner sweep the bar code scanning guns data terminator 0 d0a and then the data in the ListBox call print clear
There is a problem with is now receiving data is incomplete always disconnect the display is not in the same row or data splicing, plus time delay can be solved only efficiency too slow or has a problem consult everybody how do processing with complete data through the terminator judgment



Private void serialPort1_DataReceived (object sender, SerialDataReceivedEventArgs e)
{
//System. Threading. Thread. Sleep (300);
String STR=serialPort1. ReadExisting ();
If (STR!=string. The Empty)
{
Byte
return;
}
The else
{
MessageBox. Show (STR);
}
ListBox1. Items. The Add (STR. The Trim ());//read data add - ListBox1

}
For years, some directions should be how to write

CodePudding user response:


This is I use a serial port assistant HEX received data

CodePudding user response:

You this qr code or bar code, not by the Numbers? So, you give an input box, and code gun direct digital into the input field,

CodePudding user response:

 
String _data while forming;//store the remaining data
String _splitStr;//delimiters
Private void serialPort1_DataReceived (object sender, SerialDataReceivedEventArgs e)
{
//System. Threading. Thread. Sleep (300);
String STR=serialPort1. ReadExisting ();
If (STR!=string. The Empty)
{
_data while forming +=STR;
String [] sSplit=_data while forming. The Split (new string [] {_splitStr}, StringSplitOptions. None).
If (sSplit. Length & gt; 1)
{
For (int I=0; I & lt; SSplit. Length; I++)
{
If (I==sSplit. Length - 1)
{
if (! String. IsNullOrEmpty (sSplit [I]))
{
[I]; _data while forming=https://bbs.csdn.net/topics/sSplit
break;
}
}
ListBox1. Items. The Add (sSplit [I] the Trim ());//read data add - ListBox1
}
}
return;
}
The else
{
MessageBox. Show (STR);
}

}

CodePudding user response:

Problem may be that your hardware devices, can look up the baud rate, speed up the transfer rate, may be able to help,

That according to the end to check the data integrity may can't do that, in most of my contact scanning gun, with 0 d0a (with a newline) as the terminator still true have never heard of,
General with the Enter (return) to determine more, if you can, suggest you try the scanning gun and adjust to Enter as a judgment in your program,
  •  Tags:  
  • C #
  • Related