//private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) //{ // int len = serialPort.BytesToRead; // byte[] buffer = new byte[len]; // serialPort.Read(buffer, 0, len); // Buffer.AddRange(buffer);//断帧、粘包处理 // int idx_0a;//0x0d 0x0a 结束符 // while ((idx_0a = Buffer.IndexOf(0x0a)) != -1)//断帧、粘包处理 // { // byte[] data = Buffer.Take(idx_0a - 1).ToArray();//截取0x0d 0x0a前报文 // Buffer.RemoveRange(0, idx_0a + 1); // string strCodes = Encoding.Default.GetString(data);//TODO:编码格式 Default=GB2312 // RaiseScanned(this.Scanner, strCodes); // } //} protected void RaiseScanned(ScanDevice scan, string stopNo, string data) { try { OnScanned?.Invoke(this.Scanner, stopNo, data); } catch (Exception ex) { string errMsg = "OnScanned事件委托异常!"; RaiseError(errMsg); //MyLog.WriteLog(errMsg, ex); } }
public SerialScannerHelper(ScanDevice scanSetting) { this.Scanner = scanSetting; //serial = new SerialPort(Scanner.ComName, 9600, Parity.None, 8, StopBits.One); }
public SocketScannerHelper(ScanDevice scanSetting) { this.Scanner = scanSetting; }