1.去掉GPI的心跳获取

master
zhangxy 2 weeks ago
parent 4a546a2de9
commit ccff2c2627

@ -6,7 +6,7 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:SocketExample"
mc:Ignorable="d"
Title="RFID读写器多终端监控软件v1.061" Height="450" Width="800">
Title="RFID读写器多终端监控软件v1.062" Height="450" Width="800">
<Window.Resources>
<Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}">
@ -78,7 +78,7 @@
<Border Width="Auto" Background="LightSkyBlue" >
<TextBox Width="Auto" Foreground="Black" Background="LightSkyBlue" Text="{Binding Text}" FontSize="14"></TextBox>
</Border>
<StackPanel Orientation="Horizontal" Margin="5 5 5 5">
<StackPanel Orientation="Horizontal" Margin="5 1 5 1">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Content="IP地址" Height="30" Margin="10 8 0 0"/>
@ -92,13 +92,13 @@
</StackPanel>
<Ellipse Width="20" Height="20" Fill="{Binding StateColour}" Margin="8 8 0 0"/>
<Label Height="30" Content="{Binding LinkState}" Margin="2 8 0 0"></Label>
<Button Content="连接" Height="30" Margin="10 8 0 0" Command="{Binding _linkcomn}" Style="{StaticResource SocketButton}"/>
<Button Content="清空" Height="30" Margin="10 8 0 0" Command="{Binding _clearcomn}" Style="{StaticResource SocketButton}"/>
<Button Content="断开" Height="30" Margin="10 8 10 0" Command="{Binding _disconnectcomn}" Style="{StaticResource SocketButton}"/>
<Button Content="{Binding LinkButtonText}" Height="30" Width="45" Margin="10 8 0 0" Command="{Binding _linkcomn}" Style="{StaticResource SocketButton}"/>
<Button Content="清空" Height="30" Width="45" Margin="10 8 0 0" Command="{Binding _clearcomn}" Style="{StaticResource SocketButton}"/>
<!--<Button Content="断开" Height="30" Margin="10 8 10 0" Command="{Binding _disconnectcomn}" Style="{StaticResource SocketButton}"/>-->
</StackPanel>
<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,2,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">
<i:Interaction.Triggers>
@ -113,10 +113,10 @@
</ScrollViewer>
</Border>
<StackPanel Orientation="Vertical" Margin="0,5,0,0" Width="130">
<StackPanel Orientation="Vertical" Margin="0,2,0,0">
<TextBlock Text="请输入需要发送的内容:"></TextBlock>
<TextBox TextWrapping="Wrap" x:Name="MessageTextBox_Client" Text="{Binding MessageText}" Height="50" Width="130" Margin="0,0,0,5"/>
<Button Content="发送" Width="40" Command="{Binding _sendcomn}" Style="{StaticResource SocketButton}"/>
<TextBox TextWrapping="Wrap" x:Name="MessageTextBox_Client" Text="{Binding MessageText}" Height="50" Width="140" Margin="0,0,0,1"/>
<Button Content="发送" Width="40" Height="22" Command="{Binding _sendcomn}" Style="{StaticResource SocketButton}"/>
</StackPanel>
</StackPanel>
<Border BorderBrush="Black" BorderThickness="0.5">

@ -71,6 +71,9 @@ namespace SocketExample
private string _linkstate;//链接状态文本
public string LinkState { get => _linkstate; set { _linkstate = value; OnPropertyChanged(); } }
public string LinkButtonText { get => _linkbuttontext; set { _linkbuttontext = value; OnPropertyChanged(); } }
private string _linkbuttontext { get; set; }
private string _infotext;//信息框
public string Infotext { get => _infotext; set
{
@ -207,6 +210,7 @@ namespace SocketExample
MessageText = string.Empty;
IPtext = "192.168.0.7";//默认IP
Porttext = "20108";//默认端口
LinkButtonText = "连接";
StateColour = "Red";
LinkState = "未连接";
RSSIinfo = "##";
@ -356,6 +360,7 @@ 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');
bool GPIchange = false;
string GPI1string = "";
string GPI2string = "";
string GPI3string = "";
@ -378,6 +383,7 @@ namespace SocketExample
{
GPI4 = "低";
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
GPIchange = true;
}
}
else
@ -385,6 +391,7 @@ namespace SocketExample
{
GPI4 = "高";
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
GPIchange = true;
}
break;
@ -399,14 +406,16 @@ namespace SocketExample
if (GPI3 != "低")
{
GPI3 = "低";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPIchange = true;
}
}
else
if (GPI3 != "高")
{
GPI3 = "高";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPIchange = true;
}
break;
@ -421,14 +430,16 @@ namespace SocketExample
if (GPI2 != "低")
{
GPI2 = "低";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPIchange = true;
}
}
else
if (GPI2 != "高")
{
GPI2 = "高";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPIchange = true;
}
break;
case 7:
@ -442,14 +453,16 @@ namespace SocketExample
if (GPI1 != "低")
{
GPI1 = "低";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPIchange = true;
}
}
else
if (GPI1 != "高")
{
GPI1 = "高";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPIchange = true;
}
break;
default:
@ -457,12 +470,16 @@ namespace SocketExample
}
}
if(GPIchange == true)
{
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 ______________________________");
GPIchange = false;
}
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":
@ -684,6 +701,8 @@ namespace SocketExample
#region 动态界面控件功能
async void Button_Link()//链接按钮的事件
{
if(LinkButtonText == "连接")
{
try
{
@ -695,7 +714,7 @@ namespace SocketExample
//连接事件
client.Connected += onConnected;
//断连事件
client.Closed = (client, e) => { GPIOthread.Abort(); Infotext += "已断开!\n"; StateColour = "Red"; LinkState = "未连接"; return EasyTask.CompletedTask; };
client.Closed = (client, e) => { try { GPIOthread.Abort(); Infotext += "已断开!\n"; StateColour = "Red"; LinkState = "未连接"; } catch (Exception ex) { Infotext += ex; } return EasyTask.CompletedTask; };
//接收事件
client.Received += onRecieved;
@ -704,7 +723,7 @@ namespace SocketExample
{
a.AddConsoleLogger();//添加一个日志注入
}));
//开启连接
await client.ConnectAsync();
}
@ -712,6 +731,13 @@ namespace SocketExample
{
Infotext += $"处理请求时出错: {ex.Message}\n";
}
LinkButtonText = "断开";
}
else
{
client.Close();
LinkButtonText = "连接";
}
}
void Button_Read()
@ -772,7 +798,7 @@ namespace SocketExample
}
}
void Button_GetPower()
{
try

Loading…
Cancel
Save