From a86ba21cffecf274ea026128a8cafb6d52563450 Mon Sep 17 00:00:00 2001 From: Z Date: Wed, 26 Jun 2024 11:55:45 +0800 Subject: [PATCH] fixed type struct --- .../Gateway/Script/View/ViewModbusGateway.cs | 23 ++++++++++++++++--- .../Module/ProtocolTools/EGTCPClient.cs | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Example/Gateway/Script/View/ViewModbusGateway.cs b/Example/Gateway/Script/View/ViewModbusGateway.cs index 8636ebf..c43bc9b 100644 --- a/Example/Gateway/Script/View/ViewModbusGateway.cs +++ b/Example/Gateway/Script/View/ViewModbusGateway.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Text.Json.Nodes; +using System.Threading.Tasks; namespace EGFramework.Examples.Gateway{ public partial class ViewModbusGateway : Control,IEGFramework,IGateway @@ -131,9 +132,17 @@ namespace EGFramework.Examples.Gateway{ } } } - string resultJson = JsonConvert.SerializeObject(pushData,Formatting.Indented); - GD.Print(resultJson); - this.EGTCPClient().SendStringData("192.168.1.170",5501,resultJson); + string resultJson = JsonConvert.SerializeObject(pushData); + resultJson = JsonConvert.SerializeObject(new TypeTCPRotateData(resultJson),Formatting.Indented); + // GD.Print(resultJson); + JObject loginData = new JObject + { + { "type", "SpeedControlDeviceLogin" } + }; + this.EGTCPClient().SendStringData("192.168.1.11",9966,loginData.ToString()); + await Task.Delay(50); + this.EGTCPClient().SendStringData("192.168.1.11",9966,resultJson); + } public async void ReadTest(){ @@ -227,4 +236,12 @@ namespace EGFramework.Examples.Gateway{ } } + public struct TypeTCPRotateData{ + public string type; + public string data; + public TypeTCPRotateData(string data){ + this.type = "SendRotationalSpeed"; + this.data = data; + } + } } diff --git a/addons/EGFramework/Module/ProtocolTools/EGTCPClient.cs b/addons/EGFramework/Module/ProtocolTools/EGTCPClient.cs index 753f54e..a18d320 100644 --- a/addons/EGFramework/Module/ProtocolTools/EGTCPClient.cs +++ b/addons/EGFramework/Module/ProtocolTools/EGTCPClient.cs @@ -141,6 +141,7 @@ namespace EGFramework{ byte[] receivedByte = new byte[bytesRead]; Array.Copy(buffer, 0, receivedByte, 0, bytesRead); ResponseMsg receivedMsgs = new ResponseMsg(data,receivedByte,ClientName, ProtocolType.TCPClient); + Godot.GD.Print("[TCP-R]+("+ClientName+")" + data); ResponseMsgs.Enqueue(receivedMsgs); //this.EGOnReceivedData(receivedMsgs); }