|
|
|
@ -75,7 +75,9 @@ namespace SocketExample
|
|
|
|
private string _linkbuttontext { get; set; }
|
|
|
|
private string _linkbuttontext { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private string _infotext;//信息框
|
|
|
|
private string _infotext;//信息框
|
|
|
|
public string Infotext { get => _infotext; set
|
|
|
|
public string Infotext
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get => _infotext; set
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_infotext = value;
|
|
|
|
_infotext = value;
|
|
|
|
OnPropertyChanged(); // 通知 UI 更新
|
|
|
|
OnPropertyChanged(); // 通知 UI 更新
|
|
|
|
@ -126,7 +128,7 @@ namespace SocketExample
|
|
|
|
public string Port3WriteText { get => _port3writetext; set { _port3writetext = value; OnPropertyChanged(); } }
|
|
|
|
public string Port3WriteText { get => _port3writetext; set { _port3writetext = value; OnPropertyChanged(); } }
|
|
|
|
public string Port4WriteText { get => _port4writetext; set { _port4writetext = value; OnPropertyChanged(); } }
|
|
|
|
public string Port4WriteText { get => _port4writetext; set { _port4writetext = value; OnPropertyChanged(); } }
|
|
|
|
public int[] PortComboBox { get => _portComboBox; set { _portComboBox = value; OnPropertyChanged(); } }
|
|
|
|
public int[] PortComboBox { get => _portComboBox; set { _portComboBox = value; OnPropertyChanged(); } }
|
|
|
|
public string[] GPOComboBox { get => _gpoComboBox;set { _gpoComboBox = value; OnPropertyChanged(); } }
|
|
|
|
public string[] GPOComboBox { get => _gpoComboBox; set { _gpoComboBox = value; OnPropertyChanged(); } }
|
|
|
|
public string[] SendTextComboBox { get => _sendtextComboBox; set { _sendtextComboBox = value; OnPropertyChanged(); } }
|
|
|
|
public string[] SendTextComboBox { get => _sendtextComboBox; set { _sendtextComboBox = value; OnPropertyChanged(); } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -191,7 +193,7 @@ namespace SocketExample
|
|
|
|
readcomn = new LinkCommand(Button_Read);
|
|
|
|
readcomn = new LinkCommand(Button_Read);
|
|
|
|
stopreadingcomn = new LinkCommand(Button_StopReading);
|
|
|
|
stopreadingcomn = new LinkCommand(Button_StopReading);
|
|
|
|
sendcomn = new LinkCommand(Button_Click_Send);//绑定发送按钮的事件
|
|
|
|
sendcomn = new LinkCommand(Button_Click_Send);//绑定发送按钮的事件
|
|
|
|
sendactioncomn = new LinkCommand (Button_SendActionComn);
|
|
|
|
sendactioncomn = new LinkCommand(Button_SendActionComn);
|
|
|
|
disconnectcomn = new LinkCommand(Button_disconnect);//绑定断连按钮的事件
|
|
|
|
disconnectcomn = new LinkCommand(Button_disconnect);//绑定断连按钮的事件
|
|
|
|
clearcomn = new LinkCommand(Button_clear);//绑定清空按钮的事件
|
|
|
|
clearcomn = new LinkCommand(Button_clear);//绑定清空按钮的事件
|
|
|
|
setpowercomn = new LinkCommand(Button_SetPower);
|
|
|
|
setpowercomn = new LinkCommand(Button_SetPower);
|
|
|
|
@ -202,11 +204,11 @@ namespace SocketExample
|
|
|
|
TextChangedCommand = new RelayCommand<ScrollViewer>(TextBlock_SelectChanged);
|
|
|
|
TextChangedCommand = new RelayCommand<ScrollViewer>(TextBlock_SelectChanged);
|
|
|
|
|
|
|
|
|
|
|
|
//页面初始化
|
|
|
|
//页面初始化
|
|
|
|
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};
|
|
|
|
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[] GPOdatasource = { "高", "低" };
|
|
|
|
string[] SendTextdatasource = { "单次读取","时间段盘点"};
|
|
|
|
string[] SendTextdatasource = { "单次读取", "时间段盘点" };
|
|
|
|
|
|
|
|
|
|
|
|
Borderwidth = ((int)SystemParameters.PrimaryScreenWidth-25)/4;
|
|
|
|
Borderwidth = ((int)SystemParameters.PrimaryScreenWidth - 60) / 4; //动态生成界面宽度
|
|
|
|
MessageText = string.Empty;
|
|
|
|
MessageText = string.Empty;
|
|
|
|
IPtext = "192.168.0.7";//默认IP
|
|
|
|
IPtext = "192.168.0.7";//默认IP
|
|
|
|
Porttext = "20108";//默认端口
|
|
|
|
Porttext = "20108";//默认端口
|
|
|
|
@ -259,9 +261,10 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
|
|
private Task onRecieved(ITcpClient client, ReceivedDataEventArgs e) //接收事件
|
|
|
|
private Task onRecieved(ITcpClient client, ReceivedDataEventArgs e) //接收事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Text = Text.Replace(" ", "");
|
|
|
|
path = "";
|
|
|
|
path = "";
|
|
|
|
string time = DateTime.Now.ToString();
|
|
|
|
string time = DateTime.Now.ToString();
|
|
|
|
string currentTime = time.Substring(9, time.Length-9);
|
|
|
|
string currentTime = time.Substring(9, time.Length - 9);
|
|
|
|
var mes = e.ByteBlock.Span.ToString(Encoding.UTF8);
|
|
|
|
var mes = e.ByteBlock.Span.ToString(Encoding.UTF8);
|
|
|
|
byte[] data = e.ByteBlock.Span.ToArray();
|
|
|
|
byte[] data = e.ByteBlock.Span.ToArray();
|
|
|
|
string hexString = BitConverter.ToString(data).Replace("-", " ");
|
|
|
|
string hexString = BitConverter.ToString(data).Replace("-", " ");
|
|
|
|
@ -271,7 +274,7 @@ namespace SocketExample
|
|
|
|
string dataLength = readStateString.Substring(4, 2);//获取字符串中内容长度
|
|
|
|
string dataLength = readStateString.Substring(4, 2);//获取字符串中内容长度
|
|
|
|
string commandState = readStateString.Substring(6, 2);//获取命令
|
|
|
|
string commandState = readStateString.Substring(6, 2);//获取命令
|
|
|
|
|
|
|
|
|
|
|
|
if(commandState != "81")
|
|
|
|
if (commandState != "81")
|
|
|
|
Infotext += $"({currentTime})客户端接收到信息:\n{hexString}\n\n";
|
|
|
|
Infotext += $"({currentTime})客户端接收到信息:\n{hexString}\n\n";
|
|
|
|
|
|
|
|
|
|
|
|
int i = Convert.ToInt32(dataLength, 16);
|
|
|
|
int i = Convert.ToInt32(dataLength, 16);
|
|
|
|
@ -299,12 +302,12 @@ namespace SocketExample
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int TempLength = taglist[j].EPCstring.Length * 3 - 1;
|
|
|
|
int TempLength = taglist[j].EPCstring.Length * 3 - 1;
|
|
|
|
EPCinfo = NewDataString.Substring(startTemp, TempLength);
|
|
|
|
EPCinfo = NewDataString.Substring(startTemp, TempLength);
|
|
|
|
items.Add(new TagItem(hexString,taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
|
|
|
|
items.Add(new TagItem(hexString, taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
|
|
|
|
startTemp += 16 + TempLength;
|
|
|
|
startTemp += 16 + TempLength;
|
|
|
|
string year = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
string year = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
EnsureFolderExists($"日志文件夹/{year}/{Text}");
|
|
|
|
EnsureFolderExists($"日志文件夹/{year}/{Text}");
|
|
|
|
path = $"日志文件夹/{year}/{Text}/" + Text +"("+ IPtext+")"+ ".txt";
|
|
|
|
path = $"日志文件夹/{year}/{Text}/" + Text + "(" + IPtext + ")" + ".txt";
|
|
|
|
EnsureTxtExists(path,Text, IPtext, Porttext);
|
|
|
|
EnsureTxtExists(path, Text, IPtext, Porttext);
|
|
|
|
writeToTxt(path, $"接收消息:{hexString}\nEPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________");
|
|
|
|
writeToTxt(path, $"接收消息:{hexString}\nEPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________");
|
|
|
|
path = "";
|
|
|
|
path = "";
|
|
|
|
|
|
|
|
|
|
|
|
@ -333,9 +336,9 @@ namespace SocketExample
|
|
|
|
ObservableCollection<TagItem> items = new ObservableCollection<TagItem>();
|
|
|
|
ObservableCollection<TagItem> items = new ObservableCollection<TagItem>();
|
|
|
|
for (int j = 0; j < taglist.Count; j++)
|
|
|
|
for (int j = 0; j < taglist.Count; j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int TempLength = taglist[j].EPCstring.Length * 3 -1;
|
|
|
|
int TempLength = taglist[j].EPCstring.Length * 3 - 1;
|
|
|
|
EPCinfo = hexString.Substring(startTemp, TempLength);
|
|
|
|
EPCinfo = hexString.Substring(startTemp, TempLength);
|
|
|
|
items.Add(new TagItem(hexString,taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
|
|
|
|
items.Add(new TagItem(hexString, taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
|
|
|
|
startTemp += 16 + TempLength;
|
|
|
|
startTemp += 16 + TempLength;
|
|
|
|
string year = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
string year = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
EnsureFolderExists($"日志文件夹/{year}/{Text}");
|
|
|
|
EnsureFolderExists($"日志文件夹/{year}/{Text}");
|
|
|
|
@ -350,7 +353,8 @@ namespace SocketExample
|
|
|
|
TagItems = items;
|
|
|
|
TagItems = items;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
Infotext += ex;
|
|
|
|
Infotext += ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -379,7 +383,7 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
|
|
if (GPIBinInfo.Substring(j, 1) == "1")
|
|
|
|
if (GPIBinInfo.Substring(j, 1) == "1")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(GPI4 != "低")
|
|
|
|
if (GPI4 != "低")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GPI4 = "低";
|
|
|
|
GPI4 = "低";
|
|
|
|
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
|
|
|
|
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
|
|
|
|
@ -387,7 +391,7 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
if(GPI4 != "高")
|
|
|
|
if (GPI4 != "高")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GPI4 = "高";
|
|
|
|
GPI4 = "高";
|
|
|
|
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
|
|
|
|
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
|
|
|
|
@ -470,7 +474,7 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(GPIchange == true)
|
|
|
|
if (GPIchange == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
EnsureFolderExists($"日志文件夹/{GPIyear}/{Text}");
|
|
|
|
EnsureFolderExists($"日志文件夹/{GPIyear}/{Text}");
|
|
|
|
string temppath = $"日志文件夹/{GPIyear}/{Text}/" + Text + "GPI" + "(" + IPtext + ")" + ".txt";
|
|
|
|
string temppath = $"日志文件夹/{GPIyear}/{Text}/" + Text + "GPI" + "(" + IPtext + ")" + ".txt";
|
|
|
|
@ -486,7 +490,7 @@ namespace SocketExample
|
|
|
|
//获取功率信息
|
|
|
|
//获取功率信息
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int n = 0;n < (Convert.ToInt32(dataLength,16)/5);n++)
|
|
|
|
for (int n = 0; n < (Convert.ToInt32(dataLength, 16) / 5); n++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (n)
|
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -561,7 +565,7 @@ namespace SocketExample
|
|
|
|
EPCinfo = "No Read";
|
|
|
|
EPCinfo = "No Read";
|
|
|
|
Timeinfo = $" {time}";//获取时间
|
|
|
|
Timeinfo = $" {time}";//获取时间
|
|
|
|
ObservableCollection<TagItem> items = new ObservableCollection<TagItem>();
|
|
|
|
ObservableCollection<TagItem> items = new ObservableCollection<TagItem>();
|
|
|
|
items.Add(new TagItem(hexString,EPCASC, EPCinfo, RSSIinfo, Countinfo, Timeinfo));
|
|
|
|
items.Add(new TagItem(hexString, EPCASC, EPCinfo, RSSIinfo, Countinfo, Timeinfo));
|
|
|
|
TagItems = items;
|
|
|
|
TagItems = items;
|
|
|
|
string year = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
string year = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
EnsureFolderExists($"日志文件夹/{year}/{Text}");
|
|
|
|
EnsureFolderExists($"日志文件夹/{year}/{Text}");
|
|
|
|
@ -618,7 +622,7 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
|
|
|
|
|
|
GPIOthread = new Thread(new ThreadStart(delegate () { while (true) { byte[] data = strToToHexByte("AA 55 00 81 81 0D"); client.Send(data); Thread.Sleep(3000); } }));
|
|
|
|
GPIOthread = new Thread(new ThreadStart(delegate () { while (true) { byte[] data = strToToHexByte("AA 55 00 81 81 0D"); client.Send(data); Thread.Sleep(1000); } }));
|
|
|
|
GPIOthread.Start();//心跳获取GPIO状态
|
|
|
|
GPIOthread.Start();//心跳获取GPIO状态
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -634,7 +638,7 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
|
|
private string GPIChangeLog(string gpiInfo)
|
|
|
|
private string GPIChangeLog(string gpiInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(gpiInfo == "低")
|
|
|
|
if (gpiInfo == "低")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return "高 => 低";
|
|
|
|
return "高 => 低";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -651,7 +655,7 @@ namespace SocketExample
|
|
|
|
client.Send(data);
|
|
|
|
client.Send(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public byte GetXor(byte[] data,int m)
|
|
|
|
public byte GetXor(byte[] data, int m)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
byte CheckCode = 0;
|
|
|
|
byte CheckCode = 0;
|
|
|
|
int len = data.Length;
|
|
|
|
int len = data.Length;
|
|
|
|
@ -689,9 +693,9 @@ namespace SocketExample
|
|
|
|
return returnBytes;
|
|
|
|
return returnBytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void writeToTxt(string path,string content)
|
|
|
|
private static void writeToTxt(string path, string content)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
StreamWriter streamWriter = new StreamWriter(path,true);
|
|
|
|
StreamWriter streamWriter = new StreamWriter(path, true);
|
|
|
|
streamWriter.WriteLineAsync(content);
|
|
|
|
streamWriter.WriteLineAsync(content);
|
|
|
|
streamWriter.Close();
|
|
|
|
streamWriter.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -701,7 +705,7 @@ namespace SocketExample
|
|
|
|
#region 动态界面控件功能
|
|
|
|
#region 动态界面控件功能
|
|
|
|
async void Button_Link()//链接按钮的事件
|
|
|
|
async void Button_Link()//链接按钮的事件
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(LinkButtonText == "连接")
|
|
|
|
if (LinkButtonText == "连接")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -747,7 +751,8 @@ namespace SocketExample
|
|
|
|
byte[] data = strToToHexByte("AA 55 02 02 07 D0 D7 0D");//获取2000ms内标签信息
|
|
|
|
byte[] data = strToToHexByte("AA 55 02 02 07 D0 D7 0D");//获取2000ms内标签信息
|
|
|
|
client.Send(data);
|
|
|
|
client.Send(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
Infotext += $"发送读取命令时出错: {ex.Message}\n";
|
|
|
|
Infotext += $"发送读取命令时出错: {ex.Message}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -772,7 +777,7 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Port1ReadText == null || Port1WriteText == null|| Port2ReadText == null || Port2WriteText == null || Port3ReadText == null || Port3WriteText == null || Port4ReadText == null || Port4WriteText == null)
|
|
|
|
if (Port1ReadText == null || Port1WriteText == null || Port2ReadText == null || Port2WriteText == null || Port3ReadText == null || Port3WriteText == null || Port4ReadText == null || Port4WriteText == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("数值不可为空!");
|
|
|
|
MessageBox.Show("数值不可为空!");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -780,19 +785,20 @@ namespace SocketExample
|
|
|
|
string setPowerString = "AA 55 14 42 ";//设置命令开头
|
|
|
|
string setPowerString = "AA 55 14 42 ";//设置命令开头
|
|
|
|
int[] powers = new int[8] {int.Parse(Port1ReadText),int.Parse(Port2ReadText), int.Parse(Port3ReadText), int.Parse(Port4ReadText),
|
|
|
|
int[] powers = new int[8] {int.Parse(Port1ReadText),int.Parse(Port2ReadText), int.Parse(Port3ReadText), int.Parse(Port4ReadText),
|
|
|
|
int.Parse(Port1WriteText),int.Parse(Port2WriteText),int.Parse(Port3WriteText),int.Parse(Port4WriteText)};
|
|
|
|
int.Parse(Port1WriteText),int.Parse(Port2WriteText),int.Parse(Port3WriteText),int.Parse(Port4WriteText)};
|
|
|
|
for (int i = 0; i < powers.Length/2; i++) {
|
|
|
|
for (int i = 0; i < powers.Length / 2; i++)
|
|
|
|
setPowerString += $"0{i+1} {(powers[i]*100).ToString("X").PadLeft(4,'0').Insert(2," ")} {(powers[i+4] * 100).ToString("X").PadLeft(4, '0').Insert(2, " ")} ";
|
|
|
|
{
|
|
|
|
|
|
|
|
setPowerString += $"0{i + 1} {(powers[i] * 100).ToString("X").PadLeft(4, '0').Insert(2, " ")} {(powers[i + 4] * 100).ToString("X").PadLeft(4, '0').Insert(2, " ")} ";
|
|
|
|
}//功率设置时为两位数,乘100后再转换为16进制字符串,再填满左侧保证4位数,最后两位两位隔开
|
|
|
|
}//功率设置时为两位数,乘100后再转换为16进制字符串,再填满左侧保证4位数,最后两位两位隔开
|
|
|
|
byte[] powerdata = strToToHexByte(setPowerString);
|
|
|
|
byte[] powerdata = strToToHexByte(setPowerString);
|
|
|
|
byte xor = GetXor(powerdata,2);//计算校验位
|
|
|
|
byte xor = GetXor(powerdata, 2);//计算校验位
|
|
|
|
setPowerString += Convert.ToString(xor,16) + " 0D";//校验位需转成16进制字符串,命令结尾
|
|
|
|
setPowerString += Convert.ToString(xor, 16) + " 0D";//校验位需转成16进制字符串,命令结尾
|
|
|
|
byte[] data = strToToHexByte(setPowerString);
|
|
|
|
byte[] data = strToToHexByte(setPowerString);
|
|
|
|
client.Send(data);
|
|
|
|
client.Send(data);
|
|
|
|
Infotext += setPowerString;
|
|
|
|
Infotext += setPowerString;
|
|
|
|
data = strToToHexByte("AA 55 00 72 72 0D");//获取功率
|
|
|
|
data = strToToHexByte("AA 55 00 72 72 0D");//获取功率
|
|
|
|
client.Send(data);
|
|
|
|
client.Send(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Infotext += $"处理请求时出错: {e.Message}\n";
|
|
|
|
Infotext += $"处理请求时出错: {e.Message}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -930,7 +936,7 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sender.SelectedItem = null;
|
|
|
|
sender.SelectedItem = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Infotext += ex.Message;
|
|
|
|
Infotext += ex.Message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -966,7 +972,7 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sender.SelectedItem?.ToString() == "高")
|
|
|
|
if (sender.SelectedItem?.ToString() == "高")
|
|
|
|
Order += "01 ";
|
|
|
|
Order += "01 ";
|
|
|
|
else if(sender.SelectedItem?.ToString() == "低")
|
|
|
|
else if (sender.SelectedItem?.ToString() == "低")
|
|
|
|
Order += "00 ";
|
|
|
|
Order += "00 ";
|
|
|
|
Order += "00 00 ";
|
|
|
|
Order += "00 00 ";
|
|
|
|
Order += Convert.ToString(GetXor(strToToHexByte(Order), 2), 16) + " 0D";
|
|
|
|
Order += Convert.ToString(GetXor(strToToHexByte(Order), 2), 16) + " 0D";
|
|
|
|
@ -1022,9 +1028,9 @@ namespace SocketExample
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(client!=null)
|
|
|
|
if (client != null)
|
|
|
|
client.Close();
|
|
|
|
client.Close();
|
|
|
|
if(GPIOthread!=null)
|
|
|
|
if (GPIOthread != null)
|
|
|
|
GPIOthread.Abort();
|
|
|
|
GPIOthread.Abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -1036,11 +1042,11 @@ namespace SocketExample
|
|
|
|
string CheckForOnce()
|
|
|
|
string CheckForOnce()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string actionstring = "AA 55 02 01 ";
|
|
|
|
string actionstring = "AA 55 02 01 ";
|
|
|
|
if(TimeOut!=""&&TimeOut!=null)
|
|
|
|
if (TimeOut != "" && TimeOut != null)
|
|
|
|
actionstring += Convert.ToInt32(TimeOut).ToString("X").PadLeft(4, '0').Insert(2, " ") + " ";
|
|
|
|
actionstring += Convert.ToInt32(TimeOut).ToString("X").PadLeft(4, '0').Insert(2, " ") + " ";
|
|
|
|
else
|
|
|
|
else
|
|
|
|
actionstring +="00 00 ";
|
|
|
|
actionstring += "00 00 ";
|
|
|
|
actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16).PadLeft(2,'0').ToUpper() + " 0D";
|
|
|
|
actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16).PadLeft(2, '0').ToUpper() + " 0D";
|
|
|
|
return actionstring;
|
|
|
|
return actionstring;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string CheckDuringTime()
|
|
|
|
string CheckDuringTime()
|
|
|
|
@ -1121,7 +1127,7 @@ namespace SocketExample
|
|
|
|
public class TagItem : INotifyPropertyChanged
|
|
|
|
public class TagItem : INotifyPropertyChanged
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private string _originmessage;//原始数据
|
|
|
|
private string _originmessage;//原始数据
|
|
|
|
public string OriginMessage { get => _originmessage;set { _originmessage = value;OnPropertyChanged(); } }
|
|
|
|
public string OriginMessage { get => _originmessage; set { _originmessage = value; OnPropertyChanged(); } }
|
|
|
|
|
|
|
|
|
|
|
|
private string _rssiinfo;//RSSI强度
|
|
|
|
private string _rssiinfo;//RSSI强度
|
|
|
|
public string RSSIinfo { get => _rssiinfo; set { _rssiinfo = value; OnPropertyChanged(); } }
|
|
|
|
public string RSSIinfo { get => _rssiinfo; set { _rssiinfo = value; OnPropertyChanged(); } }
|
|
|
|
@ -1134,7 +1140,7 @@ namespace SocketExample
|
|
|
|
public string EPCinfo { get => _epcinfo; set { _epcinfo = value; OnPropertyChanged(); } }
|
|
|
|
public string EPCinfo { get => _epcinfo; set { _epcinfo = value; OnPropertyChanged(); } }
|
|
|
|
public string EPCASC { get => _epcasc; set { _epcasc = value; OnPropertyChanged(); } }
|
|
|
|
public string EPCASC { get => _epcasc; set { _epcasc = value; OnPropertyChanged(); } }
|
|
|
|
|
|
|
|
|
|
|
|
public TagItem(string originMessage,string infoEPC,string ascEPC,string RSSI,string count,string time)
|
|
|
|
public TagItem(string originMessage, string infoEPC, string ascEPC, string RSSI, string count, string time)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OriginMessage = originMessage;
|
|
|
|
OriginMessage = originMessage;
|
|
|
|
EPCinfo = infoEPC;
|
|
|
|
EPCinfo = infoEPC;
|
|
|
|
@ -1152,23 +1158,34 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 主界面参数
|
|
|
|
|
|
|
|
int currentcount = 0;//目前客户端的数量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<PanelItem> items = new List<PanelItem>();//客户端组件列表
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double? WindowLeft { get; set; }
|
|
|
|
|
|
|
|
public static double? WindowTop { get; set; }
|
|
|
|
|
|
|
|
public static double? WindowWidth { get; set; }
|
|
|
|
|
|
|
|
public static double? WindowHeight { get; set; }
|
|
|
|
|
|
|
|
public static WindowState? OriginWindowState { get; set; }
|
|
|
|
|
|
|
|
public static int? Buttonflag { get; set; }
|
|
|
|
public TCPWindowV2()
|
|
|
|
public TCPWindowV2()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
InitializeComponent();
|
|
|
|
EnsureFolderExists("日志文件夹");
|
|
|
|
EnsureFolderExists("日志文件夹");
|
|
|
|
this.Closing += TCPWindowV2_Closing;
|
|
|
|
this.Closing += TCPWindowV2_Closing;
|
|
|
|
|
|
|
|
SaveWindowSettings();
|
|
|
|
|
|
|
|
Buttonflag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
//结束所有线程,防止心跳线程冗余
|
|
|
|
//结束所有线程,防止心跳线程冗余
|
|
|
|
private void TCPWindowV2_Closing(object sender, CancelEventArgs e)
|
|
|
|
private void TCPWindowV2_Closing(object sender, CancelEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.Environment.Exit(0);
|
|
|
|
System.Environment.Exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int currentcount = 0;//目前客户端的数量
|
|
|
|
#region 主界面按钮事件
|
|
|
|
|
|
|
|
|
|
|
|
List<PanelItem> items = new List<PanelItem>();//客户端组件列表
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void GenerateButton_Click(object sender, RoutedEventArgs e)//添加客户端框体
|
|
|
|
private void GenerateButton_Click(object sender, RoutedEventArgs e)//添加客户端框体
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (int.TryParse(CountTextBox.Text, out int count) && count > 0)
|
|
|
|
if (int.TryParse(CountTextBox.Text, out int count) && count > 0)
|
|
|
|
@ -1189,13 +1206,50 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Shutdown_Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Maxmize_Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Buttonflag == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.WindowState = WindowState.Maximized;
|
|
|
|
|
|
|
|
Maxmize_Button.Content = "缩小";
|
|
|
|
|
|
|
|
Buttonflag = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LoadWindowSettings();
|
|
|
|
|
|
|
|
Maxmize_Button.Content = "最大化";
|
|
|
|
|
|
|
|
Buttonflag = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Minimize_Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.WindowState = WindowState.Minimized;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ClearButton_Click(object sender, RoutedEventArgs e)//清空客户端
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (PanelItem item in items)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item.dispose();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
items = new List<PanelItem>();
|
|
|
|
|
|
|
|
PanelContainer.ItemsSource = null;
|
|
|
|
|
|
|
|
currentcount = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
public class LinkCommand : ICommand //command方法实现
|
|
|
|
public class LinkCommand : ICommand //command方法实现
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private Action _excute;
|
|
|
|
private Action _excute;
|
|
|
|
|
|
|
|
|
|
|
|
private Action<int> _excutewithindex;
|
|
|
|
private Action<int> _excutewithindex;
|
|
|
|
|
|
|
|
|
|
|
|
public LinkCommand(Action action) {
|
|
|
|
public LinkCommand(Action action)
|
|
|
|
|
|
|
|
{
|
|
|
|
_excute = action;
|
|
|
|
_excute = action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -1217,17 +1271,6 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearButton_Click(object sender, RoutedEventArgs e)//清空客户端
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (PanelItem item in items)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item.dispose();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
items = new List<PanelItem>();
|
|
|
|
|
|
|
|
PanelContainer.ItemsSource = null;
|
|
|
|
|
|
|
|
currentcount = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<TagInfo> GetTagInfos(byte[] AutoDealReportData)
|
|
|
|
private static List<TagInfo> GetTagInfos(byte[] AutoDealReportData)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<TagInfo> tagInfoList = new List<TagInfo>();
|
|
|
|
List<TagInfo> tagInfoList = new List<TagInfo>();
|
|
|
|
@ -1403,7 +1446,7 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void EnsureTxtExists(string txtPath,string MachineName,string IPinfo,string Portinfo)
|
|
|
|
private static void EnsureTxtExists(string txtPath, string MachineName, string IPinfo, string Portinfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 检查指定的txt路径对应的txt是否已经存在
|
|
|
|
// 检查指定的txt路径对应的txt是否已经存在
|
|
|
|
if (!File.Exists(txtPath))
|
|
|
|
if (!File.Exists(txtPath))
|
|
|
|
@ -1425,5 +1468,39 @@ namespace SocketExample
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (e.ChangedButton == MouseButton.Left)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.DragMove();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void LoadWindowSettings()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (WindowLeft.HasValue && WindowTop.HasValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.Left = WindowLeft.Value;
|
|
|
|
|
|
|
|
this.Top = WindowTop.Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WindowWidth.HasValue && WindowHeight.HasValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.Width = WindowWidth.Value;
|
|
|
|
|
|
|
|
this.Height = WindowHeight.Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OriginWindowState.HasValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.WindowState = OriginWindowState.Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void SaveWindowSettings()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
WindowLeft = this.Left;
|
|
|
|
|
|
|
|
WindowTop = this.Top;
|
|
|
|
|
|
|
|
WindowWidth = this.Width;
|
|
|
|
|
|
|
|
WindowHeight = this.Height;
|
|
|
|
|
|
|
|
OriginWindowState = this.WindowState;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|