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:local="clr-namespace:SocketExample"
mc:Ignorable="d"
Title="RFID读写器多终端监控软件v1.051" Height="450" Width="800">
Title="RFID读写器多终端监控软件v1.061" Height="450" Width="800">
<Window.Resources>
<Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}">
@ -73,12 +73,12 @@
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" BorderBrush="Black" Margin="1">
<StackPanel Orientation="Vertical" Margin="5 5 5 5" Width="360" >
<Border BorderThickness="1" BorderBrush="Black" Margin="1" Width="{Binding Borderwidth}" >
<StackPanel Orientation="Vertical" Margin="5 5 5 5" >
<Border Width="Auto" Background="LightSkyBlue" >
<TextBox Width="Auto" Foreground="Black" Background="LightSkyBlue" Text="{Binding Text}" FontSize="14"></TextBox>
</Border>
<StackPanel Orientation="Horizontal" Width="360">
<StackPanel Orientation="Horizontal" Margin="5 5 5 5">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<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}"/>
</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" >
<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">
@ -405,11 +405,13 @@
<Label Content="GPI1" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI1}" >
<!-- 标签修改事件
<i:Interaction.Triggers>
<i:EventTrigger EventName="">
</i:EventTrigger>
</i:Interaction.Triggers>
-->
</Label>
</Border>
</StackPanel>

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

Loading…
Cancel
Save