1.新增发送下拉框

2.修改GPI默认显示
master
zhangxy 3 weeks ago
parent 93d0a18c79
commit 5d94176a0a

@ -6,7 +6,7 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:SocketExample" xmlns:local="clr-namespace:SocketExample"
mc:Ignorable="d" mc:Ignorable="d"
Title="RFID读写器多终端监控软件v1.02" Height="450" Width="800"> Title="RFID读写器多终端监控软件v1.03" Height="450" Width="800">
<Window.Resources> <Window.Resources>
<Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}"> <Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}">
@ -113,9 +113,19 @@
</Border> </Border>
<StackPanel Orientation="Vertical" Margin="0,5,0,0" Width="130"> <StackPanel Orientation="Vertical" Margin="0,5,0,0" Width="130">
<TextBlock Text="请输入需要发送的内容:"></TextBlock> <TextBlock Text="请输入需要发送的内容:"></TextBlock>
<TextBox TextWrapping="Wrap" x:Name="MessageTextBox_Client" Text="{Binding MessageText}" Height="50" Margin="0,0,0,5"/> <StackPanel Orientation="Horizontal">
<TextBox TextWrapping="Wrap" x:Name="MessageTextBox_Client" Text="{Binding MessageText}" Height="50" Width="110" Margin="0,0,0,5"/>
<ComboBox x:Name="TextComboBox" Width="20" Height="20" ItemsSource="{Binding SendTextComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SendTextChangedCommand}"
CommandParameter="{Binding ElementName=TextComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<Button Content="发送" Width="50" HorizontalAlignment="Center" Command="{Binding _sendcomn}" Style="{StaticResource SocketButton}"/> <Button Content="发送" Width="50" HorizontalAlignment="Center" Command="{Binding _sendcomn}" Style="{StaticResource SocketButton}"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>

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

Loading…
Cancel
Save