|
|
|
@ -46,6 +46,7 @@ namespace SocketExample
|
|
|
|
|
public string option;//命令选项
|
|
|
|
|
public ICommand TextChangedCommand { get; }
|
|
|
|
|
public ICommand SelectionChangedCommand { get; }
|
|
|
|
|
public ICommand SendTextChangedCommand { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand GPOSelectionChangedCommand { get; }
|
|
|
|
|
|
|
|
|
@ -54,7 +55,8 @@ namespace SocketExample
|
|
|
|
|
public string Text { get; set; }//客户端编号
|
|
|
|
|
public string IPtext { get; set; }//IP文本框
|
|
|
|
|
public string Porttext { get; set; }//端口文本框
|
|
|
|
|
public string MessageText { get; set; }//发送框
|
|
|
|
|
private string _messagetext;
|
|
|
|
|
public string MessageText { get => _messagetext; set { _messagetext = value; OnPropertyChanged(); } }//发送框
|
|
|
|
|
private string _statecolour { get; set; }//状态指示灯
|
|
|
|
|
public string StateColour { get => _statecolour; set { _statecolour = value; OnPropertyChanged(); } }
|
|
|
|
|
|
|
|
|
@ -95,6 +97,7 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
private int[] _portComboBox;
|
|
|
|
|
private string[] _gpoComboBox;
|
|
|
|
|
private string[] _sendtextComboBox;//下拉框数据源
|
|
|
|
|
|
|
|
|
|
public string Port1ReadText { get => _port1readtext; set { _port1readtext = value; OnPropertyChanged(); } }
|
|
|
|
|
public string Port2ReadText { get => _port2readtext; set { _port2readtext = value; OnPropertyChanged(); } }
|
|
|
|
@ -107,6 +110,7 @@ namespace SocketExample
|
|
|
|
|
public string Port4WriteText { get => _port4writetext; set { _port4writetext = value; OnPropertyChanged(); } }
|
|
|
|
|
public int[] PortComboBox { get => _portComboBox; set { _portComboBox = value; OnPropertyChanged(); } }
|
|
|
|
|
public string[] GPOComboBox { get => _gpoComboBox;set { _gpoComboBox = value; OnPropertyChanged(); } }
|
|
|
|
|
public string[] SendTextComboBox { get => _sendtextComboBox; set { _sendtextComboBox = value; OnPropertyChanged(); } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string _gpo1;
|
|
|
|
@ -171,10 +175,13 @@ namespace SocketExample
|
|
|
|
|
getpowercomn = new LinkCommand(Button_GetPower);
|
|
|
|
|
SelectionChangedCommand = new RelayCommand<ComboBox>(ComboBox_SelectChanged);
|
|
|
|
|
GPOSelectionChangedCommand = new RelayCommand<ComboBox>(GPOComboBox_SelectChanged);
|
|
|
|
|
SendTextChangedCommand = new RelayCommand<ComboBox>(SendTextComboBox_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};
|
|
|
|
|
string[] GPOdatasource = {"高","低"};
|
|
|
|
|
string[] SendTextdatasource = { "读取"};
|
|
|
|
|
|
|
|
|
|
MessageText = string.Empty;
|
|
|
|
|
IPtext = "192.168.0.7";//默认IP
|
|
|
|
@ -187,6 +194,7 @@ namespace SocketExample
|
|
|
|
|
EPCinfo = "###";
|
|
|
|
|
PortComboBox = Powerdatasource;
|
|
|
|
|
GPOComboBox = GPOdatasource;
|
|
|
|
|
SendTextComboBox = SendTextdatasource;
|
|
|
|
|
GPO1 = "低";
|
|
|
|
|
GPO2 = "低";
|
|
|
|
|
GPO3 = "低";
|
|
|
|
@ -297,9 +305,9 @@ namespace SocketExample
|
|
|
|
|
GPO4 = "低";
|
|
|
|
|
|
|
|
|
|
if (GPIBinInfo.Substring(j, 1) == "1")
|
|
|
|
|
GPI4 = "高";
|
|
|
|
|
else
|
|
|
|
|
GPI4 = "低";
|
|
|
|
|
else
|
|
|
|
|
GPI4 = "高";
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
if (GPOBinInfo.Substring(j, 1) == "1")
|
|
|
|
@ -308,9 +316,9 @@ namespace SocketExample
|
|
|
|
|
GPO3 = "低";
|
|
|
|
|
|
|
|
|
|
if (GPIBinInfo.Substring(j, 1) == "1")
|
|
|
|
|
GPI3 = "高";
|
|
|
|
|
else
|
|
|
|
|
GPI3 = "低";
|
|
|
|
|
else
|
|
|
|
|
GPI3 = "高";
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
if (GPOBinInfo.Substring(j, 1) == "1")
|
|
|
|
@ -319,9 +327,9 @@ namespace SocketExample
|
|
|
|
|
GPO2 = "低";
|
|
|
|
|
|
|
|
|
|
if (GPIBinInfo.Substring(j, 1) == "1")
|
|
|
|
|
GPI2 = "高";
|
|
|
|
|
else
|
|
|
|
|
GPI2 = "低";
|
|
|
|
|
else
|
|
|
|
|
GPI2 = "高";
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
if (GPOBinInfo.Substring(j, 1) == "1")
|
|
|
|
@ -330,9 +338,9 @@ namespace SocketExample
|
|
|
|
|
GPO1 = "低";
|
|
|
|
|
|
|
|
|
|
if (GPIBinInfo.Substring(j, 1) == "1")
|
|
|
|
|
GPI1 = "高";
|
|
|
|
|
else
|
|
|
|
|
GPI1 = "低";
|
|
|
|
|
else
|
|
|
|
|
GPI1 = "高";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
@ -566,10 +574,17 @@ namespace SocketExample
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Button_Read()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
byte[] data = strToToHexByte("AA 55 02 02 03 E8 EB 0D");//获取1000ms内标签信息
|
|
|
|
|
client.Send(data);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
Infotext += $"发送读取命令时出错: {ex.Message}\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Button_SetPower()
|
|
|
|
|
{
|
|
|
|
@ -632,6 +647,7 @@ namespace SocketExample
|
|
|
|
|
client.Send(data);//发送原始数据
|
|
|
|
|
client.Send(strToToHexByte(message));//发送16进制数据
|
|
|
|
|
}
|
|
|
|
|
MessageText = "";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -743,6 +759,25 @@ namespace SocketExample
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SendTextComboBox_SelectChanged(ComboBox sender)
|
|
|
|
|
{
|
|
|
|
|
string selcetion = sender.SelectedItem?.ToString();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (selcetion)
|
|
|
|
|
{
|
|
|
|
|
case "读取":
|
|
|
|
|
MessageText = "AA 55 02 02 03 E8 EB 0D";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Infotext += ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void SaveCommand()
|
|
|
|
|
{
|
|
|
|
|
byte[] confirmdata1 = strToToHexByte("AA 55 05 5F ");//保存命令
|
|
|
|
@ -802,6 +837,7 @@ namespace SocketExample
|
|
|
|
|
this.Closing += TCPWindowV2_Closing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//结束所有线程,防止心跳线程冗余
|
|
|
|
|
private void TCPWindowV2_Closing(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
System.Environment.Exit(0);
|
|
|
|
|