You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Net.NetworkInformation ;
using System.Text ;
using System.Threading ;
using System.Threading.Tasks ;
using System.Windows ;
using TouchSocket ;
using TouchSocket.Core ;
using TouchSocket.Sockets ;
using static SocketExample . TCPWindowV2 ;
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
{
protected override async Task OnTcpReceived ( ReceivedDataEventArgs e )
{
//此处逻辑单线程处理。
//此处处理数据, 功能相当于Received委托。
var mes = e . ByteBlock . Span . ToString ( Encoding . UTF8 ) ;
Console . WriteLine ( $"已接收到信息:{mes}" ) ;
await base . OnTcpReceived ( e ) ;
}
}
}
}