示例#1
0
        /// <summary>
        /// <para>Gets current tags within range and return the first tag. Inventory not kept.</para>
        /// <remarks>
        /// <para>
        /// Returns EPC of type <see cref="string"/>[2] || EPC[0] = Tag Lenght | EPC[1] = Tag ID
        /// </para>
        /// </remarks>
        /// </summary>
        /// <returns>[0] = Tag Lenght [1] = Tag ID</returns>
        private string[] Inventory()
        {
            #region ReaderInventoryReq

            byte AdrTID  = 0;
            byte LenTID  = 0;
            byte TIDFlag = 0;

            byte comAddrr = 0xff;

            byte[] EPC = new byte[5000];

            int Totallen = 0;
            int CardNum  = 0;

            string[] fInventory_EPC_List = new string[2];

            #endregion ReaderInventoryReq

            _fCmdRet = StaticClassReaderB.Inventory_G2(ref comAddrr, AdrTID, LenTID,
                                                       TIDFlag, EPC, ref Totallen, ref CardNum, _portHandle);

            if ((_fCmdRet == 1) | (_fCmdRet == 2) | (_fCmdRet == 3) | (_fCmdRet == 4)) //251 = no tags detected
            {
                byte[] daw = new byte[Totallen];
                Array.Copy(EPC, daw, Totallen);
                fInventory_EPC_List[0] = ByteArrayToHexString(daw).Remove(0, 2);
                fInventory_EPC_List[1] = ByteArrayToHexString(daw).Remove(2);
                _eventLog.WriteEntry("Inventory Gather status\n" + EventIds.GetErrorCodeDesc(_fCmdRet), EventLogEntryType.Information, (int)EventIds.Ids.GetTagInventorySuccess);
                return(fInventory_EPC_List);
            }

            _eventLog.WriteEntry("Inventory Gather status\n" + EventIds.GetErrorCodeDesc(_fCmdRet), EventLogEntryType.Information, (int)EventIds.Ids.GetTagInventoryFailure);
            return(null);
        }
示例#2
0
 public RfidReader(ServiceConfig.Reader readerConfig, ref EventLog log)
 {
     _eventLog = log;
     try
     {
         var connected = Connect(readerConfig.Address, readerConfig.PortNum);
         if (connected != 0x35 || connected != 0x00) //Success
         {
             _eventLog.WriteEntry($"Unsuccessfully Connected\n{EventIds.GetReturnCodeDesc(connected)}", EventLogEntryType.FailureAudit, (int)EventIds.Ids.UnsuccessfulRFIDConnection);
         }
     }
     catch (Exception e)
     {
         _eventLog.WriteEntry($"Unknown Error\n{e.Message}\n{e.StackTrace}\n\n{e.InnerException}", EventLogEntryType.Error, (int)EventIds.Ids.UnknownError);
     }
 }
示例#3
0
        /// <summary>
        /// Used to read an EPC with NO Lock on the system
        /// </summary>
        /// <returns></returns>
        public string Read_Epc()
        {
            var str = Inventory();

            if (str == null)
            {
                return(null);
            }


            #region ReaderRequirements

            const byte wordPtr  = 0;
            const byte mem      = 1;
            byte[]     cardData = new byte[320];

            byte wNum      = Convert.ToByte(Convert.ToInt64(str[1]) - 2);
            byte epcLength = Convert.ToByte(str[0].Length / 2);
            byte eNum      = Convert.ToByte(str[0].Length / 4);

            byte MaskFlag = 0, MaskAdd = 0, MaskLen = 0;
            var  fPassWord = HexStringToByteArray("00000000");

            byte[] epc = new byte[eNum];
            epc = HexStringToByteArray(str[0]);

            #endregion ReaderRequirements

            _fCmdRet = StaticClassReaderB.ReadCard_G2(ref _comAddress, epc, mem, wordPtr, wNum, fPassWord, MaskAdd,
                                                      MaskLen, MaskFlag, cardData, epcLength, ref _errorCode, _portHandle);

            if (_fCmdRet == 0) //Successful read
            {
                byte[] daw = new byte[wNum * 2];
                Array.Copy(cardData, daw, wNum * 2);


                return(ByteArrayToHexString(daw));
            }

            if (_errorCode == -1)
            {
                return(null);
            }
            _eventLog.WriteEntry(
                $"Error reading EPC Value. ErrorCode=0x{Convert.ToString(_errorCode, 2)}({EventIds.GetErrorCodeDesc(_errorCode)})", EventLogEntryType.Error, (int)EventIds.Ids.GetTagInventoryFailure);
            return(null);
        }