1.服务端基本完成

master
zhangxy 1 day ago
parent c1838474f3
commit e22e87dbf5

@ -14,57 +14,6 @@ namespace SocketExample
{
public class MyTouchClass
{
public void ConnectedSend()
{
try
{
//streamWriter = new StreamWriter(path);
byte[] data = strToToHexByte("AA 55 01 70 00 71 0D");//获取模块信息
option = "00";
client.Send(data);
Thread.Sleep(500);
data = strToToHexByte("AA 55 01 70 03 72 0D");//获取主板硬件信息
option = "03";
client.Send(data);
Thread.Sleep(500);
data = strToToHexByte("AA 55 01 70 04 75 0D");//获取主板固件信息
option = "04";
client.Send(data);
Thread.Sleep(500);
data = strToToHexByte("AA 55 00 72 72 0D");//获取功率状态
client.Send(data);
Thread.Sleep(500);
data = strToToHexByte("AA 55 00 81 81 0D");//获取GPIO状态
client.Send(data);
Thread.Sleep(500);
data = strToToHexByte("AA 55 02 02 07 D0 D7 0D");//获取1000ms内标签信息
client.Send(data);
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(1000); }
}));
GPIOthread.Start();//心跳获取GPIO状态
}
catch (Exception ex)
{
Infotext += $"连接时报错,错误内容:{ex}\n";
}
}
public sealed class MySessionClient : TcpSessionClient
{
@ -74,10 +23,36 @@ namespace SocketExample
//此处处理数据功能相当于Received委托。
var mes = e.ByteBlock.Span.ToString(Encoding.UTF8);
Console.WriteLine($"已接收到信息:{mes}");
MessageBox.Show($"已接收到信息:{mes}");
await base.OnTcpReceived(e);
}
}
public class MyService : TcpService<MySessionClient>
{
protected override void LoadConfig(TouchSocketConfig config)
{
//此处加载配置,用户可以从配置中获取配置项。
base.LoadConfig(config);
}
protected override MySessionClient NewClient()
{
return new MySessionClient();
}
protected override async Task OnTcpConnecting(MySessionClient socketClient, ConnectingEventArgs e)
{
//此处逻辑会多线程处理。
//e.Id:对新连接的客户端进行ID初始化默认情况下是按照设定的规则随机分配的。
//但是按照需求您可以自定义设置例如设置为其IP地址。但是需要注意的是id必须在生命周期内唯一。
//e.IsPermitOperation:指示是否允许该客户端链接。
await base.OnTcpConnecting(socketClient, e);
}
}
}
}

File diff suppressed because it is too large Load Diff

@ -208,6 +208,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="MyTouchClass.cs" />
<Compile Include="PanelItem.cs" />
<Compile Include="TCPWindowV2.xaml.cs">
<DependentUpon>TCPWindowV2.xaml</DependentUpon>
</Compile>

@ -8,7 +8,7 @@
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:local="clr-namespace:SocketExample"
mc:Ignorable="d"
Title="RFID读写器多终端监控软件v1.093" Height="680" Width="1180"
Title="RFID读写器多终端监控软件v1.11" Height="680" Width="1180"
Background="Transparent" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Window.Resources>
@ -150,11 +150,11 @@
<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"/>
<TextBox TextWrapping="Wrap" x:Name="IPtextbox" Text="{Binding IPtext}" Width="100" Height="20" Margin="5 8 0 0" IsReadOnly="{Binding IPtext_ReadOnly}"/>
</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"/>
<TextBox TextWrapping="Wrap" Text="{Binding Porttext}" x:Name="Porttextbox" Width="45" Height="20" Margin="5 8 0 0" IsReadOnly="{Binding Porttext_ReadOnly}"/>
<!-- <Button Content="读取" Height="20" Width="40" Margin="10 8 0 0" Command="{Binding _readcomn}" Style="{StaticResource SocketButton}"/>-->
</StackPanel>
</StackPanel>

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save