Example #1
0
        protected InventoryInfo HandleInventoryFrame(byte[] frame)
        {
            InventoryInfo info = new InventoryInfo(frame);

            //由于查询成功可能会返回其它的 Status 值,所以帧检查需要单独写
            //如果帧长度不对,则检查不通过
            if (frame[0] != frame.Length - 1)
            {
                info.ReturnValue = ReturnMessage.HF_FrameLenError;
                return(info);
            }
            //检查读写器地址
            if (frame[1] != Com_adr && frame[1] != 0xFF)
            {
                info.ReturnValue = ReturnMessage.HF_ReaderAddrError;
                return(info);
            }
            //CRC校验
            UInt16 crc = FrameBase.GetCRC(frame);
            UInt16 a   = BitConverter.ToUInt16(frame, frame.Length - 2);
            UInt16 b   = FrameBase.Reverse(crc);

            if (BitConverter.ToUInt16(frame, frame.Length - 2) != crc)
            {
                info.ReturnValue = ReturnMessage.HF_CRCError;
                return(info);
            }
            //压入结果状态码
            info.SetStatus();
            if (info.Status > 0x04)
            {
                info.ReturnValue = ReturnMessage.HF_StatusError;
                return(info);
            }

            info.Num = frame[4];
            var epcSet = info.EPCSet;
            int index  = 5;

            for (int i = 0; i < info.Num; i++)
            {
                InventoryInfo.EPCInfo epc = new InventoryInfo.EPCInfo();
                int len = frame[index++];
                epc.EPCLen = (byte)(len / 2);
                epc.EPC    = new byte[len];
                Array.Copy(frame, index, epc.EPC, 0, len);
                epcSet.Add(epc);
                index += len;
            }

            info.ReturnValue = ReturnMessage.Success;
            return(info);
        }
Example #2
0
        /// <summary>
        /// 询查单张标签
        /// </summary>
        /// <returns></returns>
        public async Task <InventoryInfo> InventorySingleAsync()
        {
            byte[] frame = CreateInventorySingleFrame();
            CommunicationReturnInfo cri = await com.SendAsync(frame);

            if (cri.ReturnValue != ReturnMessage.Success)
            {
                InventoryInfo ii = new InventoryInfo();
                ii.SendByte         = frame;
                ii.ReturnValue      = cri.ReturnValue;
                ii.ExceptionMessage = cri.ExceptionMessage;
                return(ii);
            }

            InventoryInfo info = HandleInventoryFrame(cri.RecvByte);

            info.SendByte = frame;
            return(info);
        }