diff --git a/SlnMesnac.Config/DeviceInfoConfig.cs b/SlnMesnac.Config/DeviceInfoConfig.cs
index b54ca6e..229d038 100644
--- a/SlnMesnac.Config/DeviceInfoConfig.cs
+++ b/SlnMesnac.Config/DeviceInfoConfig.cs
@@ -76,7 +76,12 @@ namespace SlnMesnac.Config
///
/// 二次验证超时时间(毫秒)
///
- public int? VerifyTimeoutMilliseconds { get; set; }
+ public int? VerifyTimeoutMilliseconds { get; set; }
+
+ ///
+ /// 写入超时时间(毫秒)
+ ///
+ public int? WriteTimeoutMilliseconds { get; set; }
}
}
\ No newline at end of file
diff --git a/SlnMesnac.Rfid/Factory/RflyFactory.cs b/SlnMesnac.Rfid/Factory/RflyFactory.cs
index f58095d..53ed73b 100644
--- a/SlnMesnac.Rfid/Factory/RflyFactory.cs
+++ b/SlnMesnac.Rfid/Factory/RflyFactory.cs
@@ -98,10 +98,10 @@ namespace SlnMesnac.Rfid.Factory
{
//lock (GloalVar.TCPLocker)
//{
- m_deviceID = deviceid;
- m_strIP = ip;
- _tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
- _tcpClient.ConnectAsync(1500).GetAwaiter().GetResult();
+ m_deviceID = deviceid;
+ m_strIP = ip;
+ _tcpClient.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
+ _tcpClient.ConnectAsync(1500).GetAwaiter().GetResult();
//}
_tcpClient.Received = (client, e) =>
{
@@ -120,7 +120,7 @@ namespace SlnMesnac.Rfid.Factory
Array.Copy(e.Memory.Span.ToArray(), 0, receivedBuffer, 0, e.Memory.Span.Length);
if (receivedBuffer.Length > 3)
{
-
+
//心跳
if (e.Memory.Span.ToArray()[3] == 0xBF)
{
@@ -193,50 +193,50 @@ namespace SlnMesnac.Rfid.Factory
{
//lock (GloalVar.TCPLocker)
//{
- Log.Information($"设置心跳:【{second}】秒");
- byte[] data = new byte[3];
- data[0] = 0x00;
- data[1] = second;
- data[2] = 0x01;
+ Log.Information($"设置心跳:【{second}】秒");
+ byte[] data = new byte[3];
+ data[0] = 0x00;
+ data[1] = second;
+ data[2] = 0x01;
- BaseSendDataEntity entity = new BaseSendDataEntity()
+ BaseSendDataEntity entity = new BaseSendDataEntity()
+ {
+ Code = 0xBF,
+ Data = data
+ };
+
+ byte[] result = BaseRFIDDataAnalyse.BaseSendDataAnalyse(entity);
+
+ var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
+ {
+ FilterFunc = response =>
{
- 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)
+ // 检查响应数据是否符合预期
+ if (response.Memory.Length > 0)
{
+ // 可以根据实际情况添加更多的检查逻辑
return true;
}
- else
- {
- return false;
- }
+ 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;
+ }
+ else
+ {
+ return false;
+ }
+ }
//}
}
@@ -556,47 +556,48 @@ namespace SlnMesnac.Rfid.Factory
{
//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 指令封装
+ #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();
+ Log.Information($"{deviceid} 停止盘点");
+ //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)
@@ -619,46 +620,46 @@ namespace SlnMesnac.Rfid.Factory
//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] = 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 指令封装
+ #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 指令封装
- _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;
+ _tcpClient.SendAsync(pMessagePack.m_pData).GetAwaiter().GetResult();
+ Log.Information($"{deviceid} 开始盘点");
+ //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)
@@ -713,102 +714,102 @@ namespace SlnMesnac.Rfid.Factory
{
//lock (GloalVar.TCPLocker)
//{
- #region 指令封装
- //自动根据写入数据封装
- Base03HENtity rawData = new Base03HENtity()
+ #region 指令封装
+ //自动根据写入数据封装
+ Base03HENtity rawData = new Base03HENtity()
+ {
+ TimeOut = _stringChange.IntToBytes(2, 5000),
+ 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 =>
{
- TimeOut = _stringChange.IntToBytes(2, 5000),
- 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)
{
- // 检查响应数据是否符合预期
- if (response.Memory.Length > 0)
- {
- // 可以根据实际情况添加更多的检查逻辑
- return true;
- }
- return false;
- }
- });
- Log.Information($"{m_deviceID}发送写入指令{_stringChange.bytesToHexStr(result, result.Length)}");
- using (var responsedData = waitClient.SendThenResponseAsync(result, 6000).GetAwaiter().GetResult())
- {
- var reciveBuffer = responsedData.Memory.ToArray();
- Log.Information($"{m_deviceID}接收写入指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
- //只要收到消息,就算心跳
- if (GloalVar.HeartBeatRecoard.TryGetValue(deviceid, out var value))
- {
- GloalVar.HeartBeatRecoard[deviceid] = DateTime.Now;
- }
- else
- {
- GloalVar.HeartBeatRecoard.Add(deviceid, DateTime.Now);
- }
- if (reciveBuffer[3] == 0x03 && reciveBuffer[4] == 0x00)
- {
- Log.Information($"写入成功,写入数值{pWriteData}");
+ // 可以根据实际情况添加更多的检查逻辑
return true;
}
+ return false;
}
- return false;
+ });
+ Log.Information($"{m_deviceID}发送写入指令{_stringChange.bytesToHexStr(result, result.Length)}");
+ using (var responsedData = waitClient.SendThenResponseAsync(result, 6000).GetAwaiter().GetResult())
+ {
+ var reciveBuffer = responsedData.Memory.ToArray();
+ Log.Information($"{m_deviceID}接收写入指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
+ //只要收到消息,就算心跳
+ if (GloalVar.HeartBeatRecoard.TryGetValue(deviceid, out var value))
+ {
+ GloalVar.HeartBeatRecoard[deviceid] = DateTime.Now;
+ }
+ else
+ {
+ GloalVar.HeartBeatRecoard.Add(deviceid, DateTime.Now);
+ }
+ if (reciveBuffer[3] == 0x03 && reciveBuffer[4] == 0x00)
+ {
+ Log.Information($"写入成功,写入数值{pWriteData}");
+ return true;
+ }
+ }
+ return false;
//}
-
+
}
catch (Exception e)
{
diff --git a/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs
index 601003a..3264ae0 100644
--- a/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs
+++ b/SlnMesnac.WPF/ViewModel/IndexPage/ProductionLineViewModel.cs
@@ -31,6 +31,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
+using System.Windows.Markup;
using System.Windows.Threading;
using System.Xml.Serialization;
using TouchSocket.Core;
@@ -60,9 +61,11 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
private RealReadDataImpl databaseService = RealReadDataImpl.Instance;
private System.Threading.Timer ReReadTimer;
private bool IsVerify = false;
+ private int WriteTime = 0;
private string LastWrite;
private string LastRFIDEPC;
private CancellationTokenSource? _verifyCts;
+ private CancellationTokenSource? _writeCts;
#endregion
@@ -149,7 +152,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
public ProductionLineViewModel()
{
- GetOrderInfoCommand = new RelayCommand