1.修复了功率设置

2.修复了GPO高低电平设置
master
zhangxy 1 month ago
parent b85caa3159
commit d338ed4b48

@ -72,6 +72,9 @@
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.135\lib\net462\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=9.3.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.9.3.0\lib\net48\MySql.Data.dll</HintPath>
</Reference>

@ -3,9 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:SocketExample"
mc:Ignorable="d"
Title="RFID读写器多终端监控软件v1.01" Height="450" Width="800">
Title="RFID读写器多终端监控软件v1.02" Height="450" Width="800">
<Window.Resources>
<Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}">
@ -173,49 +174,107 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Content="功率状态" FontSize="14" FontWeight="Bold" FontStyle="Oblique" HorizontalAlignment="Center" Grid.Row="0"/>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Label Content="读功率:" FontSize="14"/>
<Label Content="{Binding ReadPowerState}" FontSize="14"></Label>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<Label Content="写功率:" FontSize="14"/>
<Label Content="{Binding WritePowerState}" FontSize="14"></Label>
</StackPanel>
</Grid>
</Border>
<Border BorderBrush="Black" BorderThickness="0.5" Grid.Row="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="0 1 0 1" Grid.Row="0">
<Label Content="读功率:" FontSize="14"/>
<Label Content="端口1:" FontSize="14"/>
<TextBox Text="{Binding Port1ReadText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<Label Content="端口2:" FontSize="14"/>
<TextBox Text="{Binding Port2ReadText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<Label Content="端口3:" FontSize="14"/>
<TextBox Text="{Binding Port3ReadText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<Label Content="端口4:" FontSize="14"/>
<TextBox Text="{Binding Port4ReadText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 1 0 1" Grid.Row="1">
<Label Content="写功率:" FontSize="14"/>
<Label Content="端口1:" FontSize="14"/>
<TextBox Text="{Binding Port1WriteText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<Label Content="端口2:" FontSize="14"/>
<TextBox Text="{Binding Port2WriteText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<Label Content="端口3:" FontSize="14"/>
<TextBox Text="{Binding Port3WriteText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<Label Content="端口4:" FontSize="14"/>
<TextBox Text="{Binding Port4WriteText}" Width="25" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<Label Content="读:" FontSize="14"/>
<Label Content="端①:" FontSize="14"/>
<TextBox Text="{Binding Port1ReadText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port1ReadComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port1ReadComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Label Content="端②:" FontSize="14"/>
<TextBox Text="{Binding Port2ReadText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port2ReadComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port2ReadComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Label Content="端③:" FontSize="14"/>
<TextBox Text="{Binding Port3ReadText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port3ReadComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port3ReadComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Label Content="端④:" FontSize="14"/>
<TextBox Text="{Binding Port4ReadText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port4ReadComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port4ReadComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 1 0 3" Grid.Row="2">
<StackPanel Orientation="Horizontal" Margin="0 1 0 1" Grid.Row="2">
<Label Content="写:" FontSize="14"/>
<Label Content="端①:" FontSize="14"/>
<TextBox Text="{Binding Port1WriteText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port1WriteComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port1WriteComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Label Content="端②:" FontSize="14"/>
<TextBox Text="{Binding Port2WriteText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port2WriteComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port2WriteComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Label Content="端③:" FontSize="14"/>
<TextBox Text="{Binding Port3WriteText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port3WriteComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port3WriteComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Label Content="端④:" FontSize="14"/>
<TextBox Text="{Binding Port4WriteText}" Width="20" Height="20" VerticalAlignment="Center" HorizontalContentAlignment="Center"/>
<ComboBox x:Name="Port4WriteComboBox" Width="20" Height="20" ItemsSource="{Binding PortComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding SelectionChangedCommand}"
CommandParameter="{Binding ElementName=Port4WriteComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 1 0 3" Grid.Row="3">
<Button Content="设置功率" Command="{Binding _setpowercomn}" Width="50" Height="25" Margin="100 0 0 0" Style="{StaticResource SocketButton}" />
<Button Content="获取功率" Command="{Binding _getpowercomn}" Width="50" Height="25" Margin="60 0 0 0" Style="{StaticResource SocketButton}" />
</StackPanel>
@ -247,24 +306,60 @@
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPO1}"></Label>
</Border>
<ComboBox x:Name="GPO1ComboBox" Width="20" Height="20" ItemsSource="{Binding GPOComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding GPOSelectionChangedCommand}"
CommandParameter="{Binding ElementName=GPO1ComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Label Content="GPO2" HorizontalAlignment="Left"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPO2}"></Label>
</Border>
<ComboBox x:Name="GPO2ComboBox" Width="20" Height="20" ItemsSource="{Binding GPOComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding GPOSelectionChangedCommand}"
CommandParameter="{Binding ElementName=GPO2ComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Label Content="GPO3" HorizontalAlignment="Left"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPO3}"></Label>
</Border>
<ComboBox x:Name="GPO3ComboBox" Width="20" Height="20" ItemsSource="{Binding GPOComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding GPOSelectionChangedCommand}"
CommandParameter="{Binding ElementName=GPO3ComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Horizontal">
<Label Content="GPO4" HorizontalAlignment="Left"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPO4}"></Label>
</Border>
<ComboBox x:Name="GPO4ComboBox" Width="20" Height="20" ItemsSource="{Binding GPOComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
Command="{Binding GPOSelectionChangedCommand}"
CommandParameter="{Binding ElementName=GPO4ComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
</Grid>
<Grid Grid.Row="1" Margin="0 0 0 5">

