diff --git a/SocketExample/FodyWeavers.xml b/SocketExample/FodyWeavers.xml new file mode 100644 index 0000000..a5dcf04 --- /dev/null +++ b/SocketExample/FodyWeavers.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SocketExample/MyTouchClass.cs b/SocketExample/MyTouchClass.cs new file mode 100644 index 0000000..82da05d --- /dev/null +++ b/SocketExample/MyTouchClass.cs @@ -0,0 +1,83 @@ +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); + } + } + } +} diff --git a/SocketExample/RFIDmonitor.csproj b/SocketExample/RFIDmonitor.csproj index 650a992..3487987 100644 --- a/SocketExample/RFIDmonitor.csproj +++ b/SocketExample/RFIDmonitor.csproj @@ -1,5 +1,6 @@ + Debug @@ -63,6 +64,9 @@ ..\packages\CommonServiceLocator.2.0.2\lib\net47\CommonServiceLocator.dll + + ..\packages\Costura.Fody.6.0.0\lib\netstandard2.0\Costura.dll + ..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.dll @@ -203,6 +207,7 @@ + TCPWindowV2.xaml @@ -272,6 +277,9 @@ + + + @@ -279,5 +287,10 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/SocketExample/TCPWindowV2.xaml b/SocketExample/TCPWindowV2.xaml index 56a95e1..f2ee66f 100644 --- a/SocketExample/TCPWindowV2.xaml +++ b/SocketExample/TCPWindowV2.xaml @@ -105,9 +105,10 @@ - +