Browse Source

fixed ip

master
Z 5 months ago
parent
commit
22ea553ac1
  1. 1
      Example/Gateway/Script/Data/DataModbusGatewaySettings.cs
  2. 23
      Example/Gateway/Script/OutData/ValueGenerator.cs
  3. 11
      Example/Gateway/Script/View/ViewModbusGateway.cs

1
Example/Gateway/Script/Data/DataModbusGatewaySettings.cs

@ -4,6 +4,7 @@ using System.Collections.Generic;
namespace EGFramework.Examples.Gateway{ namespace EGFramework.Examples.Gateway{
public class DataModbusGatewaySetting{ public class DataModbusGatewaySetting{
public float Delay { set; get; } public float Delay { set; get; }
public AddressTCPClient TCPClientAddress { set; get; }
public Dictionary<string,DataModbus485Device> Devices485 = new Dictionary<string,DataModbus485Device>(); public Dictionary<string,DataModbus485Device> Devices485 = new Dictionary<string,DataModbus485Device>();
public Dictionary<string,DataModbusTCPDevice> DevicesTCP = new Dictionary<string,DataModbusTCPDevice>(); public Dictionary<string,DataModbusTCPDevice> DevicesTCP = new Dictionary<string,DataModbusTCPDevice>();
} }

23
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;
}
}

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

@ -28,7 +28,7 @@ namespace EGFramework.Examples.Gateway{
// GD.Print(fData.ToFloatArrayBigEndian()[0]); // GD.Print(fData.ToFloatArrayBigEndian()[0]);
this.EGRegisterMessageEvent<TypeTCPSetRotateData>(e=>{ this.EGRegisterMessageEvent<TypeTCPSetRotateData>(e=>{
if(e.ValueSet.ContainsKey("rotational_speed")){ 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!"); GD.Print("Write success!");
} }
}); });
@ -148,17 +148,18 @@ namespace EGFramework.Examples.Gateway{
{ "type", "SpeedControlDeviceLogin" } { "type", "SpeedControlDeviceLogin" }
}; };
// this.EGTCPClient().SendStringData("192.168.1.11",9966,loginData.ToString()); // 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); await Task.Delay(50);
// this.EGTCPClient().SendStringData("192.168.1.11",9966,resultJson); // 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 registerKey,object value){
public async void WriteHoldingRegisterTCP(string ipPort,string registerKey,object value){
DataModbusValue modbusValue = null; DataModbusValue modbusValue = null;
string ipPort = "";
foreach(KeyValuePair<string,DataModbusTCPDevice> deviceTCP in Setting.DevicesTCP){ foreach(KeyValuePair<string,DataModbusTCPDevice> deviceTCP in Setting.DevicesTCP){
if(Setting.DevicesTCP[deviceTCP.Key].ValueRegisters.ContainsKey(registerKey)){ if(Setting.DevicesTCP[deviceTCP.Key].ValueRegisters.ContainsKey(registerKey)){
modbusValue = Setting.DevicesTCP[deviceTCP.Key].ValueRegisters[registerKey]; modbusValue = Setting.DevicesTCP[deviceTCP.Key].ValueRegisters[registerKey];
ipPort = Setting.DevicesTCP[registerKey].Host+":"+Setting.DevicesTCP[registerKey].Port;
} }
} }
if(modbusValue == null){ if(modbusValue == null){

Loading…
Cancel
Save