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.
259 lines
7.2 KiB
C#
259 lines
7.2 KiB
C#
using SlnMesnac.Rfid.NewRFIDConnect.entity;
|
|
using RFIDTest.entity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
|
|
namespace SlnMesnac.Rfid.NewRFIDConnect
|
|
{
|
|
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="data">数据体</param>
|
|
/// <returns></returns>
|
|
public Receive02HEntity Receive02H(byte[] data)
|
|
{
|
|
Receive02HEntity entity = new Receive02HEntity();
|
|
|
|
int index = 0;
|
|
|
|
if (data.Length != 0)
|
|
{
|
|
//取读到多少个标签
|
|
entity.TagCount = data[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 = 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 (Exception ex)
|
|
{
|
|
return null;
|
|
}
|
|
index += 12;
|
|
|
|
entity.Data.Add(EPCData);
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送心跳配置包
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public byte[] SendBFH(byte second)
|
|
{
|
|
byte[] data = new byte[3];
|
|
data[0] = 0x00;
|
|
data[1] = second;
|
|
data[2] = 0x01;
|
|
|
|
BaseSendDataEntity entity = new BaseSendDataEntity()
|
|
{
|
|
Code = 0xBF,
|
|
Data = data
|
|
};
|
|
|
|
byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity);
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接收心跳包
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public uint ReceiveBFH(byte[] data)
|
|
{
|
|
uint result = BitConverter.ToUInt32(data, 0);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送连续盘点请求
|
|
/// </summary>
|
|
/// <param name="millisecond"></param>
|
|
/// <returns></returns>
|
|
public byte[] Send11H()
|
|
{
|
|
byte[] bytes = new byte[2] { 0x00, 0x00 };
|
|
//byte[] bytes = BitConverter.GetBytes(millisecond);
|
|
//bytes = bytes.Reverse().ToArray();
|
|
BaseSendDataEntity entity = new BaseSendDataEntity()
|
|
{
|
|
Code = 0x11,
|
|
Data = bytes
|
|
};
|
|
byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送停止盘点请求
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public byte[] Send12H()
|
|
{
|
|
byte[] bytes = new byte[2] { 0x00, 0x00 };
|
|
//byte[] bytes = BitConverter.GetBytes(millisecond);
|
|
//bytes = bytes.Reverse().ToArray();
|
|
BaseSendDataEntity entity = new BaseSendDataEntity()
|
|
{
|
|
Code = 0x12,
|
|
Data = bytes
|
|
};
|
|
byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接受连续盘点结果
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public ReciveResult11HEntity Receive11H(byte[] data)
|
|
{
|
|
int index = 0;
|
|
ReciveResult11HEntity entity = new ReciveResult11HEntity();
|
|
entity.Count = data[index];
|
|
index++;
|
|
|
|
entity.RSSI = data[index];
|
|
index++;
|
|
|
|
entity.Ant = data[index];
|
|
index++;
|
|
|
|
entity.PC = new byte[2];
|
|
Array.Copy(data, index, entity.PC, 0, 2);
|
|
index += 2;
|
|
|
|
int restLength = data.Length - index;
|
|
|
|
entity.EPC = new byte[restLength];
|
|
Array.Copy(data, index, entity.EPC, 0, restLength);
|
|
index += 12;
|
|
|
|
return entity;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送写入请求
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public byte[] Send03H(Base03HENtity rawData)
|
|
{
|
|
int selectLength = rawData.SelectLength / 8;
|
|
int wordCount = rawData.WordCount * 2;
|
|
byte[] bytes = new byte[2 + 4 + 1 + 4 + 1 + selectLength + 1 + 4 + 1 + wordCount];
|
|
|
|
int index = 0;
|
|
|
|
Array.Copy(rawData.TimeOut, 0, bytes, index, 2);
|
|
index += 2;
|
|
|
|
Array.Copy(rawData.AccessPassword, 0, bytes, index, 4);
|
|
index += 4;
|
|
|
|
bytes[index] = rawData.SelectBank;
|
|
index++;
|
|
|
|
Array.Copy(rawData.SelectAddress, 0, bytes, index, 4);
|
|
index += 4;
|
|
|
|
bytes[index] = rawData.SelectLength;
|
|
index++;
|
|
|
|
Array.Copy(rawData.SelectData, 0, bytes, index, selectLength);
|
|
index += selectLength;
|
|
|
|
bytes[index] = rawData.WriteBank;
|
|
index++;
|
|
|
|
Array.Copy(rawData.WriteAddress, 0, bytes, index, 4);
|
|
index += 4;
|
|
|
|
bytes[index] = rawData.WordCount;
|
|
index++;
|
|
|
|
Array.Copy(rawData.WriteData, 0, bytes, index, wordCount);
|
|
index += wordCount;
|
|
|
|
BaseSendDataEntity entity = new BaseSendDataEntity()
|
|
{
|
|
Code = 0x03,
|
|
Data = bytes
|
|
};
|
|
byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送功率设置包
|
|
/// </summary>
|
|
/// <param name="power"></param>
|
|
/// <returns></returns>
|
|
public byte[] Send42H(int power)
|
|
{
|
|
return new byte[0];
|
|
}
|
|
}
|
|
}
|