@ -1,4 +1,5 @@
using System;
using System.Buffers.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
@ -10,17 +11,23 @@ using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Markup;
using System.Xml;
using GalaSoft.MvvmLight.Command;
using K4os.Compression.LZ4.Streams.Abstractions;
using Mesnac.Log;
using Microsoft.Xaml.Behaviors.Core;
using Org.BouncyCastle.Utilities.Encoders;
using TouchSocket.Core;
using TouchSocket.Sockets;
using ZstdSharp.Unsafe;
namespace SocketExample
{
@ -32,10 +39,15 @@ namespace SocketExample
public class PanelItem : INotifyPropertyChanged //实现组件更改的接口
{
#region 变量定义
IPAddress ip;
int port;
TcpClient client;
public string option;//命令选项
public ICommand SelectionChangedCommand { get; }
public ICommand GPOSelectionChangedCommand { get; }
private ObservableCollection<TagItem> _tagItems;
public ObservableCollection<TagItem> TagItems { get => _tagItems; set { _tagItems = value; OnPropertyChanged(); } }
public string Text { get; set; }//客户端编号
@ -80,6 +92,9 @@ namespace SocketExample
private string _port3writetext;
private string _port4writetext;//设置读功率1-4
private int[] _portComboBox;
private string[] _gpoComboBox;
public string Port1ReadText { get => _port1readtext; set { _port1readtext = value; OnPropertyChanged(); } }
public string Port2ReadText { get => _port2readtext; set { _port2readtext = value; OnPropertyChanged(); } }
public string Port3ReadText { get => _port3readtext; set { _port3readtext = value; OnPropertyChanged(); } }
@ -89,6 +104,9 @@ namespace SocketExample
public string Port2WriteText { get => _port2writetext; set { _port2writetext = value; OnPropertyChanged(); } }
public string Port3WriteText { get => _port3writetext; set { _port3writetext = value; OnPropertyChanged(); } }
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(); } }
private string _gpo1;
private string _gpo2;
@ -134,6 +152,10 @@ namespace SocketExample
public LinkCommand getpowercomn;//获取功率
public LinkCommand powerselectchanged;
#endregion
public PanelItem(int index)
{
Text = $"客户端{index + 1}";
@ -144,6 +166,9 @@ namespace SocketExample
clearcomn = new LinkCommand(Button_clear);//绑定清空按钮的事件
setpowercomn = new LinkCommand(Button_SetPower);
getpowercomn = new LinkCommand(Button_GetPower);
SelectionChangedCommand = new RelayCommand<ComboBox>(ComboBox_SelectChanged);
GPOSelectionChangedCommand = new RelayCommand<ComboBox>(GPOComboBox_SelectChanged);
try
{
@ -157,6 +182,9 @@ 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 = {"高","低"};
MessageText = string.Empty;
IPtext = "192.168.0.7";//默认IP
Porttext = "20108";//默认端口
@ -166,6 +194,8 @@ namespace SocketExample
Countinfo = "00";
EPCASC = "###";
EPCinfo = "###";
PortComboBox = Powerdatasource;
GPOComboBox = GPOdatasource;
GPO1 = "低";
GPO2 = "低";
GPO3 = "低";
@ -175,6 +205,8 @@ namespace SocketExample
GPI3 = "低";
GPI4 = "低";
}
#region 界面功能绑定定义
public LinkCommand _powerselectchanged { get { return powerselectchanged; } }
public LinkCommand _linkcomn { get { return linkcomn; } }
@ -187,7 +219,9 @@ namespace SocketExample
public LinkCommand _clearcomn { get { return clearcomn; } }
public LinkCommand _setpowercomn { get { return setpowercomn; } }
public LinkCommand _getpowercomn { get { return getpowercomn; } }
#endregion
#region socket事件
private Task onSend(ITcpClient client, ReceivedDataEventArgs e)
{
@ -199,18 +233,19 @@ namespace SocketExample
private Task onRecieved(ITcpClient client, ReceivedDataEventArgs e) //接收事件
{
string time = DateTime.Now.ToString();
string currentTime = time.Substring(10, time.Length-10);
string currentTime = time.Substring(9, time.Length-9);
var mes = e.ByteBlock.Span.ToString(Encoding.UTF8);
byte[] data = e.ByteBlock.Span.ToArray();
string hexString = BitConverter.ToString(data).Replace("-", " ");
Infotext += $"({currentTime})客户端接收到信息:\n{hexString}\n\n";
//读取状态
string readStateString = hexString.Replace(" ", "");//去掉字符串中空格
string dataLength = readStateString.Substring(4, 2);//获取字符串中内容长度
string commandState = readStateString.Substring(6, 2);//获取命令
if(commandState != "81")
Infotext += $"({currentTime})客户端接收到信息:\n{hexString}\n\n";
int i = Convert.ToInt32(dataLength, 16);
if (i != 0)
{
@ -318,17 +353,31 @@ namespace SocketExample
//获取功率信息
try
{
string tempReadstate = "";
string tempWritestate = "";
for (int n = 0;n < (Convert.ToInt32(dataLength,16)/5);n++)
{
tempReadstate += $"端口{n+1}{(Convert.ToInt32(readStateString.Substring(12+10*n,4),16)/100).ToString()} ";
tempWritestate += $"端口{n + 1}{(Convert.ToInt32(readStateString.Substring(16 + 10 * n, 4), 16) / 100).ToString()} ";
switch (n)
{
case 0:
Port1ReadText = $"{(Convert.ToInt32(readStateString.Substring(12 + 10 * n, 4), 16) / 100).ToString()}";
Port1WriteText = $"{(Convert.ToInt32(readStateString.Substring(16 + 10 * n, 4), 16) / 100).ToString()}";
break;
case 1:
Port2ReadText = $"{(Convert.ToInt32(readStateString.Substring(12 + 10 * n, 4), 16) / 100).ToString()}";
Port2WriteText = $"{(Convert.ToInt32(readStateString.Substring(16 + 10 * n, 4), 16) / 100).ToString()}";
break;
case 2:
Port3ReadText = $"{(Convert.ToInt32(readStateString.Substring(12 + 10 * n, 4), 16) / 100).ToString()}";
Port3WriteText = $"{(Convert.ToInt32(readStateString.Substring(16 + 10 * n, 4), 16) / 100).ToString()}";
break;
case 3:
Port4ReadText = $"{(Convert.ToInt32(readStateString.Substring(12 + 10 * n, 4), 16) / 100).ToString()}";
Port4WriteText = $"{(Convert.ToInt32(readStateString.Substring(16 + 10 * n, 4), 16) / 100).ToString()}";
break;
default:
break;
}
}
ReadPowerState = tempReadstate;
WritePowerState = tempWritestate;
tempReadstate = "";
tempWritestate = "";
}
catch
{
@ -409,21 +458,45 @@ namespace SocketExample
Thread.Sleep(500);
data = strToToHexByte("AA 55 00 81 81 0D");//获取GPIO状态
data = strToToHexByte("AA 55 00 72 72 0D");//获取功率状态
client.Send(data);
Thread.Sleep(500);
data = strToToHexByte("AA 55 00 72 72 0D");//获取功率状态
data = strToToHexByte("AA 55 00 81 81 0D");//获取GPIO状态
client.Send(data);
Thread.Sleep(500);
data = strToToHexByte("AA 55 02 02 03 E8 EB 0D");//获取1000ms内标签信息
client.Send(data);
Thread.Sleep(1000);
Thread GPIOthread = new Thread(new ThreadStart(delegate () { byte[] data = strToToHexByte("AA 55 00 81 81 0D"); client.Send(data); Thread.Sleep(3000); }));
//GPIOthread.Start();
return EasyTask.CompletedTask;
}
#endregion
#region 辅助功能
static void GetGPIOThread(ITcpClient client)
{
byte[] data = strToToHexByte("AA 55 00 81 81 0D");//获取GPIO状态
client.Send(data);
}
public byte GetXor(byte[] data,int m)
{
byte CheckCode = 0;
int len = data.Length;
for (int i = m; i < len; i++)
{
CheckCode ^= data[i];
}
return CheckCode;
}
private static byte[] HextoByte(string Temp)
{
byte[] Tempbytes = new byte[Temp.Length / 2];//16进制转byte数组
@ -459,6 +532,9 @@ namespace SocketExample
streamWriter.Close();
}
#endregion
#region 动态界面控件功能
async void Button_Link()//链接按钮的事件
{
try
@ -502,30 +578,23 @@ namespace SocketExample
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("数值不可为空!");
return;
}
string setPowerString = "AA 55 14 42 ";//设置命令开头
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[] 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)};
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, " ")} ";
}//功率设置时为两位数乘100后再转换为16进制字符串再填满左侧保证4位数最后两位两位隔开
setPowerString += "52 0D";//命令结尾
byte[] powerdata = strToToHexByte(setPowerString);
byte xor = GetXor(powerdata,2);//计算校验位
setPowerString += Convert.ToString(xor,16) + " 0D";//校验位需转成16进制字符串命令结尾
byte[] data = strToToHexByte(setPowerString);
client.Send(data);
byte[] confirmdata1 = strToToHexByte("AA 55 05 5F ");//保存命令
byte[] confirmdata2 = System.Text.Encoding.UTF8.GetBytes("\"SAVE\" ");
byte[] confirmdata3 = strToToHexByte("01 5A 0D");
byte[] confirmdata = new byte[confirmdata1.Length+ confirmdata2.Length+ confirmdata3.Length];
confirmdata1.CopyTo(confirmdata,0);
confirmdata2.CopyTo(confirmdata,confirmdata1.Length);
confirmdata3.CopyTo(confirmdata,confirmdata1.Length+ confirmdata2.Length);//保存命令拼接
client.Send(confirmdata);
Infotext += setPowerString;
data = strToToHexByte("AA 55 00 72 72 0D");//获取功率
client.Send(data);
}
@ -538,8 +607,16 @@ namespace SocketExample
void Button_GetPower()
{
byte[] data = strToToHexByte("AA 55 00 72 72 0D");//获取功率
client.Send(data);
try
{
byte[] data = strToToHexByte("AA 55 00 72 72 0D");//获取功率
client.Send(data);
}
catch (Exception ex)
{
Infotext += ex.Message;
}
}
void Button_Click_Send()//发送按钮的事件
@ -572,7 +649,108 @@ namespace SocketExample
void Button_clear()
{
Infotext = string.Empty;//清空信息框
}
}
void ComboBox_SelectChanged(ComboBox sender)
{
string comboxname = sender.Name;
try
{
switch (comboxname)
{
case "Port1ReadComboBox":
Port1ReadText = sender.SelectedItem?.ToString();
break;
case "Port2ReadComboBox":
Port2ReadText = sender.SelectedItem?.ToString();
break;
case "Port3ReadComboBox":
Port3ReadText = sender.SelectedItem?.ToString();
break;
case "Port4ReadComboBox":
Port4ReadText = sender.SelectedItem?.ToString();
break;
case "Port1WriteComboBox":
Port1WriteText = sender.SelectedItem?.ToString();
break;
case "Port2WriteComboBox":
Port2WriteText = sender.SelectedItem?.ToString();
break;
case "Port3WriteComboBox":
Port3WriteText = sender.SelectedItem?.ToString();
break;
case "Port4WriteComboBox":
Port4WriteText = sender.SelectedItem?.ToString();
break;
}
}
catch(Exception ex)
{
Infotext += ex.Message;
}
}
void GPOComboBox_SelectChanged(ComboBox sender)
{
string Order = "AA 55 04 51 ";
string comboxname = sender.Name;
try
{
switch (comboxname)
{
case "GPO1ComboBox":
GPO1 = sender.SelectedItem?.ToString();
Order += "01 ";
break;
case "GPO2ComboBox":
GPO2 = sender.SelectedItem?.ToString();
Order += "02 ";
break;
case "GPO3ComboBox":
GPO3 = sender.SelectedItem?.ToString();
Order += "03 ";
break;
case "GPO4ComboBox":
GPO4 = sender.SelectedItem?.ToString();
Order += "04 ";
break;
}
if (sender.SelectedItem?.ToString() == "高")
Order += "01 ";
else
Order += "00 ";
Order += "00 00 ";
Order += Convert.ToString(GetXor(strToToHexByte(Order), 2), 16) + " 0D";
//Infotext += Order+"\n";
byte[] data = strToToHexByte(Order);
client.Send(data);
data = strToToHexByte("AA 55 00 81 81 0D");//获取GPIO状态
client.Send(data);
//SaveCommand();
}
catch (Exception ex)
{
Infotext += ex.Message;
}
}
void SaveCommand()
{
byte[] confirmdata1 = strToToHexByte("AA 55 05 5F ");//保存命令
byte[] confirmdata2 = System.Text.Encoding.UTF8.GetBytes("\"SAVE\" ");
byte[] confirmdata3 = strToToHexByte("01 5A 0D");
byte[] confirmdata = new byte[confirmdata1.Length + confirmdata2.Length + confirmdata3.Length];
confirmdata1.CopyTo(confirmdata, 0);
confirmdata2.CopyTo(confirmdata, confirmdata1.Length);
confirmdata3.CopyTo(confirmdata, confirmdata1.Length + confirmdata2.Length);//保存命令拼接
client.Send(confirmdata);
}
#endregion
//组件属性更改事件
public event PropertyChangedEventHandler PropertyChanged;
@ -851,5 +1029,6 @@ namespace SocketExample
}
}
}
}
}

@ -7,6 +7,7 @@
<package id="K4os.Compression.LZ4.Streams" version="1.3.8" targetFramework="net48" />
<package id="K4os.Hash.xxHash" version="1.0.8" targetFramework="net48" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net48" />
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.135" targetFramework="net48" />
<package id="MvvmLightLibs" version="5.4.1.1" targetFramework="net48" />
<package id="MySql.Data" version="9.3.0" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />

Loading…
Cancel
Save