示例#1
0
 public void CheckID(string id)
 {
     if (!IsCorrectID(id))
     {
         throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_ID);
     }
 }
示例#2
0
 private void CheckPortOpen()
 {
     if (serialPort == null || !serialPort.IsOpen)
     {
         throw ExceptionRFID.Create(ErrorCodeRFID.SerialPortOpenError, PortName);
     }
 }
示例#3
0
 private void VerifyCheckSum(string rfidData)
 {
     _checkSumCalculate = CalculateCheckSum(rfidData);
     if (_checkSumCalculate != (byte)rfidData[CheckSumByteNo])
     {
         throw ExceptionRFID.Create(ErrorCodeRFID.CHECKSUM_ERR);
     }
 }
示例#4
0
 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);
     }
 }
示例#5
0
 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);
     }
 }
示例#6
0
 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);
     }
 }
示例#7
0
 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);
     }
 }
示例#8
0
 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);
     }
 }
示例#9
0
        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);
            }
        }