|
|
|
|
@ -70,8 +70,8 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
|
|
|
|
|
_tcpClient.Connect();
|
|
|
|
|
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
|
|
|
|
|
_tcpClient.ConnectAsync();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
@ -92,15 +92,15 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
{
|
|
|
|
|
m_deviceID = deviceid;
|
|
|
|
|
m_strIP = ip;
|
|
|
|
|
_tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
|
|
|
|
|
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
|
|
|
|
|
await _tcpClient.ConnectAsync(1500);
|
|
|
|
|
_tcpClient.Received = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
//从客户端收到信息
|
|
|
|
|
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
|
|
|
|
|
var mes = Encoding.UTF8.GetString(e.Memory.Span.ToArray(), 0, e.Memory.Span.Length);//注意:数据长度是byteBlock.Len
|
|
|
|
|
|
|
|
|
|
byte[] receivedBuffer = new byte[e.ByteBlock.Len];
|
|
|
|
|
Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len);
|
|
|
|
|
byte[] receivedBuffer = new byte[e.Memory.Span.Length];
|
|
|
|
|
Array.Copy(e.Memory.Span.ToArray(), 0, receivedBuffer, 0, e.Memory.Span.Length);
|
|
|
|
|
byte[] resultBuffer = PareReceiveBufferData(receivedBuffer, receivedBuffer.Length);
|
|
|
|
|
List<TagInfo> tagInfoList = Device_DealTagInfoList(resultBuffer);
|
|
|
|
|
string info = "";
|
|
|
|
|
@ -133,56 +133,6 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按时间段盘点
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="timeout"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="InvalidOperationException"></exception>
|
|
|
|
|
public override List<TagInfo> TimePeriodRead(int timeout = 5000)
|
|
|
|
|
{
|
|
|
|
|
byte[] u16byte = new byte[2];
|
|
|
|
|
byte[] bCRC = new byte[4];
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 指令封装
|
|
|
|
|
MessagePack pMessagePack = new MessagePack();
|
|
|
|
|
pMessagePack.m_pData = new byte[8];
|
|
|
|
|
pMessagePack.m_pData[0] = 0xAA;
|
|
|
|
|
pMessagePack.m_pData[1] = 0x55;
|
|
|
|
|
pMessagePack.m_pData[2] = 0x02;
|
|
|
|
|
pMessagePack.m_pData[3] = 0x02;
|
|
|
|
|
u16byte = BitConverter.GetBytes(timeout); //超时时间
|
|
|
|
|
u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前
|
|
|
|
|
Array.Copy(u16byte, 0, pMessagePack.m_pData, 4, 2);
|
|
|
|
|
Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 4);
|
|
|
|
|
pMessagePack.m_pData[6] = _stringChange.CalculateVerify(bCRC, bCRC.Length);
|
|
|
|
|
pMessagePack.m_pData[7] = 0x0D;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
{
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
byte[] reciveBuffer = waitClient.SendThenReturn(pMessagePack.m_pData, timeout);
|
|
|
|
|
|
|
|
|
|
_logger.Info($"接收原始报文:{_stringChange.bytesToHexStr(reciveBuffer,reciveBuffer.Length)}");
|
|
|
|
|
|
|
|
|
|
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer,reciveBuffer.Length);
|
|
|
|
|
|
|
|
|
|
List<TagInfo> tagInfoList = Device_DealTagInfoList(resultBuffer);
|
|
|
|
|
|
|
|
|
|
return tagInfoList;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException($"按时间段盘点异常:{e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 异步按时间段盘点
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="timeout"></param>
|
|
|
|
|
@ -224,7 +174,7 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Data != null && response.Data.Length > 0)
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
@ -232,16 +182,21 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, timeout))
|
|
|
|
|
{
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
|
|
|
|
|
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, timeout);
|
|
|
|
|
_logger.Info($"{m_deviceID}发送读取指令{_stringChange.bytesToHexStr(pMessagePack.m_pData,pMessagePack.m_pData.Length)}");
|
|
|
|
|
_logger.Info($"{m_deviceID}发送读取指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
|
|
|
|
|
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
|
|
|
|
|
_logger.Info($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer,resultBuffer.Length)}");
|
|
|
|
|
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
|
|
|
|
|
_logger.Info($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer, resultBuffer.Length)}");
|
|
|
|
|
|
|
|
|
|
tagInfoList = Device_DealTagInfoList(resultBuffer);
|
|
|
|
|
|
|
|
|
|
return tagInfoList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tagInfoList = Device_DealTagInfoList(resultBuffer);
|
|
|
|
|
|
|
|
|
|
return tagInfoList;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
@ -287,7 +242,7 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Data != null && response.Data.Length > 0)
|
|
|
|
|
if ( response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
@ -296,15 +251,14 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000);
|
|
|
|
|
|
|
|
|
|
//byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
|
|
|
|
|
|
|
|
|
|
if (reciveBuffer[3] == 0x51)
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
if (reciveBuffer[3] == 0x51)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
@ -371,7 +325,7 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Data != null && response.Data.Length > 0)
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
@ -380,16 +334,15 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
|
|
|
|
|
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000);
|
|
|
|
|
_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
//byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
|
|
|
|
|
|
|
|
|
|
if (reciveBuffer[3] == 0x42)
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
if (reciveBuffer[3] == 0x42)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
@ -424,7 +377,7 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Data != null && response.Data.Length > 0)
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
@ -432,18 +385,21 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000);
|
|
|
|
|
|
|
|
|
|
if (reciveBuffer[3] == 0x72)
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
|
|
|
|
|
{
|
|
|
|
|
byte[] bDB = new byte[2];
|
|
|
|
|
bDB[0] = reciveBuffer[6];
|
|
|
|
|
bDB[1] = reciveBuffer[7];
|
|
|
|
|
DB = Convert.ToInt32(_stringChange.bytesToHexStr(bDB, 2), 16) / 100;
|
|
|
|
|
return DB;
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
if (reciveBuffer[3] == 0x72)
|
|
|
|
|
{
|
|
|
|
|
byte[] bDB = new byte[2];
|
|
|
|
|
bDB[0] = reciveBuffer[6];
|
|
|
|
|
bDB[1] = reciveBuffer[7];
|
|
|
|
|
DB = Convert.ToInt32(_stringChange.bytesToHexStr(bDB, 2), 16) / 100;
|
|
|
|
|
return DB;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DB;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
@ -469,12 +425,12 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_tcpClient.SafeDispose();
|
|
|
|
|
_tcpClient.CloseAsync();
|
|
|
|
|
_tcpClient.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
_logger.Error(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -842,6 +798,93 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
}
|
|
|
|
|
return epcLength;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置过滤参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Filter"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<bool> Set_FilterData(string Filter)
|
|
|
|
|
{
|
|
|
|
|
bool iflag = false;
|
|
|
|
|
Filter = "FC 08";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(Filter))
|
|
|
|
|
{
|
|
|
|
|
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
{
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
Filter = "filter " + Filter.Replace(" ", "").Length / 2 + " " + Filter + "\r\n";
|
|
|
|
|
//byte[] reciveBuffer = await waitClient.SendThenReturnAsync(Filter + "\r\n", 2000);
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync(Filter, 2000))
|
|
|
|
|
{
|
|
|
|
|
var memory = responsedData.Memory;
|
|
|
|
|
string result = Encoding.GetEncoding("GBK").GetString(memory.ToArray(), 0, memory.Length);
|
|
|
|
|
_logger.Info($"{m_deviceID}接收设置过滤指令{result}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
//_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
}
|
|
|
|
|
return iflag;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return iflag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取过滤参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<string> Get_FilterData()
|
|
|
|
|
{
|
|
|
|
|
string iflag = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
{
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
|
|
|
|
|
//byte[] reciveBuffer = await waitClient.SendThenReturnAsync("filter?\r\n", 2000);
|
|
|
|
|
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync("filter?\r\n", 2000))
|
|
|
|
|
{
|
|
|
|
|
var memory = responsedData.Memory;
|
|
|
|
|
string result = Encoding.GetEncoding("GBK").GetString(memory.ToArray(), 0, memory.Length);
|
|
|
|
|
_logger.Info($"{m_deviceID}接收设置过滤指令{result}");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
return iflag;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return iflag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|