diff --git a/Properties/Resources.zh-TW.resx b/Properties/Resources.zh-TW.resx index eb1f7e7..8496e0d 100644 --- a/Properties/Resources.zh-TW.resx +++ b/Properties/Resources.zh-TW.resx @@ -924,4 +924,7 @@ 今天 + + 測試 + \ No newline at end of file diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 7dd945f..6eefb8a 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -23,6 +23,8 @@ using Newtonsoft.Json; using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper; using SunlightCentralizedControlManagement_SCCM_.View; using TcpClient = TouchSocket.Sockets.TcpClient; +using Newtonsoft.Json.Linq; +using System.Xml.Linq; namespace SunlightCentralizedControlManagement_SCCM_.UserClass {/// @@ -30,13 +32,19 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass /// public class AsyncTcpClient { - public static async Task TcpClient(TcpClient tcpClient, string ip,string port) + public static async Task TcpClient(TcpClient tcpClient, string ip,string port) { //TcpClient tcpClient = new TcpClient(); tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp - tcpClient.Connected = (client, e) => - { - + tcpClient.Connected = (client, e) => + { + DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First(); + drEmployee.BeginEdit(); + drEmployee["State"] = "101"; + drEmployee.EndEdit(); + drEmployee.AcceptChanges(); + drEmployee.ClearErrors(); + return EasyTask.CompletedTask; };//成功连接到服务器 tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。 @@ -58,13 +66,24 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass .SetRemoteIPHost(ip+":"+port) .ConfigurePlugins(a => { + a.UseCheckClear() + .SetCheckClearType(CheckClearType.All) + .SetTick(TimeSpan.FromSeconds(30)) + .SetOnClose((c, t) => + { + c.TryShutdown(); + }); a.UseTcpReconnection();//触发型重连 }) .ConfigureContainer(a => { // a.AddConsoleLogger();//添加一个日志注入 })); - try + + // Result result = await + _ = tcpClient.TryConnectAsync(); + // return result.IsSuccess; + /* try { await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。 return true; @@ -72,7 +91,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass catch { return false; - } + }*/ } } diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 259f8b3..615b45c 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -106,9 +106,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel private readonly TcpClient[] MachiensTcpClient = new TcpClient[999]; public int Machinesdata_Count; - public async void TcpClientNEW() + public void TcpClientNEW() { - bool Machine_ = false; + // bool Machine_ ; DataRow[] machinesdata = Machines.Select("PORT>0 AND IP<>''", "id asc");//获取连接有效的组 Machinesdata_Count = machinesdata.Count(); @@ -116,14 +116,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { MachiensTcpClient[i] = new TcpClient(); DataRow dt = machinesdata[i]; - - Machine_ = await AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接 - , Selet_Machines(MainWindowViewModel.Machines, "IP", Convert.ToInt16(dt["ID"])).ToString() - , Selet_Machines(MainWindowViewModel.Machines, "PORT", Convert.ToInt16(dt["ID"])).ToString()); - - if (!Machine_) Updata_Machines(Machines , Convert.ToInt16(dt["ID"]), "State" ,"309" ); - } - } + Updata_Machines(Machines, Convert.ToInt16(dt["ID"]), "State", "800"); + _ = AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接 + , Selet_Machines(Machines, "IP", Convert.ToInt16(dt["ID"])).ToString() + , Selet_Machines(Machines, "PORT", Convert.ToInt16(dt["ID"])).ToString()); + } + } public static string SYS_WorkNumder; //工单号 public static int SYS_AT1; //附缸1-3