Esempio n. 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[] EPC = new byte[5000];

            int Totallen = 0;
            int CardNum  = 0;

            string[] fInventory_EPC_List = new string[2];

            #endregion ReaderInventoryReq

            _fCmdRet = StaticClassReaderB.Inventory_G2(ref Reader.ComAddrr, AdrTID, LenTID,
                                                       TIDFlag, EPC, ref Totallen, ref CardNum, Reader.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] = RfidConversion.ByteArrayToHexString(daw).Remove(0, 2);
                fInventory_EPC_List[1] = RfidConversion.ByteArrayToHexString(daw).Remove(2);
                return(fInventory_EPC_List);
            }

            Console.WriteLine(RfidConversion.GetErrorCodeDesc(_fCmdRet));
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Used to read an EPC with NO Lock on the system
        /// </summary>
        /// <returns></returns>
        private string Read_Epc()
        {
            var str = Inventory();

            if (str == null)
            {
                Console.WriteLine("No Tags Found at {0}", ReaderName);
                return(null);
            }

            Console.WriteLine("Tag ID at {0}:{1}", ReaderName, str[0]);
            Thread.Sleep(500);

            #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 = RfidConversion.HexStringToByteArray("00000000");

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

            #endregion ReaderRequirements

            _fCmdRet = StaticClassReaderB.ReadCard_G2(ref Reader.ComAddrr, epc, mem, wordPtr, wNum, fPassWord, MaskAdd,
                                                      MaskLen, MaskFlag, cardData, epcLength, ref Reader.ErrorCode, Reader.PortHandle);

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

                Console.WriteLine("Tag ID at {0}:{1}", ReaderName, RfidConversion.ByteArrayToHexString(daw));

                return(RfidConversion.ByteArrayToHexString(daw));
            }

            if (Reader.ErrorCode == -1)
            {
                return(null);
            }
            Console.WriteLine(
                "Error reading EPC Value. ErrorCode=0x{0}({1})",
                Convert.ToString(Reader.ErrorCode, 2),
                RfidConversion.GetErrorCodeDesc(Reader.ErrorCode));
            return(null);
        }