using HighWayIot.Rfid.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HighWayIot.Rfid { public class RfidDataAnalyse { /// /// 02H时间段盘点发送 /// /// 盘点时间毫秒数 /// public byte[] Send02H(ushort millisecond) { byte[] bytes = BitConverter.GetBytes(millisecond); bytes = bytes.Reverse().ToArray(); BaseSendDataEntity entity = new BaseSendDataEntity() { Code = 0x02, Data = bytes }; byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity); return result; } /// /// 接受02H盘点数据 (默认EPC 4位) /// /// 数据体 /// public Receive02HEntity Receive02H(byte[] data) { Receive02HEntity entity = new Receive02HEntity(); int index = 0; if (data.Length != 0) { //取读到多少个标签 entity.TagCount = data[index]; entity.Data = new List(); index++; } else { entity.TagCount = 0; } //取每一个读到的标签 for (int i = 0; i < entity.TagCount; i++) { Single02HReceive EPCData = new Single02HReceive(); //取单个标签读取的次数 EPCData.Count = data[index]; index++; //取信号强度 EPCData.RSSI = data[index]; index++; //取天线端口 EPCData.Ant = data[index]; index++; //取EPC区域 EPCData.PC = new byte[2]; Array.Copy(data, index, EPCData.PC, 0, 2); index += 2; //取读到标签的EPC EPCData.EPC = new byte[12]; try { Array.Copy(data, index, EPCData.EPC, 0, 12); } catch { return null; } index += 12; entity.Data.Add(EPCData); } return entity; } /// /// 发送心跳配置包 /// /// public byte[] SendBFH(ushort second) { byte[] data = new byte[3]; data[0] = 0x00; data[1] = 0x05; data[2] = 0x01; BaseSendDataEntity entity = new BaseSendDataEntity() { Code = 0xBF, Data = data }; byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity); return result; } /// /// 接收心跳包 /// /// public uint ReceiveBFH(byte[] data) { uint result = BitConverter.ToUInt32(data, 0); return result; } } }