1.升级UI

2.修复日志
3.自适应
master
zhangxy 8 months ago
parent ccff2c2627
commit 2f23e79852

@ -27,9 +27,67 @@
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 颜色定义 -->
<Color x:Key="PrimaryColor">#FF4285F4</Color>
<Color x:Key="DarkPrimaryColor">#FF3367D6</Color>
<Color x:Key="AccentColor">#FF34A853</Color>
<Color x:Key="WarningColor">#FFEA4335</Color>
<Color x:Key="LightGray">#FFEEEEEE</Color>
<Color x:Key="DarkGray">#FF757575</Color>
<!-- 笔刷定义 -->
<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource PrimaryColor}"/>
<SolidColorBrush x:Key="DarkPrimaryBrush" Color="{StaticResource DarkPrimaryColor}"/>
<SolidColorBrush x:Key="AccentBrush" Color="{StaticResource AccentColor}"/>
<SolidColorBrush x:Key="WarningBrush" Color="{StaticResource WarningColor}"/>
<SolidColorBrush x:Key="LightGrayBrush" Color="{StaticResource LightGray}"/>
<SolidColorBrush x:Key="DarkGrayBrush" Color="{StaticResource DarkGray}"/>
<!-- 终端样式 -->
<Style x:Key="TerminalStyle" TargetType="Border">
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="8"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Margin" Value="4"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="12"
ShadowDepth="0"
Color="#20000000"/>
</Setter.Value>
</Setter>
</Style>
<!-- 扁平化按钮样式 -->
<Style x:Key="FlatButton" TargetType="Button">
<Setter Property="Background" Value="{StaticResource PrimaryBrush}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="12 8"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="FontSize" Value="15"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}"
CornerRadius="4">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource DarkPrimaryBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
</Application>

@ -259,6 +259,9 @@
<ItemGroup>
<Resource Include="Pictogrammers-Material-Monitor-eye.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="海威图标-横.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets" Condition="Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

