diff --git a/Example/Gateway/Script/Data/DataModbusGatewaySettings.cs b/Example/Gateway/Script/Data/DataModbusGatewaySettings.cs index 37f3571..833e77e 100644 --- a/Example/Gateway/Script/Data/DataModbusGatewaySettings.cs +++ b/Example/Gateway/Script/Data/DataModbusGatewaySettings.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; namespace EGFramework.Examples.Gateway{ public class DataModbusGatewaySetting{ public float Delay { set; get; } + public AddressTCPClient TCPClientAddress { set; get; } public Dictionary Devices485 = new Dictionary(); public Dictionary DevicesTCP = new Dictionary(); } diff --git a/Example/Gateway/Script/OutData/ValueGenerator.cs b/Example/Gateway/Script/OutData/ValueGenerator.cs new file mode 100644 index 0000000..e18f326 --- /dev/null +++ b/Example/Gateway/Script/OutData/ValueGenerator.cs @@ -0,0 +1,23 @@ + +using System; + +public class ValueGenerator +{ + int Value = 0; + float ValueFloat = 0f; + public int GenerateValue(){ + Value ++; + if(Value>10){ + Value = 0; + } + return Value; + } + + public float GenerateFValue(){ + ValueFloat += 0.1f; + if(ValueFloat>10){ + ValueFloat = 0; + } + return ValueFloat; + } +} diff --git a/Example/Gateway/Script/View/ViewModbusGateway.cs b/Example/Gateway/Script/View/ViewModbusGateway.cs index de63b79..46144b2 100644 --- a/Example/Gateway/Script/View/ViewModbusGateway.cs +++ b/Example/Gateway/Script/View/ViewModbusGateway.cs @@ -28,7 +28,7 @@ namespace EGFramework.Examples.Gateway{ // GD.Print(fData.ToFloatArrayBigEndian()[0]); this.EGRegisterMessageEvent(e=>{ if(e.ValueSet.ContainsKey("rotational_speed")){ - WriteHoldingRegisterTCP("192.168.1.170:8234","rotational_speed",e.ValueSet["rotational_speed"]); + WriteHoldingRegisterTCP("rotational_speed",e.ValueSet["rotational_speed"]); GD.Print("Write success!"); } }); @@ -148,17 +148,18 @@ namespace EGFramework.Examples.Gateway{ { "type", "SpeedControlDeviceLogin" } }; // this.EGTCPClient().SendStringData("192.168.1.11",9966,loginData.ToString()); - this.EGTCPClient().SendStringData("192.168.1.170",5501,loginData.ToString()); + this.EGTCPClient().SendStringData(Setting.TCPClientAddress.Host,Setting.TCPClientAddress.Port,loginData.ToString()); await Task.Delay(50); // this.EGTCPClient().SendStringData("192.168.1.11",9966,resultJson); - this.EGTCPClient().SendStringData("192.168.1.170",5501,resultJson); + this.EGTCPClient().SendStringData(Setting.TCPClientAddress.Host,Setting.TCPClientAddress.Port,resultJson); } - - public async void WriteHoldingRegisterTCP(string ipPort,string registerKey,object value){ + public async void WriteHoldingRegisterTCP(string registerKey,object value){ DataModbusValue modbusValue = null; + string ipPort = ""; foreach(KeyValuePair deviceTCP in Setting.DevicesTCP){ if(Setting.DevicesTCP[deviceTCP.Key].ValueRegisters.ContainsKey(registerKey)){ modbusValue = Setting.DevicesTCP[deviceTCP.Key].ValueRegisters[registerKey]; + ipPort = Setting.DevicesTCP[registerKey].Host+":"+Setting.DevicesTCP[registerKey].Port; } } if(modbusValue == null){