|
|
|
|
@ -96,10 +96,13 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_deviceID = deviceid;
|
|
|
|
|
m_strIP = ip;
|
|
|
|
|
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
|
|
|
|
|
await _tcpClient.ConnectAsync(1500);
|
|
|
|
|
lock (GloalVar.TCPLocker)
|
|
|
|
|
{
|
|
|
|
|
m_deviceID = deviceid;
|
|
|
|
|
m_strIP = ip;
|
|
|
|
|
_tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
|
|
|
|
|
_tcpClient.ConnectAsync(1500).GetAwaiter().GetResult();
|
|
|
|
|
}
|
|
|
|
|
_tcpClient.Received = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
//从客户端收到信息
|
|
|
|
|
@ -186,47 +189,50 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<bool> Set_HeartBeat(byte second)
|
|
|
|
|
{
|
|
|
|
|
byte[] data = new byte[3];
|
|
|
|
|
data[0] = 0x00;
|
|
|
|
|
data[1] = second;
|
|
|
|
|
data[2] = 0x01;
|
|
|
|
|
|
|
|
|
|
BaseSendDataEntity entity = new BaseSendDataEntity()
|
|
|
|
|
lock (GloalVar.TCPLocker)
|
|
|
|
|
{
|
|
|
|
|
Code = 0xBF,
|
|
|
|
|
Data = data
|
|
|
|
|
};
|
|
|
|
|
byte[] data = new byte[3];
|
|
|
|
|
data[0] = 0x00;
|
|
|
|
|
data[1] = second;
|
|
|
|
|
data[2] = 0x01;
|
|
|
|
|
|
|
|
|
|
byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity);
|
|
|
|
|
|
|
|
|
|
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
{
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
BaseSendDataEntity entity = new BaseSendDataEntity()
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
Code = 0xBF,
|
|
|
|
|
Data = data
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity);
|
|
|
|
|
|
|
|
|
|
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
{
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
using (var responsedData = waitClient.SendThenResponseAsync(result, 2000).GetAwaiter().GetResult())
|
|
|
|
|
{
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
|
|
|
|
|
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
|
|
|
|
|
Log.Information($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer, resultBuffer.Length)}");
|
|
|
|
|
|
|
|
|
|
if (resultBuffer[3] == 0xBF || resultBuffer[4] == 0x00)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync(result, 2000))
|
|
|
|
|
{
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
|
|
|
|
|
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
|
|
|
|
|
Log.Information($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer, resultBuffer.Length)}");
|
|
|
|
|
|
|
|
|
|
if (resultBuffer[3] == 0xBF || resultBuffer[4] == 0x00)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -541,50 +547,54 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<bool> Set_StopIdentify()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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] = 0x12;
|
|
|
|
|
pMessagePack.m_pData[4] = 0x00;
|
|
|
|
|
pMessagePack.m_pData[5] = 0x00;
|
|
|
|
|
Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 4);
|
|
|
|
|
pMessagePack.m_pData[6] = _stringChange.CalculateVerify(bCRC, bCRC.Length);
|
|
|
|
|
pMessagePack.m_pData[7] = 0x0D;
|
|
|
|
|
#endregion 指令封装
|
|
|
|
|
lock (GloalVar.TCPLocker)
|
|
|
|
|
{
|
|
|
|
|
#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] = 0x12;
|
|
|
|
|
pMessagePack.m_pData[4] = 0x00;
|
|
|
|
|
pMessagePack.m_pData[5] = 0x00;
|
|
|
|
|
Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 4);
|
|
|
|
|
pMessagePack.m_pData[6] = _stringChange.CalculateVerify(bCRC, bCRC.Length);
|
|
|
|
|
pMessagePack.m_pData[7] = 0x0D;
|
|
|
|
|
#endregion 指令封装
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_tcpClient.SendAsync(pMessagePack.m_pData).GetAwaiter().GetResult();
|
|
|
|
|
//var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
//{
|
|
|
|
|
// FilterFunc = response =>
|
|
|
|
|
// {
|
|
|
|
|
// // 检查响应数据是否符合预期
|
|
|
|
|
// if (response.Memory.Length > 0)
|
|
|
|
|
// {
|
|
|
|
|
// // 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
//Log.Information($"{m_deviceID}发送停止连续盘点指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
//using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
|
|
|
|
|
//{
|
|
|
|
|
// var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
// Log.Information($"{m_deviceID}接收停止连续盘点指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
// if (reciveBuffer[3] == 0x12)
|
|
|
|
|
// {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//return false;
|
|
|
|
|
return true;
|
|
|
|
|
_tcpClient.SendAsync(pMessagePack.m_pData).GetAwaiter().GetResult();
|
|
|
|
|
//var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
//{
|
|
|
|
|
// FilterFunc = response =>
|
|
|
|
|
// {
|
|
|
|
|
// // 检查响应数据是否符合预期
|
|
|
|
|
// if (response.Memory.Length > 0)
|
|
|
|
|
// {
|
|
|
|
|
// // 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
//Log.Information($"{m_deviceID}发送停止连续盘点指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
//using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
|
|
|
|
|
//{
|
|
|
|
|
// var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
// Log.Information($"{m_deviceID}接收停止连续盘点指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
// if (reciveBuffer[3] == 0x12)
|
|
|
|
|
// {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
@ -603,46 +613,50 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
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] = 0x11;
|
|
|
|
|
pMessagePack.m_pData[4] = 0x00;
|
|
|
|
|
pMessagePack.m_pData[5] = 0x00;
|
|
|
|
|
Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 4);
|
|
|
|
|
pMessagePack.m_pData[6] = _stringChange.CalculateVerify(bCRC, bCRC.Length);
|
|
|
|
|
pMessagePack.m_pData[7] = 0x0D;
|
|
|
|
|
#endregion 指令封装
|
|
|
|
|
lock (GloalVar.TCPLocker)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_tcpClient.SendAsync(pMessagePack.m_pData).GetAwaiter().GetResult();
|
|
|
|
|
#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] = 0x11;
|
|
|
|
|
pMessagePack.m_pData[4] = 0x00;
|
|
|
|
|
pMessagePack.m_pData[5] = 0x00;
|
|
|
|
|
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 =>
|
|
|
|
|
// {
|
|
|
|
|
// // 检查响应数据是否符合预期
|
|
|
|
|
// if (response.Memory.Length > 0)
|
|
|
|
|
// {
|
|
|
|
|
// // 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
//Log.Information($"{m_deviceID}发送连续盘点指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
//using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
|
|
|
|
|
//{
|
|
|
|
|
// var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
// Log.Information($"{m_deviceID}接收连续盘点指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
// if (reciveBuffer[3] == 0x11)
|
|
|
|
|
// {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
return true;
|
|
|
|
|
_tcpClient.SendAsync(pMessagePack.m_pData).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
//var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
//{
|
|
|
|
|
// FilterFunc = response =>
|
|
|
|
|
// {
|
|
|
|
|
// // 检查响应数据是否符合预期
|
|
|
|
|
// if (response.Memory.Length > 0)
|
|
|
|
|
// {
|
|
|
|
|
// // 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
//Log.Information($"{m_deviceID}发送连续盘点指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
|
|
|
|
|
//using (var responsedData = await waitClient.SendThenResponseAsync(pMessagePack.m_pData, 2000))
|
|
|
|
|
//{
|
|
|
|
|
// var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
// Log.Information($"{m_deviceID}接收连续盘点指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
// if (reciveBuffer[3] == 0x11)
|
|
|
|
|
// {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
@ -659,6 +673,7 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<bool> Set_Write(byte[] pSelectData, string pWriteData)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
byte[] bWriteData = null;
|
|
|
|
|
if (Convert.ToByte(pWriteData.Length % 2) != 0)
|
|
|
|
|
{
|
|
|
|
|
@ -693,91 +708,95 @@ namespace SlnMesnac.Rfid.Factory
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 指令封装
|
|
|
|
|
//自动根据写入数据封装
|
|
|
|
|
Base03HENtity rawData = new Base03HENtity()
|
|
|
|
|
lock (GloalVar.TCPLocker)
|
|
|
|
|
{
|
|
|
|
|
TimeOut = _stringChange.IntToBytes(2, 1000),
|
|
|
|
|
AccessPassword = _stringChange.IntToBytes(4, 0),
|
|
|
|
|
SelectBank = 01,
|
|
|
|
|
SelectAddress = _stringChange.IntToBytes(4, 32),
|
|
|
|
|
SelectLength = (byte)(pSelectData.Count() * 8),
|
|
|
|
|
SelectData = pSelectData,
|
|
|
|
|
WriteBank = 01,
|
|
|
|
|
WriteAddress = _stringChange.IntToBytes(4, 1),
|
|
|
|
|
WordCount = (byte)((finalWriteData.Count() / 2)),
|
|
|
|
|
WriteData = finalWriteData
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
#endregion 指令封装
|
|
|
|
|
|
|
|
|
|
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
{
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
#region 指令封装
|
|
|
|
|
//自动根据写入数据封装
|
|
|
|
|
Base03HENtity rawData = new Base03HENtity()
|
|
|
|
|
{
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
TimeOut = _stringChange.IntToBytes(2, 1000),
|
|
|
|
|
AccessPassword = _stringChange.IntToBytes(4, 0),
|
|
|
|
|
SelectBank = 01,
|
|
|
|
|
SelectAddress = _stringChange.IntToBytes(4, 32),
|
|
|
|
|
SelectLength = (byte)(pSelectData.Count() * 8),
|
|
|
|
|
SelectData = pSelectData,
|
|
|
|
|
WriteBank = 01,
|
|
|
|
|
WriteAddress = _stringChange.IntToBytes(4, 1),
|
|
|
|
|
WordCount = (byte)((finalWriteData.Count() / 2)),
|
|
|
|
|
WriteData = finalWriteData
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
#endregion 指令封装
|
|
|
|
|
|
|
|
|
|
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
|
|
|
|
|
{
|
|
|
|
|
FilterFunc = response =>
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
// 检查响应数据是否符合预期
|
|
|
|
|
if (response.Memory.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
// 可以根据实际情况添加更多的检查逻辑
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Log.Information($"{m_deviceID}发送写入指令{_stringChange.bytesToHexStr(result, result.Length)}");
|
|
|
|
|
using (var responsedData = waitClient.SendThenResponseAsync(result, 2000).GetAwaiter().GetResult())
|
|
|
|
|
{
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
Log.Information($"{m_deviceID}接收写入指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
if (reciveBuffer[3] == 0x03 && reciveBuffer[4] == 0x00)
|
|
|
|
|
{
|
|
|
|
|
Log.Information($"写入成功,写入数值{pWriteData}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Log.Information($"{m_deviceID}发送写入指令{_stringChange.bytesToHexStr(result, result.Length)}");
|
|
|
|
|
using (var responsedData = await waitClient.SendThenResponseAsync(result, 2000))
|
|
|
|
|
{
|
|
|
|
|
var reciveBuffer = responsedData.Memory.ToArray();
|
|
|
|
|
Log.Information($"{m_deviceID}接收写入指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
|
|
|
|
|
if (reciveBuffer[3] == 0x03 && reciveBuffer[4] == 0x00)
|
|
|
|
|
{
|
|
|
|
|
Log.Information($"写入成功,写入数值{pWriteData}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
|