You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.8 KiB
C#

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
{
/// <summary>
/// 02H时间段盘点发送
/// </summary>
/// <param name="millisecond">盘点时间毫秒数</param>
/// <returns></returns>
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;
}
/// <summary>
/// 接受02H盘点数据 (默认EPC 4位)
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public Receive02HEntity Receive02H(byte[] bytes)
{
BaseReciveDataEntity recive = BaseRFIDDataAnalyse.BaseReceiveAnalyse(bytes);
if (recive == null)
{
return null;
}
byte[] DataBytes = recive.Data;
Receive02HEntity entity = new Receive02HEntity();
int index = 0;
if (DataBytes.Length != 0)
{
//取读到多少个标签
entity.TagCount = DataBytes[index];
entity.Data = new List<Single02HReceive>();
index++;
}
else
{
entity.TagCount = 0;
}
//取每一个读到的标签
for (int i = 0; i < entity.TagCount; i++)
{
Single02HReceive EPCData = new Single02HReceive();
//取单个标签读取的次数
EPCData.Count = DataBytes[index];
index++;
//取信号强度
EPCData.RSSI = DataBytes[index];
index++;
//取天线端口
EPCData.Ant = DataBytes[index];
index++;
//取EPC区域
EPCData.PC = new byte[2];
Array.Copy(DataBytes, index, EPCData.PC, 0, 2);
index += 2;
//取读到标签的EPC
EPCData.EPC = new byte[12];
try
{
Array.Copy(DataBytes, index, EPCData.EPC, 0, 12);
}
catch
{
return null;
}
index += 12;
entity.Data.Add(EPCData);
}
return entity;
}
}
}