@ -4,9 +4,12 @@
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:controls="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:local="clr-namespace:SocketExample"
mc:Ignorable="d"
Title="RFID读写器多终端监控软件v1.062" Height="450" Width="800">
Title="RFID读写器多终端监控软件v1.07" Height="450" Width="800"
Background="Transparent" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}">
@ -51,148 +54,193 @@
</Style>
</Window.Resources>
<Border>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="10" Height="30">
<TextBlock Text="监控终端生成数量:" VerticalAlignment="Center" Margin="0,0,10,0"/>
<TextBox x:Name="CountTextBox" Width="100" Margin="0,0,10,0" VerticalAlignment="Center"/>
<Button Content="生成" Click="GenerateButton_Click" Width="50" Margin="10 0 0 0" Style="{StaticResource SocketButton}"/>
<Button Content="清空" Click="ClearButton_Click" Width="50" Margin="10 0 0 0" Style="{StaticResource SocketButton}"/>
</StackPanel>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<Border CornerRadius="30" BorderThickness="2" BorderBrush="#ebedf3" Padding="10" MouseDown="Border_MouseDown" Background="#FFCFD5E5">
<Border CornerRadius="30">
<Border.Background>
<LinearGradientBrush>
<GradientStop Color="#fefefe" Offset="0"/>
<GradientStop Color="#ededef" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Border CornerRadius="30">
<Border.Background>
<DrawingBrush Opacity="0.2" TileMode="Tile" Viewport="0,0,300,80" ViewportUnits="Absolute">
<DrawingBrush.Transform>
<RotateTransform Angle="-45" CenterX="0" CenterY="0"/>
</DrawingBrush.Transform>
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="Transparent">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,110,75"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<ImageDrawing ImageSource="/海威图标-横.png" Rect="5,5,100,60"/>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="90"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" CornerRadius="20" Background="{StaticResource PrimaryBrush}" Margin="10" Cursor="">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="10 0 0 0" VerticalAlignment="Center">
<TextBlock Text="监控终端生成数量:" VerticalAlignment="Center" Margin="0,0,10,0" Foreground="White" FontSize="15" FontWeight="SemiBold"/>
<TextBox x:Name="CountTextBox" Width="100" Margin="0,0,10,0" VerticalAlignment="Center" FontSize="15" FontWeight="SemiBold"/>
<Button Content="生成" Click="GenerateButton_Click" Height="40" Width="50" Margin="10 0 0 0" Style="{StaticResource FlatButton}"/>
<Button Content="清空" Click="ClearButton_Click" Height="40" Width="50" Margin="10 0 0 0" Style="{StaticResource FlatButton}"/>
</StackPanel>
<Grid Grid.Column="1" HorizontalAlignment="Right" Margin="0 0 10 0" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button x:Name="Minimize_Button" Grid.Column="0" Content="最小化" Height="40" Width="50" Style="{StaticResource FlatButton}" Margin="0 0 16 0" Click="Minimize_Button_Click"/>
<Button x:Name="Maxmize_Button" Grid.Column="1" Content="最大化" Height="40" Width="50" Style="{StaticResource FlatButton}" Margin="0 0 0 0" Click="Maxmize_Button_Click"/>
<Button x:Name="Shutdown_Button" Grid.Column="2" Content="关闭" Height="40" Width="50" Style="{StaticResource FlatButton}" Click="Shutdown_Button_Click"/>
</Grid>
</Grid>
</Border>
<ItemsControl x:Name="PanelContainer">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"></WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<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" Margin="5 1 5 1">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Content="IP地址" Height="30" Margin="10 8 0 0"/>
<TextBox TextWrapping="Wrap" x:Name="IPtextbox" Text="{Binding IPtext}" Width="100" Height="20" Margin="5 8 0 0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="端口号" Height="30" Margin="10 8 0 0"/>
<TextBox TextWrapping="Wrap" Text="{Binding Porttext}" x:Name="Porttextbox" Width="45" Height="20" Margin="5 8 0 0"/>
<!-- <Button Content="读取" Height="20" Width="40" Margin="10 8 0 0" Command="{Binding _readcomn}" Style="{StaticResource SocketButton}"/>-->
</StackPanel>
</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="{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>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<StackPanel Orientation="Horizontal" Margin="0,1,0,5" Height="100">
<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>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction
<ItemsControl x:Name="PanelContainer">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"></WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Style="{StaticResource TerminalStyle}" Width="{Binding Borderwidth}">
<StackPanel Orientation="Vertical" Margin="5 5 5 5" >
<Border Width="Auto" Background="LightSkyBlue" CornerRadius="6" Padding="3">
<TextBox Width="Auto" Foreground="Black" Background="LightSkyBlue" Text="{Binding Text}" BorderThickness="0" FontSize="15" FontWeight="SemiBold"></TextBox>
</Border>
<StackPanel Orientation="Horizontal" Margin="5 1 5 1">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Content="IP地址" Height="30" Margin="10 8 0 0" FontWeight="SemiBold"/>
<TextBox TextWrapping="Wrap" x:Name="IPtextbox" Text="{Binding IPtext}" Width="100" Height="20" Margin="5 8 0 0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="端口号" Height="30" Margin="10 8 0 0" FontWeight="SemiBold"/>
<TextBox TextWrapping="Wrap" Text="{Binding Porttext}" x:Name="Porttextbox" Width="45" Height="20" Margin="5 8 0 0"/>
<!-- <Button Content="读取" Height="20" Width="40" Margin="10 8 0 0" Command="{Binding _readcomn}" Style="{StaticResource SocketButton}"/>-->
</StackPanel>
</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="{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,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>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction
Command="{Binding TextChangedCommand}"
CommandParameter="{Binding ElementName=TextScrollViewer}"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
</ScrollViewer>
</Border>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
</ScrollViewer>
</Border>
<StackPanel Orientation="Vertical" Margin="0,2,0,0">
<TextBlock Text="请输入需要发送的内容:"></TextBlock>
<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">
<ScrollViewer VerticalScrollBarVisibility="Visible" Margin="0.5 0.1 0.5 0.1" Height="150">
<ItemsControl ItemsSource="{Binding TagItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"></WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Margin="0.5 0 0.5 0">
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Label Content="接收消息:"/>
<TextBlock Text="{Binding OriginMessage}" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Label Content="标签:"/>
<TextBlock Text="{Binding EPCinfo}" FontSize="15" FontWeight="Bold" Foreground="Green" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Label Content="HEX:"/>
<TextBlock Text="{Binding EPCASC}" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="RSSI:"/>
<TextBlock Text="{Binding RSSIinfo}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Label Margin="5 0 0 0" Content="Count:"/>
<TextBlock Text="{Binding Countinfo}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Label Margin="5 0 0 0" Content="Time:"/>
<TextBlock Text="{Binding Timeinfo}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Grid>
</ScrollViewer>
<StackPanel Orientation="Vertical" Margin="0,2,0,0">
<TextBlock Text="请输入需要发送的内容:" FontWeight="SemiBold"></TextBlock>
<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">
<ScrollViewer VerticalScrollBarVisibility="Visible" Margin="0.5 0.1 0.5 0.1" Height="150">
<ItemsControl ItemsSource="{Binding TagItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"></WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0.5" CornerRadius="10" BorderBrush="Black" Padding="2.5 3 2.5 3" Margin="0.5 1 0.5 1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
<Grid Margin="0.5">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Label Content="接收消息:"/>
<TextBlock Text="{Binding OriginMessage}" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Label Content="标签:"/>
<TextBlock Text="{Binding EPCinfo}" FontSize="15" FontWeight="Bold" Foreground="Green" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Label Content="HEX:"/>
<TextBlock Text="{Binding EPCASC}" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="RSSI:"/>
<TextBlock Text="{Binding RSSIinfo}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Label Margin="5 0 0 0" Content="Count:"/>
<TextBlock Text="{Binding Countinfo}" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Label Margin="5 0 0 0" Content="Time:"/>
<TextBlock Text="{Binding Timeinfo}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Grid>
</ScrollViewer>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Border>
<!--触发动作部分-->
<Border BorderBrush="Black" BorderThickness="0.5">
<StackPanel Orientation="Horizontal" Margin="1 2 1 2">
<Label Content="触发动作:" FontWeight="Bold" FontSize="13"/>
<TextBox Text="{Binding ActionType}" Width="70" TextAlignment="Center" FontSize="13"/>
<ComboBox x:Name="TextComboBox" Width="20" Height="20" ItemsSource="{Binding SendTextComboBox,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction
<!--触发动作部分-->
<Border BorderBrush="Black" BorderThickness="0.5">
<StackPanel Orientation="Horizontal" Margin="1 2 1 2">
<Label Content="触发动作:" FontWeight="Bold" FontSize="13"/>
<TextBox Text="{Binding ActionType}" Width="70" TextAlignment="Center" VerticalContentAlignment="Center" FontSize="13"/>
<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>
<Label Content="时间段:" FontWeight="Bold" FontSize="13"/>
<TextBox Text="{Binding TimeOut}" Width="50" TextAlignment="Center" FontSize="13"/>
<Button Content="发送" Width="50" Margin="15 2 0 2" Command="{Binding _sendactioncomn}" Style="{StaticResource SocketButton}"/>
</StackPanel>
</Border>
<!-- 功率部分,已备份,注释后不再生成该部分
CommandParameter="{Binding ElementName=TextComboBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Label Content="时间段:" FontWeight="Bold" FontSize="13"/>
<TextBox Text="{Binding TimeOut}" Width="50" TextAlignment="Center" VerticalContentAlignment="Center" FontSize="13"/>
<Button Content="发送" Width="50" Margin="15 2 0 2" Command="{Binding _sendactioncomn}" Style="{StaticResource SocketButton}"/>
</StackPanel>
</Border>
<!-- 功率部分,已备份,注释后不再生成该部分
<Border BorderBrush="Black" BorderThickness="0.5">
<Grid Margin="0 0 0 0">
<Grid.RowDefinitions>
@ -318,154 +366,157 @@
</Border>
-->
<Border BorderBrush="Black" BorderThickness="0.5">
<Grid Margin="0 0 0 2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" HorizontalAlignment="Center" Content="GPIO状态" FontSize="14" FontWeight="Bold" FontStyle="Oblique"></Label>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="GPO1" HorizontalAlignment="Left"/>
<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
<!--gpio部分-->
<Border BorderBrush="Black" BorderThickness="0.5">
<Grid Margin="0 0 0 2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" HorizontalAlignment="Center" Content="GPIO状态" FontSize="14" FontWeight="Bold" FontStyle="Oblique"></Label>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="GPO1" HorizontalAlignment="Left"/>
<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
</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
</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
</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">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="GPI1" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI1}" >
<!-- 标签修改事件
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</StackPanel>
</Grid>
<Grid Grid.Row="1" Margin="0 0 0 5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<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>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Label Content="GPI2" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI2}"></Label>
</Border>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Label Content="GPI3" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI3}"></Label>
</Border>
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Horizontal">
<Label Content="GPI4" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI4}"></Label>
</Border>
</StackPanel>
</Grid>
</Grid>
</Border>
<Border BorderBrush="Black" BorderThickness="0.5">
<Grid Margin="0 0 0 2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="版本信息" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" FontStyle="Oblique"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="模块型号:" HorizontalAlignment="Left" FontSize="14" />
<Label Grid.Column="1" Content="{Binding moduleInfo}"></Label>
<Label Grid.Column="2" Content="主板固件号:" HorizontalAlignment="Left" FontSize="14" />
<Label Grid.Column="3" Content="{Binding motherboardFirmware}"></Label>
</Grid>
</Label>
</Border>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Label Content="GPI2" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI2}"></Label>
</Border>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<Label Content="GPI3" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI3}"></Label>
</Border>
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Horizontal">
<Label Content="GPI4" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI4}"></Label>
</Border>
</StackPanel>
</Grid>
</Grid>
</Border>
<Border BorderBrush="Black" BorderThickness="0.5">
<Grid Margin="0 0 0 2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="版本信息" HorizontalAlignment="Center" FontSize="14" FontWeight="Bold" FontStyle="Oblique"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="模块型号:" HorizontalAlignment="Left" FontSize="14" />
<Label Grid.Column="1" Content="{Binding moduleInfo}"></Label>
<Label Grid.Column="2" Content="主板固件号:" HorizontalAlignment="Left" FontSize="14" />
<Label Grid.Column="3" Content="{Binding motherboardFirmware}"></Label>
</Grid>
</Grid>
</Grid>
</Border>
</StackPanel>
</Border>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</Border>
</Border>
</Border>
</Window>

