public void CheckID(string id) { if (!IsCorrectID(id)) { throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_ID); } }
private void CheckPortOpen() { if (serialPort == null || !serialPort.IsOpen) { throw ExceptionRFID.Create(ErrorCodeRFID.SerialPortOpenError, PortName); } }
private void VerifyCheckSum(string rfidData) { _checkSumCalculate = CalculateCheckSum(rfidData); if (_checkSumCalculate != (byte)rfidData[CheckSumByteNo]) { throw ExceptionRFID.Create(ErrorCodeRFID.CHECKSUM_ERR); } }
public void DecodeWriteResponse(string writeResponse) { if (writeResponse.Length == 4 && writeResponse[0] == 'W' && writeResponse[1] == 'T') { DecodeErrorCode(writeResponse.Substring(2, 2)); } else { throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_DATA); } }
public byte DecodeCheckSum(string readData) { if (readData.Length == 5 && readData[0] == 'R' && readData[1] == 'D') { DecodeErrorCode(readData.Substring(2, 2)); return((byte)readData[4]); } else { throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_DATA); } }
public string DecodeID(string readData) { if (readData.Length == 7 && readData[0] == 'R' && readData[1] == 'D') { DecodeErrorCode(readData.Substring(2, 2)); return(readData.Substring(4).Trim()); } else { throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_DATA); } }
private void DecodeErrorCode(string errorCodeString) { try { int errorCode = int.Parse(errorCodeString, System.Globalization.NumberStyles.HexNumber); if (errorCode != 0) { throw ExceptionRFID.Create((ErrorCodeRFID)errorCode); } } catch { throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_DATA); } }
public void DecodeReadData(string readData, bool isChksum) { if (readData.Length >= 257 && readData[0] == 'R' && readData[1] == 'D') { DecodeErrorCode(readData.Substring(2, 2)); string rfidData = readData.Substring(4); ExtractReadData(rfidData); if (isChksum) { VerifyCheckSum(rfidData); } } else { throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_DATA); } }
private void OpenPort() { try { if (serialPort == null) { serialPort = new SerialPort(PortName); } else { if (serialPort.IsOpen) { serialPort.Close(); } serialPort.PortName = PortName; } serialPort.BaudRate = BaudRate; serialPort.DataBits = DataBits; serialPort.Parity = Parity; serialPort.StopBits = StopBits; serialPort.ReadTimeout = ReadTimeOut; serialPort.Encoding = Encoding.GetEncoding(28591); // 28591 = iso-8859-1 Western European (ISO) serialPort.NewLine = "\r"; serialPort.Open(); if (serialPort.IsOpen) { serialPort.DiscardInBuffer(); serialPort.DiscardOutBuffer(); InitTagData(); } else { throw ExceptionRFID.Create(ErrorCodeRFID.SerialPortOpenError, PortName); } } catch { throw ExceptionRFID.Create(ErrorCodeRFID.SerialPortOpenError, PortName); } }