示例#1
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);
        }
示例#2
0
        public string WriteEpc()
        {
            lock (_locker)
            {
                #region ReaderRequirements

                byte   WordPtr = 1, ENum;
                byte   Mem            = 1;
                byte   WNum           = 0;
                byte   EPClength      = 0;
                byte   Writedatalen   = 0;
                int    WrittenDataNum = 0;
                byte[] CardData       = new byte[320];
                byte[] writedata      = new byte[230];

                byte MaskFlag = 0, MaskAdd = 0, MaskLen = 0;

                var fPassword = RfidConversion.HexStringToByteArray("00000000");

                #endregion ReaderRequirements

                var epcVal = Read_Epc();

                #region Setup GUID

                var guid = Guid.NewGuid().ToString().Replace("-", null).ToUpper(); //32 characters long
                guid      = guid + epcVal.Substring(epcVal.Length - 4);
                ENum      = Convert.ToByte(epcVal.Length / 4);
                EPClength = Convert.ToByte(ENum * 2);
                byte[] EPC = new byte[ENum];

                WNum = Convert.ToByte(guid.Length / 4);
                byte[] Writedata = new byte[WNum * 2];

                Writedata    = RfidConversion.HexStringToByteArray(guid);
                Writedatalen = Convert.ToByte(WNum * 2);

                #endregion Setup GUID

                _fCmdRet = StaticClassReaderB.WriteCard_G2(ref Reader.ComAddrr, EPC, Mem, WordPtr,
                                                           Writedatalen, Writedata, fPassword, MaskAdd, MaskLen, MaskFlag, WrittenDataNum,
                                                           EPClength, ref Reader.ErrorCode, Reader.ComAddrr);

                return(guid);
            }
        }