From b2b7cb9adbbdd6e60257db83da6a7d3f5ed1b065 Mon Sep 17 00:00:00 2001 From: Z Date: Fri, 28 Jun 2024 09:03:36 +0800 Subject: [PATCH] fixed egmessage set delay not effect bugs --- Example/Gateway/Script/View/ViewModbusGateway.cs | 1 + addons/EGFramework/Module/EGMessage.cs | 1 + addons/EGFramework/Module/ProtocolTools/EGModbus.cs | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Example/Gateway/Script/View/ViewModbusGateway.cs b/Example/Gateway/Script/View/ViewModbusGateway.cs index 820331d..de63b79 100644 --- a/Example/Gateway/Script/View/ViewModbusGateway.cs +++ b/Example/Gateway/Script/View/ViewModbusGateway.cs @@ -33,6 +33,7 @@ namespace EGFramework.Examples.Gateway{ } }); this.EGOnMessage(); + this.GetModule().SetDelay(0); } // Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/addons/EGFramework/Module/EGMessage.cs b/addons/EGFramework/Module/EGMessage.cs index 1ac2649..b1c38c4 100644 --- a/addons/EGFramework/Module/EGMessage.cs +++ b/addons/EGFramework/Module/EGMessage.cs @@ -85,6 +85,7 @@ namespace EGFramework public void SetDelay(int millisecond){ this.SendDelay = millisecond; + RequestTimer.Interval = millisecond; } } diff --git a/addons/EGFramework/Module/ProtocolTools/EGModbus.cs b/addons/EGFramework/Module/ProtocolTools/EGModbus.cs index 5bc5ea9..4a47554 100644 --- a/addons/EGFramework/Module/ProtocolTools/EGModbus.cs +++ b/addons/EGFramework/Module/ProtocolTools/EGModbus.cs @@ -209,7 +209,7 @@ namespace EGFramework{ return res; } - public async Task WriteOnceTCPAsync(ModbusRegisterType registerType,string serialPort,byte deviceAddress,ushort registerAddress,object value){ + public async Task WriteOnceTCPAsync(ModbusRegisterType registerType,string ipPort,byte deviceAddress,ushort registerAddress,object value){ if(IsRequestTCP){ SendPointerTCP++; int messageId = SendPointerTCP; @@ -232,7 +232,7 @@ namespace EGFramework{ switch(registerType){ case ModbusRegisterType.Coil: WriteRequest = new ModbusTCP_WriteSingleCoil(deviceAddress,registerAddress,(bool)value); - this.EGSendMessage(WriteRequest,serialPort,ProtocolType.TCPClient); + this.EGSendMessage(WriteRequest,ipPort,ProtocolType.TCPClient); break; case ModbusRegisterType.HoldingRegister: if(value.GetType() == typeof(float)){ @@ -241,7 +241,7 @@ namespace EGFramework{ }else{ WriteRequest = new ModbusTCP_WriteSingleHoldingRegister(deviceAddress,registerAddress,(ushort)value); } - this.EGSendMessage(WriteRequest,serialPort,ProtocolType.TCPClient); + this.EGSendMessage(WriteRequest,ipPort,ProtocolType.TCPClient); break; } await Task.Run(async ()=>{