diff --git a/SocketExample/TCPWindowV2.xaml b/SocketExample/TCPWindowV2.xaml
index 6673606..46b8ee2 100644
--- a/SocketExample/TCPWindowV2.xaml
+++ b/SocketExample/TCPWindowV2.xaml
@@ -6,7 +6,7 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:SocketExample"
mc:Ignorable="d"
- Title="RFID读写器多终端监控软件v1.031" Height="450" Width="800">
+ Title="RFID读写器多终端监控软件v1.041" Height="450" Width="800">
-
-
-
-
-
+
+
+
+
+
+
@@ -62,126 +63,136 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
-
-
-
+
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/SocketExample/TCPWindowV2.xaml.cs b/SocketExample/TCPWindowV2.xaml.cs
index ab8cbf1..8ebd791 100644
--- a/SocketExample/TCPWindowV2.xaml.cs
+++ b/SocketExample/TCPWindowV2.xaml.cs
@@ -12,6 +12,7 @@ using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -21,9 +22,11 @@ using System.Windows.Input;
using System.Windows.Markup;
using System.Xml;
using GalaSoft.MvvmLight.Command;
+using Google.Protobuf.WellKnownTypes;
using K4os.Compression.LZ4.Streams.Abstractions;
using Mesnac.Log;
using Microsoft.Xaml.Behaviors.Core;
+using Mysqlx.Crud;
using Org.BouncyCastle.Utilities.Encoders;
using TouchSocket.Core;
using TouchSocket.Sockets;
@@ -70,6 +73,12 @@ namespace SocketExample
OnPropertyChanged(); // 通知 UI 更新
}
}
+ public string _actiontype;//触发动作
+ public string ActionType { get => _actiontype; set { _actiontype = value; OnPropertyChanged(); } }
+
+ public string _timeout;//时间段盘点
+ public string TimeOut { get => _timeout; set { _timeout = value; OnPropertyChanged(); } }
+
private string _rssiinfo;//RSSI强度
public string RSSIinfo { get => _rssiinfo; set { _rssiinfo = value; OnPropertyChanged(); } }
private string _countinfo;//count数值
@@ -157,6 +166,10 @@ namespace SocketExample
public LinkCommand getpowercomn;//获取功率
+ public LinkCommand stopreadingcomn;//停止连续读取功能
+
+ public LinkCommand sendactioncomn;
+
public LinkCommand powerselectchanged;
Thread GPIOthread;
@@ -168,7 +181,9 @@ namespace SocketExample
Text = $"客户端{index + 1}";
linkcomn = new LinkCommand(Button_Link);//绑定按钮的链接事件
readcomn = new LinkCommand(Button_Read);
+ stopreadingcomn = new LinkCommand(Button_StopReading);
sendcomn = new LinkCommand(Button_Click_Send);//绑定发送按钮的事件
+ sendactioncomn = new LinkCommand (Button_SendActionComn);
disconnectcomn = new LinkCommand(Button_disconnect);//绑定断连按钮的事件
clearcomn = new LinkCommand(Button_clear);//绑定清空按钮的事件
setpowercomn = new LinkCommand(Button_SetPower);
@@ -181,7 +196,7 @@ namespace SocketExample
//页面初始化
int[] Powerdatasource = {5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33};
string[] GPOdatasource = {"高","低"};
- string[] SendTextdatasource = { "读取"};
+ string[] SendTextdatasource = { "单次读取","时间段盘点"};
MessageText = string.Empty;
IPtext = "192.168.0.7";//默认IP
@@ -211,6 +226,8 @@ namespace SocketExample
public LinkCommand _readcomn { get { return readcomn; } }
+ public LinkCommand _stopreadingcomn { get { return stopreadingcomn; } }
+
public LinkCommand _sendcomn { get { return sendcomn; } }
public LinkCommand _disconnectcomn { get { return disconnectcomn; } }
@@ -218,6 +235,7 @@ namespace SocketExample
public LinkCommand _clearcomn { get { return clearcomn; } }
public LinkCommand _setpowercomn { get { return setpowercomn; } }
public LinkCommand _getpowercomn { get { return getpowercomn; } }
+ public LinkCommand _sendactioncomn { get { return sendactioncomn; } }
#endregion
#region socket事件
@@ -250,12 +268,49 @@ namespace SocketExample
{
switch (commandState)
{
+ case "01":
+ try
+ {
+ byte[] newData = new byte[data.Length + 1];
+ Array.Copy(data, 0, newData, 0, 5); // 复制前半部分 // 插入新值
+ Array.Copy(data, 5, newData, 5, 4);
+ Array.Copy(data, 5, newData, 6, data.Length - 5);
+ Timeinfo = $"{currentTime} {time.Substring(0, 10)}";//获取时间
+ string NewDataString = BitConverter.ToString(newData).Replace("-", " ");
+
+ int startTemp = 33;
+
+ //Infotext += $"({currentTime})客户端接收到EPC信息:\n{EPCASC}\n\n";
+
+ List taglist = GetTagInfos(newData);
+ ObservableCollection items = new ObservableCollection();
+ for (int j = 0; j < taglist.Count; j++)
+ {
+ int TempLength = taglist[j].EPCstring.Length * 3 - 1;
+ EPCinfo = NewDataString.Substring(startTemp, TempLength);
+ items.Add(new TagItem(taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
+ startTemp += 16 + TempLength;
+ string year = DateTime.Now.ToString("yyyy-MM-dd");
+ EnsureFolderExists($"日志文件夹/{year}/{Text}");
+ path = $"日志文件夹/{year}/{Text}/" + path + Text + ".txt";
+ writeToTxt(path, $"EPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________");
+ path = "";
+
+ //LogService.Instance.Debug("");
+ }
+
+ TagItems = items;
+ }
+ catch (Exception ex)
+ {
+ Infotext += ex;
+ }
+
+ break;
+
case "02":
try
{
- RSSIinfo = Convert.ToInt32(readStateString.Substring(14, 2), 16).ToString();//RSSI
- Countinfo = Convert.ToInt32(readStateString.Substring(12, 2), 16).ToString();//Count
- int TagNumber = Convert.ToInt32(readStateString.Substring(10,2),16);
Timeinfo = $"{currentTime} {time.Substring(0, 10)}";//获取时间
int startTemp = 33;
@@ -425,6 +480,9 @@ namespace SocketExample
EPCASC = "###";
EPCinfo = "###";
Timeinfo = $" {currentTime}\n{time.Substring(0, 10)}";//获取时间
+ ObservableCollection items = new ObservableCollection();
+ items.Add(new TagItem(EPCASC, EPCinfo, RSSIinfo, Countinfo, Timeinfo));
+ TagItems = items;
break;
}
}
@@ -469,7 +527,7 @@ namespace SocketExample
Thread.Sleep(500);
- data = strToToHexByte("AA 55 02 02 03 E8 EB 0D");//获取1000ms内标签信息
+ data = strToToHexByte("AA 55 02 02 07 D0 D7 0D");//获取1000ms内标签信息
client.Send(data);
Thread.Sleep(1000);
@@ -577,7 +635,7 @@ namespace SocketExample
{
try
{
- byte[] data = strToToHexByte("AA 55 02 02 03 E8 EB 0D");//获取1000ms内标签信息
+ byte[] data = strToToHexByte("AA 55 02 02 07 D0 D7 0D");//获取2000ms内标签信息
client.Send(data);
}
catch (Exception ex) {
@@ -586,6 +644,20 @@ namespace SocketExample
}
+ void Button_StopReading()
+ {
+ try
+ {
+ byte[] data = strToToHexByte("AA 55 02 12 00 00 10 0D");//停止连续盘点
+ client.Send(data);
+ }
+ catch (Exception ex)
+ {
+ Infotext += $"发送读取命令时出错: {ex.Message}\n";
+ }
+
+ }
+
void Button_SetPower()
{
@@ -654,7 +726,51 @@ namespace SocketExample
Infotext += $"处理请求时出错: {ex.Message}\n";
}
}
+
+ void Button_SendActionComn()
+ {
+ try
+ {
+ string message = ActionType;
+ if (message == string.Empty || message == null)
+ {
+ MessageBox.Show("请选择触发动作!");
+ }
+ else
+ {
+ try
+ {
+ byte[] data = null;
+ switch (message)
+ {
+ case "单次读取":
+ ActionType = "单次读取";
+ data = strToToHexByte("AA 55 02 01 00 64 67 0D");//单次
+ break;
+ /*
+ case "连续读取":
+ ActionType = "连续读取";
+ data = strToToHexByte("AA 55 02 11 00 00 13 0D");//连续
+ break;
+ */
+ case "时间段盘点":
+ ActionType = "时间段盘点";
+ data = strToToHexByte(CheckDuringTime());
+ break;
+ }
+ client.Send(data);
+ }
+ catch (Exception ex)
+ {
+ Infotext += ex.Message;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+ }
void Button_disconnect()
{
client.Close();//断开连接
@@ -703,6 +819,7 @@ namespace SocketExample
break;
}
+ sender.SelectedItem = null;
}
catch(Exception ex)
{
@@ -764,13 +881,26 @@ namespace SocketExample
string selcetion = sender.SelectedItem?.ToString();
try
{
+ //byte[] data = null;
switch (selcetion)
{
- case "读取":
- MessageText = "AA 55 02 02 03 E8 EB 0D";
+ case "单次读取":
+ ActionType = "单次读取";
+ //data = strToToHexByte("AA 55 02 01 00 64 67 0D");//单次
+ break;
+ /*
+ case "连续读取":
+ ActionType = "连续读取";
+ data = strToToHexByte("AA 55 02 11 00 00 13 0D");//连续
+ break;
+ */
+ case "时间段盘点":
+ ActionType = "时间段盘点";
+ //data = strToToHexByte(CheckDuringTime());
break;
-
}
+ //client.Send(data);
+ sender.SelectedItem = null;
}
catch (Exception ex)
{
@@ -778,6 +908,14 @@ namespace SocketExample
}
}
+
+ string CheckDuringTime()
+ {
+ string actionstring = "AA 55 02 02 ";
+ actionstring += Convert.ToInt32(TimeOut).ToString("X").PadLeft(4, '0').Insert(2, " ")+ " ";
+ actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16) + " 0D";
+ return actionstring;
+ }
void SaveCommand()
{
byte[] confirmdata1 = strToToHexByte("AA 55 05 5F ");//保存命令