1.清空按钮结束端口连接和进程

2.GPI修改加入日志
master
zhangxy 2 weeks ago
parent 77a5559f8d
commit 4a546a2de9

@ -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.051" Height="450" Width="800"> Title="RFID读写器多终端监控软件v1.061" 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}">
@ -73,12 +73,12 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderThickness="1" BorderBrush="Black" Margin="1"> <Border BorderThickness="1" BorderBrush="Black" Margin="1" Width="{Binding Borderwidth}" >
<StackPanel Orientation="Vertical" Margin="5 5 5 5" Width="360" > <StackPanel Orientation="Vertical" Margin="5 5 5 5" >
<Border Width="Auto" Background="LightSkyBlue" > <Border Width="Auto" Background="LightSkyBlue" >
<TextBox Width="Auto" Foreground="Black" Background="LightSkyBlue" Text="{Binding Text}" FontSize="14"></TextBox> <TextBox Width="Auto" Foreground="Black" Background="LightSkyBlue" Text="{Binding Text}" FontSize="14"></TextBox>
</Border> </Border>
<StackPanel Orientation="Horizontal" Width="360"> <StackPanel Orientation="Horizontal" Margin="5 5 5 5">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Label Content="IP地址" Height="30" Margin="10 8 0 0"/> <Label Content="IP地址" Height="30" Margin="10 8 0 0"/>
@ -97,7 +97,7 @@
<Button Content="断开" Height="30" Margin="10 8 10 0" Command="{Binding _disconnectcomn}" Style="{StaticResource SocketButton}"/> <Button Content="断开" Height="30" Margin="10 8 10 0" Command="{Binding _disconnectcomn}" Style="{StaticResource SocketButton}"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Width="370" Margin="0,1,0,5" Height="100"> <StackPanel Orientation="Horizontal" Margin="0,1,0,5" Height="100">
<Border Height="Auto" Width="200" BorderBrush="Black" BorderThickness="1" Margin="5,5,10,0" > <Border Height="Auto" Width="200" BorderBrush="Black" BorderThickness="1" Margin="5,5,10,0" >
<ScrollViewer x:Name="TextScrollViewer" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> <ScrollViewer x:Name="TextScrollViewer" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<TextBox x:Name="InfoTextBlock_Client" TextWrapping="Wrap" BorderThickness="0" IsReadOnly="True" Text="{Binding Infotext}" Height="Auto" Width="Auto"> <TextBox x:Name="InfoTextBlock_Client" TextWrapping="Wrap" BorderThickness="0" IsReadOnly="True" Text="{Binding Infotext}" Height="Auto" Width="Auto">
@ -405,11 +405,13 @@
<Label Content="GPI1" HorizontalAlignment="Left" Margin="0 0 6 0"/> <Label Content="GPI1" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5"> <Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI1}" > <Label Content="{Binding GPI1}" >
<!-- 标签修改事件
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName=""> <i:EventTrigger EventName="">
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
-->
</Label> </Label>
</Border> </Border>
</StackPanel> </StackPanel>

