sc 11 months ago
parent
commit
e8cd6f53a9
  1. 17
      UserClass/AsyncTcpClient.cs
  2. 14
      ViewModel/MainWindowViewModel.cs

17
UserClass/AsyncTcpClient.cs

@ -32,6 +32,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
/// </summary>
public class AsyncTcpClient
{
public static async Task TcpClient(TcpClient tcpClient, string ip, string port)
{
//TcpClient tcpClient = new TcpClient();
@ -56,7 +57,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
drEmployee.AcceptChanges();
drEmployee.ClearErrors();
return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
return EasyTask.CompletedTask;
};//即将从服务器断开连接。此处仅主动断开才有效。
tcpClient.Closed = (client, e) =>
{
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First();
@ -66,17 +68,22 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
drEmployee.AcceptChanges();
drEmployee.ClearErrors();
return EasyTask.CompletedTask; };//从服务器断开连接,当连接不成功时不会触发。
return EasyTask.CompletedTask;
};//从服务器断开连接,当连接不成功时不会触发。
tcpClient.Received = (client, e) =>
{
//从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
string SYSAPI = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(0, 5);
string DAT = e.ByteBlock.Span.ToString(Encoding.ASCII);
string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8);
if (SYSAPI == "SC851")
{
DAT = DAT.Substring(DAT.IndexOf("]") + 1);
DataTable obj = JsonConvert.DeserializeObject<DataTable>(DAT);//反序列化
// client.SendAsync("SC851" + "[" + MainWindowViewModel.S01 + "]" + MainWindowViewModel.dt_d.ToJsonString());//数字开关信息
@ -91,6 +98,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
//载入配置
await tcpClient.SetupAsync(new TouchSocketConfig()
.SetMaxBufferSize(1024*1024)
.SetMinBufferSize(1024*64)
.SetRemoteIPHost(ip + ":" + port)
.ConfigurePlugins(a =>
{
@ -122,6 +131,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
}*/
}
}
}

14
ViewModel/MainWindowViewModel.cs

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenTK.Graphics.ES11;
using SunlightCentralizedControlManagement_SCCM_.Properties;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
@ -82,9 +83,16 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
for (int i = 0; i < Machinesdata_Count; i++)
{
if ( Selet_Machines(Machines,"State", i).ToString() =="801")
MachiensTcpClient[i].SendAsync("SC800:SCCM["+ MachiensTcpClient[i].IP+";"+ MachiensTcpClient[i].Port+"]");
// if ( Selet_Machines(Machines,"State", i).ToString() =="801")
// MachiensTcpClient[i].SendAsync("SC800:SCCM["+ MachiensTcpClient[i].IP+";"+ MachiensTcpClient[i].Port+"]");
MachiensTcpClient[1].SendAsync("SC851BED2E58B6EBB4BD4");
}
// DataTable obj = JsonConvert.DeserializeObject<DataTable>(yt);//反序列化
}
void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS
{

Loading…
Cancel
Save