Exemplo n.º 1
0
 private void CheckPortOpen()
 {
     if (serialPort == null || !serialPort.IsOpen)
     {
         throw ExceptionRFID.Create(ErrorCodeRFID.SerialPortOpenError, PortName);
     }
 }
Exemplo n.º 2
0
 public void CheckID(string id)
 {
     if (!IsCorrectID(id))
     {
         throw ExceptionRFID.Create(ErrorCodeRFID.INVALID_ID);
     }
 }
Exemplo n.º 3
0
 private void VerifyCheckSum(string rfidData)
 {
     _checkSumCalculate = CalculateCheckSum(rfidData);
     if (_checkSumCalculate != (byte)rfidData[CheckSumByteNo])
     {
         throw ExceptionRFID.Create(ErrorCodeRFID.CHECKSUM_ERR);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 10
0
        public static ExceptionRFID Create(ErrorCodeRFID errorCode, string message)
        {
            string   errorMessage = "";
            Severity severity     = Severity.None;

            switch (errorCode)
            {
            case ErrorCodeRFID.Unknown:
                errorMessage = "Unknown error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.RFID_SUCCESS:
                errorMessage = "RFID operation succeeded.";
                severity     = Severity.None;
                break;

            case ErrorCodeRFID.MEMORY_ERR:
                errorMessage = "Memory error. The internal data structures couldn't be allocated.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.RANGE_ERR:
                errorMessage = "Parameter out of range error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.NOT_FOUND:
                errorMessage = "Station code not found error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.NOT_NEXT:
                errorMessage = "Station is out of sequence error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CHECKSUM_ERR:
                errorMessage = "Check sum error for data in RFID tag. The data is corrupted.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.WRITECOUNT_ERR:
                errorMessage = "The maximum number of write cycles has been reached on the RFID tag.";
                severity     = Severity.Error;
                break;

            //case ErrorCodeRFID.INVALID_CARRIER:
            //    errorMessage = "The tray at the RF head " + message + " does not contain a valid tray ID.";
            //    severity = Severity.Error;
            //    break;
            case ErrorCodeRFID.INVALID_ID:
                errorMessage = "Invalid Carrier/Tray ID.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.WRITE_VERIFY_ERR:
                errorMessage = "Read after write failure.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.TAGTYPE_ERR:
                errorMessage = "Operation not valid for tag error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.TIMEOUT_ERR:
                errorMessage = "No data was received error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.NO_WORKORDER:
                errorMessage = "No workorder description file was found error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.ASYNC_BUSY:
                errorMessage = "An asynchronous operation is already running.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.ASYNC_FAIL:
                errorMessage = "The asynchronous operation failed.";
                severity     = Severity.Error;
                break;
            // Error from Controller

            case ErrorCodeRFID.CTRL_BATTERY_LOW:
                errorMessage = "Battery low warning indicating the battery replacement is required.";
                severity     = Severity.Warning;
                break;

            case ErrorCodeRFID.CTRL_VERICAL_PARITY_ERROR:
                errorMessage = "Vertical parity error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_FRAMING_ERROR:
                errorMessage = "Framing Error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_OVERRUN_ERROR:
                errorMessage = "Overrun Error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_FORMAT_ERROR:
                errorMessage = "Format Error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_EXECUTION_STATUS_ERROR:
                errorMessage = "Execution status error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_FRAME_LENGTH_ERROR:
                errorMessage = "Frame length error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_COMM_ERROR:
                errorMessage = "Data carrier communications error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_MISMATCH_ERROR:
                errorMessage = "Mismatch error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_DATA_CARRIER_ERROR:
                errorMessage = "Data carrier non-existent error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_DATA_ERROR:
                errorMessage = "Data error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_ADDRESS_ERROR:
                errorMessage = "Address error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_ANTENNA_ERROR:
                errorMessage = "Antenna error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_WRITE_PROTECT_ERROR:
                errorMessage = "Write protect error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.CTRL_MEMORY_ERROR:
                errorMessage = "Memory error.";
                severity     = Severity.Error;
                break;

            // External Error
            case ErrorCodeRFID.DLL_INTERNAL_ERR:
                errorMessage = "DLL internal error.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.SerialPortError:
                errorMessage = "Port " + message + ", Serial port error. Check that all cables are connected and the port is not being used by another application.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.SerialPortOpenError:
                errorMessage = "Opening port " + message + " Error.  Check that it is not being used by another application.";
                severity     = Severity.Error;
                break;

            case ErrorCodeRFID.INVALID_DATA:
                errorMessage = "Invalid Data.";
                severity     = Severity.Error;
                break;

            default:
                errorMessage = "Omron internal error reading/writing the RFID tag on the tray at the " + message + ".";
                severity     = Severity.Error;
                break;
            }

            ExceptionRFID ex = new ExceptionRFID(errorMessage);

            ex.severity   = severity;
            ex._errorCode = errorCode;
            return(ex);
        }