@ -20,6 +20,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Markup; using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Xml; using System.Xml;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
@ -60,6 +61,9 @@ namespace SocketExample
public string IPtext { get; set; }//IP文本框 public string IPtext { get; set; }//IP文本框
public string Porttext { get; set; }//端口文本框 public string Porttext { get; set; }//端口文本框
private string _messagetext; private string _messagetext;
public int Borderwidth { get => _borderwidth; set { _borderwidth = value; OnPropertyChanged(); } }
private int _borderwidth { get; set; }
public string MessageText { get => _messagetext; set { _messagetext = value; OnPropertyChanged(); } }//发送框 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(); } }
@ -137,10 +141,10 @@ namespace SocketExample
public string GPO3 { get => _gpo3; set { _gpo3 = value; OnPropertyChanged(); } } public string GPO3 { get => _gpo3; set { _gpo3 = value; OnPropertyChanged(); } }
public string GPO4 { get => _gpo4; set { _gpo4 = value; OnPropertyChanged(); } } public string GPO4 { get => _gpo4; set { _gpo4 = value; OnPropertyChanged(); } }
public string GPI1 { get => _gpi1; set { if (_gpi1 != value && _gpi1 != null) { _gpi1 = value; LabelPropertyChanged(); } else { _gpi1 = value; OnPropertyChanged(); } } } public string GPI1 { get => _gpi1; set { if (_gpi1 != value && _gpi1 != null) { _gpi1 = value; OnPropertyChanged(); } else { _gpi1 = value; OnPropertyChanged(); } } }
public string GPI2 { get => _gpi2; set { if (_gpi2 != value && _gpi1 != null) { _gpi2 = value; LabelPropertyChanged(); } else { _gpi2 = value; OnPropertyChanged(); } } } public string GPI2 { get => _gpi2; set { if (_gpi2 != value && _gpi1 != null) { _gpi2 = value; OnPropertyChanged(); } else { _gpi2 = value; OnPropertyChanged(); } } }
public string GPI3 { get => _gpi3; set { if (_gpi3 != value && _gpi1 != null) { _gpi3 = value; LabelPropertyChanged(); } else { _gpi3 = value; OnPropertyChanged(); } } } public string GPI3 { get => _gpi3; set { if (_gpi3 != value && _gpi1 != null) { _gpi3 = value; OnPropertyChanged(); } else { _gpi3 = value; OnPropertyChanged(); } } }
public string GPI4 { get => _gpi4; set { if (_gpi4 != value && _gpi1 != null) { _gpi4 = value; LabelPropertyChanged(); } else { _gpi4 = value; OnPropertyChanged(); } } } public string GPI4 { get => _gpi4; set { if (_gpi4 != value && _gpi1 != null) { _gpi4 = value; OnPropertyChanged(); } else { _gpi4 = value; OnPropertyChanged(); } } }
private string _moduleinfo; private string _moduleinfo;
private string _motherboardhardware; private string _motherboardhardware;
@ -199,6 +203,7 @@ namespace SocketExample
string[] GPOdatasource = {"高","低"}; string[] GPOdatasource = {"高","低"};
string[] SendTextdatasource = { "单次读取","时间段盘点"}; string[] SendTextdatasource = { "单次读取","时间段盘点"};
Borderwidth = ((int)SystemParameters.PrimaryScreenWidth-25)/4;
MessageText = string.Empty; MessageText = string.Empty;
IPtext = "192.168.0.7";//默认IP IPtext = "192.168.0.7";//默认IP
Porttext = "20108";//默认端口 Porttext = "20108";//默认端口
@ -351,7 +356,11 @@ namespace SocketExample
//获取GPIO状态16进制转二进制 //获取GPIO状态16进制转二进制
string GPIBinInfo = Convert.ToString(Convert.ToInt32(readStateString.Substring(12, 2), 16), 2).PadLeft(8, '0'); string GPIBinInfo = Convert.ToString(Convert.ToInt32(readStateString.Substring(12, 2), 16), 2).PadLeft(8, '0');
string GPOBinInfo = Convert.ToString(Convert.ToInt32(readStateString.Substring(10, 2), 16), 2).PadLeft(8, '0'); string GPOBinInfo = Convert.ToString(Convert.ToInt32(readStateString.Substring(10, 2), 16), 2).PadLeft(8, '0');
string GPI1string = "";
string GPI2string = "";
string GPI3string = "";
string GPI4string = "";
string GPIyear = DateTime.Now.ToString("yyyy-MM-dd");
for (int j = 4; j < GPOBinInfo.Length; j++) for (int j = 4; j < GPOBinInfo.Length; j++)
{ {
//按位判断GPIO状态 //按位判断GPIO状态
@ -364,9 +373,20 @@ namespace SocketExample
GPO4 = "低"; GPO4 = "低";
if (GPIBinInfo.Substring(j, 1) == "1") if (GPIBinInfo.Substring(j, 1) == "1")
GPI4 = "低"; {
if(GPI4 != "低")
{
GPI4 = "低";
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
}
}
else else
GPI4 = "高"; if(GPI4 != "高")
{
GPI4 = "高";
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
}
break; break;
case 5: case 5:
if (GPOBinInfo.Substring(j, 1) == "1") if (GPOBinInfo.Substring(j, 1) == "1")
@ -375,9 +395,20 @@ namespace SocketExample
GPO3 = "低"; GPO3 = "低";
if (GPIBinInfo.Substring(j, 1) == "1") if (GPIBinInfo.Substring(j, 1) == "1")
GPI3 = "低"; {
if (GPI3 != "低")
{
GPI3 = "低";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
}
}
else else
GPI3 = "高"; if (GPI3 != "高")
{
GPI3 = "高";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
}
break; break;
case 6: case 6:
if (GPOBinInfo.Substring(j, 1) == "1") if (GPOBinInfo.Substring(j, 1) == "1")
@ -386,9 +417,19 @@ namespace SocketExample
GPO2 = "低"; GPO2 = "低";
if (GPIBinInfo.Substring(j, 1) == "1") if (GPIBinInfo.Substring(j, 1) == "1")
GPI2 = "低"; {
if (GPI2 != "低")
{
GPI2 = "低";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
}
}
else else
GPI2 = "高"; if (GPI2 != "高")
{
GPI2 = "高";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
}
break; break;
case 7: case 7:
if (GPOBinInfo.Substring(j, 1) == "1") if (GPOBinInfo.Substring(j, 1) == "1")
@ -397,14 +438,31 @@ namespace SocketExample
GPO1 = "低"; GPO1 = "低";
if (GPIBinInfo.Substring(j, 1) == "1") if (GPIBinInfo.Substring(j, 1) == "1")
GPI1 = "低"; {
if (GPI1 != "低")
{
GPI1 = "低";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
}
}
else else
GPI1 = "高"; if (GPI1 != "高")
{
GPI1 = "高";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
}
break; break;
default: default:
break; break;
} }
} }
EnsureFolderExists($"日志文件夹/{GPIyear}/{Text}");
string temppath = $"日志文件夹/{GPIyear}/{Text}/" + Text + "GPI" + "(" + IPtext + ")" + ".txt";
EnsureTxtExists(temppath, Text, IPtext, Porttext);
string currenttime = DateTime.Now.ToString();
writeToTxt(temppath, $"{GPI1string}{GPI2string}{GPI3string}{GPI4string}\n当前状态GPI1:{GPI1} GPI2:{GPI2} GPI3:{GPI3} GPI4:{GPI4}\n当前时间{currenttime}\n ______________________________");
break; break;
case "72": case "72":
@ -556,6 +614,20 @@ namespace SocketExample
#endregion #endregion
#region 辅助功能 #region 辅助功能
private string GPIChangeLog(string gpiInfo)
{
if(gpiInfo == "低")
{
return "高 => 低";
}
else if (gpiInfo == "高")
{
return "低 => 高";
}
throw new NotImplementedException();
}
static void GetGPIOThread(ITcpClient client) static void GetGPIOThread(ITcpClient client)
{ {
byte[] data = strToToHexByte("AA 55 00 81 81 0D");//获取GPIO状态 byte[] data = strToToHexByte("AA 55 00 81 81 0D");//获取GPIO状态
@ -920,6 +992,21 @@ namespace SocketExample
} }
public void dispose()
{
try
{
if(client!=null)
client.Close();
if(GPIOthread!=null)
GPIOthread.Abort();
}
catch (Exception ex)
{
}
}
string CheckForOnce() string CheckForOnce()
{ {
string actionstring = "AA 55 02 01 "; string actionstring = "AA 55 02 01 ";
@ -962,6 +1049,7 @@ namespace SocketExample
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
/*
protected void LabelPropertyChanged([CallerMemberName] string propertyName = null) protected void LabelPropertyChanged([CallerMemberName] string propertyName = null)
{ {
if(GPI1 == "" || GPI2 == ""|| GPI3 == ""|| GPI4 == "" || GPI1 ==null || GPI2 == null || GPI3 == null || GPI4 == null ||client == null) if(GPI1 == "" || GPI2 == ""|| GPI3 == ""|| GPI4 == "" || GPI1 ==null || GPI2 == null || GPI3 == null || GPI4 == null ||client == null)
@ -973,6 +1061,7 @@ namespace SocketExample
EnsureFolderExists($"日志文件夹/{year}/{Text}"); EnsureFolderExists($"日志文件夹/{year}/{Text}");
string temppath = $"日志文件夹/{year}/{Text}/" + Text + "GPI"+"(" + IPtext + ")" + ".txt"; string temppath = $"日志文件夹/{year}/{Text}/" + Text + "GPI"+"(" + IPtext + ")" + ".txt";
EnsureTxtExists(temppath, Text, IPtext, Porttext); EnsureTxtExists(temppath, Text, IPtext, Porttext);
string currenttime = DateTime.Now.ToString();
string GPIname = ""; string GPIname = "";
string front = ""; string front = "";
string back = ""; string back = "";
@ -1000,9 +1089,9 @@ namespace SocketExample
front = "低"; front = "低";
else else
front = "高"; front = "高";
writeToTxt(temppath,$"{GPIname}:{front} => {back}\n当前状态GPI1:{GPI1} GPI2:{GPI2} GPI3:{GPI3} GPI4:{GPI4}\n当前时间{year}\n ______________________________"); writeToTxt(temppath,$"{GPIname}:{front} => {back}\n当前状态GPI1:{GPI1} GPI2:{GPI2} GPI3:{GPI3} GPI4:{GPI4}\n当前时间{currenttime}\n ______________________________");
} }
*/
public class TagItem : INotifyPropertyChanged public class TagItem : INotifyPropertyChanged
{ {
private string _originmessage;//原始数据 private string _originmessage;//原始数据
@ -1104,7 +1193,11 @@ namespace SocketExample
private void ClearButton_Click(object sender, RoutedEventArgs e)//清空客户端 private void ClearButton_Click(object sender, RoutedEventArgs e)//清空客户端
{ {
items.Clear(); foreach (PanelItem item in items)
{
item.dispose();
}
items = new List<PanelItem>();
PanelContainer.ItemsSource = null; PanelContainer.ItemsSource = null;
currentcount = 0; currentcount = 0;
} }

Loading…
Cancel
Save