void OnDataReceived(object sender, SerialDataReceivedEventArgs e) { try { while (_port.BytesToRead > 0) { int bytesToRead = _port.BytesToRead <= _buf.Length ? _port.BytesToRead : _buf.Length; int actuallyRead = _port.Read(_buf, 0, bytesToRead); if (actuallyRead > 0) { var data = Encoding.ASCII.GetString(_buf, 0, actuallyRead); RfidReceived?.Invoke(this, new RfidReceivedEventArgs(data)); WriteDebugLine(data); } //if (actuallyRead > 0) //{ // int etx = -1; // for (int i = 0; i < actuallyRead; i++) // { // if (_buf[i] == STX) // { // _stx = i; // _snIndex = 0; // } // else if (_buf[i] == ETX) // { // if (_stx >= 0) // { // etx = i; // break; // } // } // else if (_stx >= 0) // { // _sn[_snIndex++] = _buf[i]; // } // } // if (_stx >= 0 && etx >= 0) // { // var data = Encoding.ASCII.GetString(_sn, 0, _snIndex); // WriteDebugLine(data); // _stx = -1; // _snIndex = 0; // } //} } } catch (Exception ex) { WriteLine(ex); } }
void OnRfidReceived(string rfid) { RfidReceived?.Invoke(this, new RfidReceivedEventArgs(rfid)); }
void OnRfidReceived(string rfid) { var decRfid = ConvertRfidToDecimal(rfid); RfidReceived?.Invoke(this, new RfidReceivedEventArgs(decRfid)); }