Browse Source

fixed egmessage set delay not effect bugs

master
Z 5 months ago
parent
commit
b2b7cb9adb
  1. 1
      Example/Gateway/Script/View/ViewModbusGateway.cs
  2. 1
      addons/EGFramework/Module/EGMessage.cs
  3. 6
      addons/EGFramework/Module/ProtocolTools/EGModbus.cs

1
Example/Gateway/Script/View/ViewModbusGateway.cs

@ -33,6 +33,7 @@ namespace EGFramework.Examples.Gateway{
} }
}); });
this.EGOnMessage<TypeTCPSetRotateData>(); this.EGOnMessage<TypeTCPSetRotateData>();
this.GetModule<EGMessage>().SetDelay(0);
} }
// Called every frame. 'delta' is the elapsed time since the previous frame. // Called every frame. 'delta' is the elapsed time since the previous frame.

1
addons/EGFramework/Module/EGMessage.cs

@ -85,6 +85,7 @@ namespace EGFramework
public void SetDelay(int millisecond){ public void SetDelay(int millisecond){
this.SendDelay = millisecond; this.SendDelay = millisecond;
RequestTimer.Interval = millisecond;
} }
} }

6
addons/EGFramework/Module/ProtocolTools/EGModbus.cs

@ -209,7 +209,7 @@ namespace EGFramework{
return res; return res;
} }
public async Task<ModbusTCP_Response?> WriteOnceTCPAsync(ModbusRegisterType registerType,string serialPort,byte deviceAddress,ushort registerAddress,object value){ public async Task<ModbusTCP_Response?> WriteOnceTCPAsync(ModbusRegisterType registerType,string ipPort,byte deviceAddress,ushort registerAddress,object value){
if(IsRequestTCP){ if(IsRequestTCP){
SendPointerTCP++; SendPointerTCP++;
int messageId = SendPointerTCP; int messageId = SendPointerTCP;
@ -232,7 +232,7 @@ namespace EGFramework{
switch(registerType){ switch(registerType){
case ModbusRegisterType.Coil: case ModbusRegisterType.Coil:
WriteRequest = new ModbusTCP_WriteSingleCoil(deviceAddress,registerAddress,(bool)value); WriteRequest = new ModbusTCP_WriteSingleCoil(deviceAddress,registerAddress,(bool)value);
this.EGSendMessage(WriteRequest,serialPort,ProtocolType.TCPClient); this.EGSendMessage(WriteRequest,ipPort,ProtocolType.TCPClient);
break; break;
case ModbusRegisterType.HoldingRegister: case ModbusRegisterType.HoldingRegister:
if(value.GetType() == typeof(float)){ if(value.GetType() == typeof(float)){
@ -241,7 +241,7 @@ namespace EGFramework{
}else{ }else{
WriteRequest = new ModbusTCP_WriteSingleHoldingRegister(deviceAddress,registerAddress,(ushort)value); WriteRequest = new ModbusTCP_WriteSingleHoldingRegister(deviceAddress,registerAddress,(ushort)value);
} }
this.EGSendMessage(WriteRequest,serialPort,ProtocolType.TCPClient); this.EGSendMessage(WriteRequest,ipPort,ProtocolType.TCPClient);
break; break;
} }
await Task.Run(async ()=>{ await Task.Run(async ()=>{

Loading…
Cancel
Save