private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { byte[] buffer = new byte[this.g_serialPort.ReadBufferSize]; int bytesRead = this.g_serialPort.Read(buffer, 0, buffer.Length); this.g_byteBarCodeTempData.AddRange(buffer.ToList().Where(f => f != (byte)StartPreFix && f != (byte)EndPreFix && f != (byte)0)); // CHOO //if (this._baseInfo.center_cd_string.Equals("YJ") == true) var aaa = buffer.Where(f => f != (byte)0).LastOrDefault(); if (buffer.Where(f => f != (byte)0).LastOrDefault() == (byte)EndPreFix) { string data = Encoding.UTF8.GetString(this.g_byteBarCodeTempData.ToArray(), 0, this.g_byteBarCodeTempData.Count()); //string data = serialPort.ReadLine(); this.g_byteBarCodeTempData.Clear(); if (!string.IsNullOrWhiteSpace(data.ToWhiteSpaceOrString())) { var _barcode = data.Replace("\r", "").Replace("\n", ""); BarCodeReceived?.Invoke(this, new BarCodeReceivedEventArgs { BarCode = _barcode }); } } }
private void Form_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.D0: case Keys.D1: case Keys.D2: case Keys.D3: case Keys.D4: case Keys.D5: case Keys.D6: case Keys.D7: case Keys.D8: case Keys.D9: if (!_ongoingBarcodeReading) { // Start saving digits. _ongoingBarcodeReading = true; _barCodeString = ""; } // Add digit. _barCodeString += e.KeyCode.ToString().Substring(1); if (_barCodeString.Length == Settings.Default.BarCodeLengthInternal) { BarCodeReceived?.Invoke(_barCodeString); _ongoingBarcodeReading = false; } break; default: _ongoingBarcodeReading = false; break; } e.Handled = true; e.SuppressKeyPress = true; }
private void Scanner_BarCodeReceived(object sender, BarCodeReceivedEventArgs e) { this.Dispatcher.BeginInvoke(new Action(() => { bool _IsVisible = false; if (this.InputParent is UserControl) { var _window = this.InputParent.FindParent <Window>(); if (_window != null) { if (_window.IsActive) { _IsVisible = (this.InputParent as UserControl).IsVisible; } } } if (this.InputParent is Window) { //var _window = this.InputParent.FindParent<Window>(); //if (_window != null) //{ // if (_window.IsActive) // { // _IsVisible = (this.InputParent as Window).IsVisible; // } //} var _window = this.InputParent.FindParent <Window>(); if (_window == null) { _window = this.InputParent as Window; if (_window != null) { //{ // if (_window.IsActive) // { // _IsVisible = (this.InputParent as Window).IsVisible; // } _IsVisible = true; } } else { _window = this.InputParent.FindParent <Window>(); if (_window != null) { if (_window.IsActive) { _IsVisible = (this.InputParent as UserControl).IsVisible; } } } } //if (this.InputParent is KioskForm) //{ // var _window = this.InputParent.FindParent<Window>(); // if (_window.IsActive) // { // _IsVisible = (this.InputParent as KioskForm).IsVisible; // } //} if (_IsVisible) { System.Diagnostics.Debug.WriteLine("BarCodeReader : " + e.BarCode); BarCodeReceived?.Invoke(this, new BarCodeReceivedEventArgs { BarCode = e.BarCode }); } })); }