@ -75,7 +75,9 @@ namespace SocketExample
private string _linkbuttontext { get; set; }
private string _infotext;//信息框
public string Infotext { get => _infotext; set
public string Infotext
{
get => _infotext; set
{
_infotext = value;
OnPropertyChanged(); // 通知 UI 更新
@ -126,7 +128,7 @@ namespace SocketExample
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(); } }
public string[] GPOComboBox { get => _gpoComboBox; set { _gpoComboBox = value; OnPropertyChanged(); } }
public string[] SendTextComboBox { get => _sendtextComboBox; set { _sendtextComboBox = value; OnPropertyChanged(); } }
@ -191,7 +193,7 @@ namespace SocketExample
readcomn = new LinkCommand(Button_Read);
stopreadingcomn = new LinkCommand(Button_StopReading);
sendcomn = new LinkCommand(Button_Click_Send);//绑定发送按钮的事件
sendactioncomn = new LinkCommand (Button_SendActionComn);
sendactioncomn = new LinkCommand(Button_SendActionComn);
disconnectcomn = new LinkCommand(Button_disconnect);//绑定断连按钮的事件
clearcomn = new LinkCommand(Button_clear);//绑定清空按钮的事件
setpowercomn = new LinkCommand(Button_SetPower);
@ -200,13 +202,13 @@ namespace SocketExample
GPOSelectionChangedCommand = new RelayCommand<ComboBox>(GPOComboBox_SelectChanged);
SendTextChangedCommand = new RelayCommand<ComboBox>(SendTextComboBox_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};
string[] GPOdatasource = {"高","低"};
string[] SendTextdatasource = { "单次读取","时间段盘点"};
Borderwidth = ((int)SystemParameters.PrimaryScreenWidth-25)/4;
//页面初始化
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[] SendTextdatasource = { "单次读取", "时间段盘点" };
Borderwidth = ((int)SystemParameters.PrimaryScreenWidth - 60) / 4; //动态生成界面宽度
MessageText = string.Empty;
IPtext = "192.168.0.7";//默认IP
Porttext = "20108";//默认端口
@ -256,12 +258,13 @@ namespace SocketExample
return EasyTask.CompletedTask;
}
private Task onRecieved(ITcpClient client, ReceivedDataEventArgs e) //接收事件
{
Text = Text.Replace(" ", "");
path = "";
string time = DateTime.Now.ToString();
string currentTime = time.Substring(9, time.Length-9);
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("-", " ");
@ -271,8 +274,8 @@ namespace SocketExample
string dataLength = readStateString.Substring(4, 2);//获取字符串中内容长度
string commandState = readStateString.Substring(6, 2);//获取命令
if(commandState != "81")
Infotext += $"({currentTime})客户端接收到信息:\n{hexString}\n\n";
if (commandState != "81")
Infotext += $"({currentTime})客户端接收到信息:\n{hexString}\n\n";
int i = Convert.ToInt32(dataLength, 16);
if (i != 0)
@ -299,12 +302,12 @@ namespace SocketExample
{
int TempLength = taglist[j].EPCstring.Length * 3 - 1;
EPCinfo = NewDataString.Substring(startTemp, TempLength);
items.Add(new TagItem(hexString,taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
items.Add(new TagItem(hexString, taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
startTemp += 16 + TempLength;
string year = DateTime.Now.ToString("yyyy-MM-dd");
EnsureFolderExists($"日志文件夹/{year}/{Text}");
path = $"日志文件夹/{year}/{Text}/" + Text +"("+ IPtext+")"+ ".txt";
EnsureTxtExists(path,Text, IPtext, Porttext);
path = $"日志文件夹/{year}/{Text}/" + Text + "(" + IPtext + ")" + ".txt";
EnsureTxtExists(path, Text, IPtext, Porttext);
writeToTxt(path, $"接收消息:{hexString}\nEPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________");
path = "";
@ -333,9 +336,9 @@ namespace SocketExample
ObservableCollection<TagItem> items = new ObservableCollection<TagItem>();
for (int j = 0; j < taglist.Count; j++)
{
int TempLength = taglist[j].EPCstring.Length * 3 -1;
int TempLength = taglist[j].EPCstring.Length * 3 - 1;
EPCinfo = hexString.Substring(startTemp, TempLength);
items.Add(new TagItem(hexString,taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
items.Add(new TagItem(hexString, taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
startTemp += 16 + TempLength;
string year = DateTime.Now.ToString("yyyy-MM-dd");
EnsureFolderExists($"日志文件夹/{year}/{Text}");
@ -343,14 +346,15 @@ namespace SocketExample
EnsureTxtExists(path, Text, IPtext, Porttext);
writeToTxt(path, $"接收消息:{hexString}\nEPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________");
path = "";
//LogService.Instance.Debug("");
}
TagItems = items;
}
catch (Exception ex) {
catch (Exception ex)
{
Infotext += ex;
}
@ -378,8 +382,8 @@ namespace SocketExample
GPO4 = "低";
if (GPIBinInfo.Substring(j, 1) == "1")
{
if(GPI4 != "低")
{
if (GPI4 != "低")
{
GPI4 = "低";
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
@ -387,13 +391,13 @@ namespace SocketExample
}
}
else
if(GPI4 != "高")
{
GPI4 = "高";
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
GPIchange = true;
}
if (GPI4 != "高")
{
GPI4 = "高";
GPI4string = "GPI4:" + GPIChangeLog(GPI4);
GPIchange = true;
}
break;
case 5:
if (GPOBinInfo.Substring(j, 1) == "1")
@ -406,17 +410,17 @@ namespace SocketExample
if (GPI3 != "低")
{
GPI3 = "低";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPIchange = true;
}
}
else
if (GPI3 != "高")
{
GPI3 = "高";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPIchange = true;
}
{
GPI3 = "高";
GPI3string = "GPI3:" + GPIChangeLog(GPI3) + " ";
GPIchange = true;
}
break;
case 6:
@ -430,17 +434,17 @@ namespace SocketExample
if (GPI2 != "低")
{
GPI2 = "低";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPIchange = true;
}
}
else
if (GPI2 != "高")
{
GPI2 = "高";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPIchange = true;
}
{
GPI2 = "高";
GPI2string = "GPI2:" + GPIChangeLog(GPI2) + " ";
GPIchange = true;
}
break;
case 7:
if (GPOBinInfo.Substring(j, 1) == "1")
@ -453,24 +457,24 @@ namespace SocketExample
if (GPI1 != "低")
{
GPI1 = "低";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPIchange = true;
}
}
else
if (GPI1 != "高")
{
GPI1 = "高";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPIchange = true;
}
{
GPI1 = "高";
GPI1string = "GPI1:" + GPIChangeLog(GPI1) + " ";
GPIchange = true;
}
break;
default:
break;
}
}
if(GPIchange == true)
if (GPIchange == true)
{
EnsureFolderExists($"日志文件夹/{GPIyear}/{Text}");
string temppath = $"日志文件夹/{GPIyear}/{Text}/" + Text + "GPI" + "(" + IPtext + ")" + ".txt";
@ -479,14 +483,14 @@ namespace SocketExample
writeToTxt(temppath, $"{GPI1string}{GPI2string}{GPI3string}{GPI4string}\n当前状态GPI1:{GPI1} GPI2:{GPI2} GPI3:{GPI3} GPI4:{GPI4}\n当前时间{currenttime}\n ______________________________");
GPIchange = false;
}
break;
case "72":
//获取功率信息
try
{
for (int n = 0;n < (Convert.ToInt32(dataLength,16)/5);n++)
for (int n = 0; n < (Convert.ToInt32(dataLength, 16) / 5); n++)
{
switch (n)
{
@ -561,7 +565,7 @@ namespace SocketExample
EPCinfo = "No Read";
Timeinfo = $" {time}";//获取时间
ObservableCollection<TagItem> items = new ObservableCollection<TagItem>();
items.Add(new TagItem(hexString,EPCASC, EPCinfo, RSSIinfo, Countinfo, Timeinfo));
items.Add(new TagItem(hexString, EPCASC, EPCinfo, RSSIinfo, Countinfo, Timeinfo));
TagItems = items;
string year = DateTime.Now.ToString("yyyy-MM-dd");
EnsureFolderExists($"日志文件夹/{year}/{Text}");
@ -572,7 +576,7 @@ namespace SocketExample
break;
}
}
return EasyTask.CompletedTask;
}
@ -618,14 +622,14 @@ namespace SocketExample
Thread.Sleep(1000);
GPIOthread = new Thread(new ThreadStart(delegate () { while (true) { byte[] data = strToToHexByte("AA 55 00 81 81 0D"); client.Send(data); Thread.Sleep(3000); } }));
GPIOthread = new Thread(new ThreadStart(delegate () { while (true) { byte[] data = strToToHexByte("AA 55 00 81 81 0D"); client.Send(data); Thread.Sleep(1000); } }));
GPIOthread.Start();//心跳获取GPIO状态
}
catch (Exception ex)
{
Infotext += $"连接时报错,错误内容:{ex}\n";
}
return EasyTask.CompletedTask;
}
#endregion
@ -634,7 +638,7 @@ namespace SocketExample
private string GPIChangeLog(string gpiInfo)
{
if(gpiInfo == "低")
if (gpiInfo == "低")
{
return "高 => 低";
}
@ -651,7 +655,7 @@ namespace SocketExample
client.Send(data);
}
public byte GetXor(byte[] data,int m)
public byte GetXor(byte[] data, int m)
{
byte CheckCode = 0;
int len = data.Length;
@ -672,7 +676,7 @@ namespace SocketExample
}
catch (Exception excp)
{
}
}
return Tempbytes;
@ -689,9 +693,9 @@ namespace SocketExample
return returnBytes;
}
private static void writeToTxt(string path,string content)
private static void writeToTxt(string path, string content)
{
StreamWriter streamWriter = new StreamWriter(path,true);
StreamWriter streamWriter = new StreamWriter(path, true);
streamWriter.WriteLineAsync(content);
streamWriter.Close();
}
@ -701,36 +705,36 @@ namespace SocketExample
#region 动态界面控件功能
async void Button_Link()//链接按钮的事件
{
if(LinkButtonText == "连接")
{
try
if (LinkButtonText == "连接")
{
ip = IPAddress.Parse(IPtext);
port = int.Parse(Porttext);
Infotext += $"{Text}";
client = new TcpClient();
//连接事件
client.Connected += onConnected;
//断连事件
client.Closed = (client, e) => { try { GPIOthread.Abort(); Infotext += "已断开!\n"; StateColour = "Red"; LinkState = "未连接"; } catch (Exception ex) { Infotext += ex; } return EasyTask.CompletedTask; };
//接收事件
client.Received += onRecieved;
//设置连接属性
await client.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{IPtext}:{Porttext}").ConfigureContainer(a =>
try
{
a.AddConsoleLogger();//添加一个日志注入
}));
//开启连接
await client.ConnectAsync();
}
catch (Exception ex)
{
Infotext += $"处理请求时出错: {ex.Message}\n";
}
ip = IPAddress.Parse(IPtext);
port = int.Parse(Porttext);
Infotext += $"{Text}";
client = new TcpClient();
//连接事件
client.Connected += onConnected;
//断连事件
client.Closed = (client, e) => { try { GPIOthread.Abort(); Infotext += "已断开!\n"; StateColour = "Red"; LinkState = "未连接"; } catch (Exception ex) { Infotext += ex; } return EasyTask.CompletedTask; };
//接收事件
client.Received += onRecieved;
//设置连接属性
await client.SetupAsync(new TouchSocketConfig().SetRemoteIPHost($"{IPtext}:{Porttext}").ConfigureContainer(a =>
{
a.AddConsoleLogger();//添加一个日志注入
}));
//开启连接
await client.ConnectAsync();
}
catch (Exception ex)
{
Infotext += $"处理请求时出错: {ex.Message}\n";
}
LinkButtonText = "断开";
}
else
@ -747,10 +751,11 @@ namespace SocketExample
byte[] data = strToToHexByte("AA 55 02 02 07 D0 D7 0D");//获取2000ms内标签信息
client.Send(data);
}
catch (Exception ex) {
catch (Exception ex)
{
Infotext += $"发送读取命令时出错: {ex.Message}\n";
}
}
void Button_StopReading()
@ -772,7 +777,7 @@ 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;
@ -780,25 +785,26 @@ namespace SocketExample
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)};
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, " ")} ";
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位数最后两位两位隔开
byte[] powerdata = strToToHexByte(setPowerString);
byte xor = GetXor(powerdata,2);//计算校验位
setPowerString += Convert.ToString(xor,16) + " 0D";//校验位需转成16进制字符串命令结尾
byte xor = GetXor(powerdata, 2);//计算校验位
setPowerString += Convert.ToString(xor, 16) + " 0D";//校验位需转成16进制字符串命令结尾
byte[] data = strToToHexByte(setPowerString);
client.Send(data);
Infotext += setPowerString;
data = strToToHexByte("AA 55 00 72 72 0D");//获取功率
client.Send(data);
}
catch(Exception e)
catch (Exception e)
{
Infotext += $"处理请求时出错: {e.Message}\n";
}
}
void Button_GetPower()
{
try
@ -810,7 +816,7 @@ namespace SocketExample
{
Infotext += ex.Message;
}
}
void Button_Click_Send()//发送按钮的事件
@ -832,10 +838,10 @@ namespace SocketExample
}
catch (Exception ex)
{
Infotext += $"处理请求时出错: {ex.Message}\n";
Infotext += $"处理请求时出错: {ex.Message}\n";
}
}
void Button_SendActionComn()
{
try
@ -930,11 +936,11 @@ namespace SocketExample
}
sender.SelectedItem = null;
}
catch(Exception ex)
catch (Exception ex)
{
Infotext += ex.Message;
}
}
void GPOComboBox_SelectChanged(ComboBox sender)
@ -966,7 +972,7 @@ namespace SocketExample
}
if (sender.SelectedItem?.ToString() == "高")
Order += "01 ";
else if(sender.SelectedItem?.ToString() == "低")
else if (sender.SelectedItem?.ToString() == "低")
Order += "00 ";
Order += "00 00 ";
Order += Convert.ToString(GetXor(strToToHexByte(Order), 2), 16) + " 0D";
@ -1021,11 +1027,11 @@ namespace SocketExample
public void dispose()
{
try
{
if(client!=null)
client.Close();
if(GPIOthread!=null)
GPIOthread.Abort();
{
if (client != null)
client.Close();
if (GPIOthread != null)
GPIOthread.Abort();
}
catch (Exception ex)
{
@ -1036,11 +1042,11 @@ namespace SocketExample
string CheckForOnce()
{
string actionstring = "AA 55 02 01 ";
if(TimeOut!=""&&TimeOut!=null)
if (TimeOut != "" && TimeOut != null)
actionstring += Convert.ToInt32(TimeOut).ToString("X").PadLeft(4, '0').Insert(2, " ") + " ";
else
actionstring +="00 00 ";
actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16).PadLeft(2,'0').ToUpper() + " 0D";
actionstring += "00 00 ";
actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16).PadLeft(2, '0').ToUpper() + " 0D";
return actionstring;
}
string CheckDuringTime()
@ -1121,7 +1127,7 @@ namespace SocketExample
public class TagItem : INotifyPropertyChanged
{
private string _originmessage;//原始数据
public string OriginMessage { get => _originmessage;set { _originmessage = value;OnPropertyChanged(); } }
public string OriginMessage { get => _originmessage; set { _originmessage = value; OnPropertyChanged(); } }
private string _rssiinfo;//RSSI强度
public string RSSIinfo { get => _rssiinfo; set { _rssiinfo = value; OnPropertyChanged(); } }
@ -1134,7 +1140,7 @@ namespace SocketExample
public string EPCinfo { get => _epcinfo; set { _epcinfo = value; OnPropertyChanged(); } }
public string EPCASC { get => _epcasc; set { _epcasc = value; OnPropertyChanged(); } }
public TagItem(string originMessage,string infoEPC,string ascEPC,string RSSI,string count,string time)
public TagItem(string originMessage, string infoEPC, string ascEPC, string RSSI, string count, string time)
{
OriginMessage = originMessage;
EPCinfo = infoEPC;
@ -1152,23 +1158,34 @@ namespace SocketExample
}
}
#region 主界面参数
int currentcount = 0;//目前客户端的数量
List<PanelItem> items = new List<PanelItem>();//客户端组件列表
public static double? WindowLeft { get; set; }
public static double? WindowTop { get; set; }
public static double? WindowWidth { get; set; }
public static double? WindowHeight { get; set; }
public static WindowState? OriginWindowState { get; set; }
public static int? Buttonflag { get; set; }
public TCPWindowV2()
{
InitializeComponent();
EnsureFolderExists("日志文件夹");
this.Closing += TCPWindowV2_Closing;
SaveWindowSettings();
Buttonflag = 0;
}
#endregion
//结束所有线程,防止心跳线程冗余
private void TCPWindowV2_Closing(object sender, CancelEventArgs e)
{
System.Environment.Exit(0);
}
int currentcount = 0;//目前客户端的数量
List<PanelItem> items = new List<PanelItem>();//客户端组件列表
#region 主界面按钮事件
private void GenerateButton_Click(object sender, RoutedEventArgs e)//添加客户端框体
{
if (int.TryParse(CountTextBox.Text, out int count) && count > 0)
@ -1189,13 +1206,50 @@ namespace SocketExample
}
}
private void Shutdown_Button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void Maxmize_Button_Click(object sender, RoutedEventArgs e)
{
if (Buttonflag == 0)
{
this.WindowState = WindowState.Maximized;
Maxmize_Button.Content = "缩小";
Buttonflag = 1;
}
else
{
LoadWindowSettings();
Maxmize_Button.Content = "最大化";
Buttonflag = 0;
}
}
private void Minimize_Button_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void ClearButton_Click(object sender, RoutedEventArgs e)//清空客户端
{
foreach (PanelItem item in items)
{
item.dispose();
}
items = new List<PanelItem>();
PanelContainer.ItemsSource = null;
currentcount = 0;
}
#endregion
public class LinkCommand : ICommand //command方法实现
{
private Action _excute;
private Action<int> _excutewithindex;
public LinkCommand(Action action) {
public LinkCommand(Action action)
{
_excute = action;
}
@ -1213,21 +1267,10 @@ namespace SocketExample
public void Execute(object parameter)
{
_excute();
_excute();
}
}
private void ClearButton_Click(object sender, RoutedEventArgs e)//清空客户端
{
foreach (PanelItem item in items)
{
item.dispose();
}
items = new List<PanelItem>();
PanelContainer.ItemsSource = null;
currentcount = 0;
}
private static List<TagInfo> GetTagInfos(byte[] AutoDealReportData)
{
List<TagInfo> tagInfoList = new List<TagInfo>();
@ -1403,7 +1446,7 @@ namespace SocketExample
}
}
private static void EnsureTxtExists(string txtPath,string MachineName,string IPinfo,string Portinfo)
private static void EnsureTxtExists(string txtPath, string MachineName, string IPinfo, string Portinfo)
{
// 检查指定的txt路径对应的txt是否已经存在
if (!File.Exists(txtPath))
@ -1425,5 +1468,39 @@ namespace SocketExample
}
}
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
this.DragMove();
}
}
private void LoadWindowSettings()
{
if (WindowLeft.HasValue && WindowTop.HasValue)
{
this.Left = WindowLeft.Value;
this.Top = WindowTop.Value;
}
if (WindowWidth.HasValue && WindowHeight.HasValue)
{
this.Width = WindowWidth.Value;
this.Height = WindowHeight.Value;
}
if (OriginWindowState.HasValue)
{
this.WindowState = OriginWindowState.Value;
}
}
private void SaveWindowSettings()
{
WindowLeft = this.Left;
WindowTop = this.Top;
WindowWidth = this.Width;
WindowHeight = this.Height;
OriginWindowState = this.WindowState;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Loading…
Cancel
Save