Add alias to machine
This commit is contained in:
@@ -27,8 +27,8 @@ namespace Modbus.Net.HJ212
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">设备的ID号</param>
|
/// <param name="id">设备的ID号</param>
|
||||||
/// <param name="connectionString">连接地址</param>
|
/// <param name="connectionString">连接地址</param>
|
||||||
public HJ212Machine(TKey id, string connectionString, string st, string cn, string pw, string mn)
|
public HJ212Machine(TKey id, string alias, string connectionString, string st, string cn, string pw, string mn)
|
||||||
: base(id, null, true)
|
: base(id, alias, null, true)
|
||||||
{
|
{
|
||||||
BaseUtility = new HJ212Utility(connectionString);
|
BaseUtility = new HJ212Utility(connectionString);
|
||||||
ST = st;
|
ST = st;
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ namespace Modbus.Net.Modbus
|
|||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
/// <param name="endian">端格式</param>
|
/// <param name="endian">端格式</param>
|
||||||
public ModbusMachine(TKey id, ModbusType connectionType, string connectionString,
|
public ModbusMachine(TKey id, string alias, ModbusType connectionType, string connectionString,
|
||||||
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress,
|
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress,
|
||||||
Endian endian)
|
Endian endian)
|
||||||
: base(id, getAddresses, keepConnect, slaveAddress, masterAddress)
|
: base(id, alias, getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
BaseUtility = new ModbusUtility(connectionType, connectionString, slaveAddress, masterAddress, endian);
|
BaseUtility = new ModbusUtility(connectionType, connectionString, slaveAddress, masterAddress, endian);
|
||||||
AddressFormater = new AddressFormaterModbus();
|
AddressFormater = new AddressFormaterModbus();
|
||||||
@@ -41,10 +41,10 @@ namespace Modbus.Net.Modbus
|
|||||||
/// <param name="slaveAddress">从站号</param>
|
/// <param name="slaveAddress">从站号</param>
|
||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
/// <param name="endian">端格式</param>
|
/// <param name="endian">端格式</param>
|
||||||
public ModbusMachine(TKey id, ModbusType connectionType, string connectionString,
|
public ModbusMachine(TKey id, string alias, ModbusType connectionType, string connectionString,
|
||||||
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, byte slaveAddress, byte masterAddress,
|
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, byte slaveAddress, byte masterAddress,
|
||||||
Endian endian)
|
Endian endian)
|
||||||
: this(id, connectionType, connectionString, getAddresses, true, slaveAddress, masterAddress, endian)
|
: this(id, alias, connectionType, connectionString, getAddresses, true, slaveAddress, masterAddress, endian)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ namespace Modbus.Net.Siemens
|
|||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
/// <param name="src">本机模块位,0到7,仅200使用,其它型号不要填写</param>
|
/// <param name="src">本机模块位,0到7,仅200使用,其它型号不要填写</param>
|
||||||
/// <param name="dst">PLC模块位,0到7,仅200使用,其它型号不要填写</param>
|
/// <param name="dst">PLC模块位,0到7,仅200使用,其它型号不要填写</param>
|
||||||
public SiemensMachine(TKey id, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
public SiemensMachine(TKey id, string alias, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||||
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress, byte src = 1, byte dst = 0)
|
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, bool keepConnect, byte slaveAddress, byte masterAddress, byte src = 1, byte dst = 0)
|
||||||
: base(id, getAddresses, keepConnect, slaveAddress, masterAddress)
|
: base(id, alias, getAddresses, keepConnect, slaveAddress, masterAddress)
|
||||||
{
|
{
|
||||||
BaseUtility = new SiemensUtility(connectionType, connectionString, model, slaveAddress, masterAddress, src, dst);
|
BaseUtility = new SiemensUtility(connectionType, connectionString, model, slaveAddress, masterAddress, src, dst);
|
||||||
AddressFormater = new AddressFormaterSiemens();
|
AddressFormater = new AddressFormaterSiemens();
|
||||||
@@ -44,9 +44,9 @@ namespace Modbus.Net.Siemens
|
|||||||
/// <param name="masterAddress">主站号</param>
|
/// <param name="masterAddress">主站号</param>
|
||||||
/// <param name="src">本机模块位,0到7,仅200使用,其它型号不要填写</param>
|
/// <param name="src">本机模块位,0到7,仅200使用,其它型号不要填写</param>
|
||||||
/// <param name="dst">PLC模块位,0到7,仅200使用,其它型号不要填写</param>
|
/// <param name="dst">PLC模块位,0到7,仅200使用,其它型号不要填写</param>
|
||||||
public SiemensMachine(TKey id, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
public SiemensMachine(TKey id, string alias, SiemensType connectionType, string connectionString, SiemensMachineModel model,
|
||||||
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, byte slaveAddress, byte masterAddress, byte src = 1, byte dst = 0)
|
IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, byte slaveAddress, byte masterAddress, byte src = 1, byte dst = 0)
|
||||||
: this(id, connectionType, connectionString, model, getAddresses, true, slaveAddress, masterAddress, src, dst)
|
: this(id, alias, connectionType, connectionString, model, getAddresses, true, slaveAddress, masterAddress, src, dst)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ namespace Modbus.Net
|
|||||||
/// <param name="keepConnect">是否保持连接</param>
|
/// <param name="keepConnect">是否保持连接</param>
|
||||||
/// <param name="slaveAddress">从站地址</param>
|
/// <param name="slaveAddress">从站地址</param>
|
||||||
/// <param name="masterAddress">主站地址</param>
|
/// <param name="masterAddress">主站地址</param>
|
||||||
protected BaseMachine(TKey id, IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, bool keepConnect, byte slaveAddress,
|
protected BaseMachine(TKey id, string alias, IEnumerable<AddressUnit<TUnitKey, int, int>> getAddresses, bool keepConnect, byte slaveAddress,
|
||||||
byte masterAddress) : base(id, getAddresses, keepConnect)
|
byte masterAddress) : base(id, alias, getAddresses, keepConnect)
|
||||||
{
|
{
|
||||||
SlaveAddress = slaveAddress;
|
SlaveAddress = slaveAddress;
|
||||||
MasterAddress = masterAddress;
|
MasterAddress = masterAddress;
|
||||||
@@ -510,8 +510,8 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">设备的ID号</param>
|
/// <param name="id">设备的ID号</param>
|
||||||
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
||||||
protected BaseMachine(TKey id, IEnumerable<AddressUnit<TUnitKey, TAddressKey, TSubAddressKey>> getAddresses)
|
protected BaseMachine(TKey id, string alias, IEnumerable<AddressUnit<TUnitKey, TAddressKey, TSubAddressKey>> getAddresses)
|
||||||
: this(id, getAddresses, false)
|
: this(id, alias, getAddresses, false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,11 +521,22 @@ namespace Modbus.Net
|
|||||||
/// <param name="id">设备的ID号</param>
|
/// <param name="id">设备的ID号</param>
|
||||||
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
/// <param name="getAddresses">需要与设备通讯的地址</param>
|
||||||
/// <param name="keepConnect">是否保持连接</param>
|
/// <param name="keepConnect">是否保持连接</param>
|
||||||
protected BaseMachine(TKey id, IEnumerable<AddressUnit<TUnitKey, TAddressKey, TSubAddressKey>> getAddresses, bool keepConnect)
|
protected BaseMachine(TKey id, string alias, IEnumerable<AddressUnit<TUnitKey, TAddressKey, TSubAddressKey>> getAddresses, bool keepConnect)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
GetAddresses = getAddresses;
|
GetAddresses = getAddresses;
|
||||||
KeepConnect = keepConnect;
|
KeepConnect = keepConnect;
|
||||||
|
if (alias.Contains(':'))
|
||||||
|
{
|
||||||
|
var aliasArray = alias.Split(':');
|
||||||
|
ProjectName = aliasArray[0];
|
||||||
|
MachineName = aliasArray[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ProjectName = "";
|
||||||
|
MachineName = alias;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly int _maxErrorCount = 3;
|
private readonly int _maxErrorCount = 3;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace AnyType.Controllers
|
|||||||
Value = 0,
|
Value = 0,
|
||||||
Type = unitValue.DataType.Name
|
Type = unitValue.DataType.Name
|
||||||
};
|
};
|
||||||
var machine = new ModbusMachine("1", ModbusType.Tcp, "10.10.18.251:502", addressUnits, true, 2, 0, Endian.BigEndianLsb);
|
var machine = new ModbusMachine("1", "", ModbusType.Tcp, "10.10.18.251:502", addressUnits, true, 2, 0, Endian.BigEndianLsb);
|
||||||
//启动任务
|
//启动任务
|
||||||
await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 1).Result.From(machine.Id, machine, MachineDataType.CommunicationTag).Result.Query("Query1",
|
await MachineJobSchedulerCreator.CreateScheduler("Trigger1", -1, 1).Result.From(machine.Id, machine, MachineDataType.CommunicationTag).Result.Query("Query1",
|
||||||
returnValues =>
|
returnValues =>
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace TripleAdd.Controllers
|
|||||||
{
|
{
|
||||||
if (machine == null)
|
if (machine == null)
|
||||||
{
|
{
|
||||||
machine = new ModbusMachine<string, string>("1", ModbusType.Tcp, "10.10.18.251", new List<AddressUnit>()
|
machine = new ModbusMachine<string, string>("1", "", ModbusType.Tcp, "10.10.18.251", new List<AddressUnit>()
|
||||||
{
|
{
|
||||||
new AddressUnit() {Id = "1", Area = "4X", Address = 1, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
new AddressUnit() {Id = "1", Area = "4X", Address = 1, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||||
new AddressUnit() {Id = "2", Area = "4X", Address = 2, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
new AddressUnit() {Id = "2", Area = "4X", Address = 2, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ namespace Modbus.Net.Tests
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
_baseMachine = new SiemensMachine<int, int>(2, SiemensType.Tcp, _machineIp, SiemensMachineModel.S7_1200, _addressUnits, true, 2, 0, 1, 0)
|
_baseMachine = new SiemensMachine<int, int>(2, "", SiemensType.Tcp, _machineIp, SiemensMachineModel.S7_1200, _addressUnits, true, 2, 0, 1, 0)
|
||||||
{
|
{
|
||||||
ProjectName = "Project 1",
|
ProjectName = "Project 1",
|
||||||
MachineName = "Test 2"
|
MachineName = "Test 2"
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace Modbus.Net.Tests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
_modbusTcpMachine = new ModbusMachine<string, string>("1", ModbusType.Tcp, _machineIp, null, true, 1, 0, Endian.BigEndianLsb);
|
_modbusTcpMachine = new ModbusMachine<string, string>("1", "",ModbusType.Tcp, _machineIp, null, true, 1, 0, Endian.BigEndianLsb);
|
||||||
|
|
||||||
_modbusTcpMachine2 = new ModbusMachine<string, string>("2", ModbusType.Tcp, _machineIp, null, true, 1, 0, Endian.LittleEndianLsb);
|
_modbusTcpMachine2 = new ModbusMachine<string, string>("2", "", ModbusType.Tcp, _machineIp, null, true, 1, 0, Endian.LittleEndianLsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Modbus.Net.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void GetUtility()
|
public void GetUtility()
|
||||||
{
|
{
|
||||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, _machineIp, null, true, 2, 0, Endian.BigEndianLsb);
|
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, "", ModbusType.Tcp, _machineIp, null, true, 2, 0, Endian.BigEndianLsb);
|
||||||
var utility = baseMachine.GetUtilityMethods<IUtilityMethodDatas>();
|
var utility = baseMachine.GetUtilityMethods<IUtilityMethodDatas>();
|
||||||
var methods = utility.GetType().GetRuntimeMethods();
|
var methods = utility.GetType().GetRuntimeMethods();
|
||||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "GetDatasAsync") != null, true);
|
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "GetDatasAsync") != null, true);
|
||||||
@@ -24,7 +24,7 @@ namespace Modbus.Net.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task InvokeUtility()
|
public async Task InvokeUtility()
|
||||||
{
|
{
|
||||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, _machineIp, null, true, 2, 0, Endian.BigEndianLsb);
|
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, "", ModbusType.Tcp, _machineIp, null, true, 2, 0, Endian.BigEndianLsb);
|
||||||
await baseMachine.BaseUtility.ConnectAsync();
|
await baseMachine.BaseUtility.ConnectAsync();
|
||||||
var success = await baseMachine.BaseUtility.GetUtilityMethods<IUtilityMethodDatas>().SetDatasAsync("4X 1", new object[] { (byte)11 }, 1);
|
var success = await baseMachine.BaseUtility.GetUtilityMethods<IUtilityMethodDatas>().SetDatasAsync("4X 1", new object[] { (byte)11 }, 1);
|
||||||
Assert.AreEqual(success.IsSuccess, true);
|
Assert.AreEqual(success.IsSuccess, true);
|
||||||
@@ -36,7 +36,7 @@ namespace Modbus.Net.Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task InvokeMachine()
|
public async Task InvokeMachine()
|
||||||
{
|
{
|
||||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, ModbusType.Tcp, _machineIp, new List<AddressUnit>
|
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(1, "",ModbusType.Tcp, _machineIp, new List<AddressUnit>
|
||||||
{
|
{
|
||||||
new AddressUnit
|
new AddressUnit
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ namespace Modbus.Net.Tests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
_modbusRtuMachine1 = new ModbusMachine<string, string>("1", ModbusType.Rtu, _machineCom, null, true, 1, 0, Endian.BigEndianLsb);
|
_modbusRtuMachine1 = new ModbusMachine<string, string>("1", "", ModbusType.Rtu, _machineCom, null, true, 1, 0, Endian.BigEndianLsb);
|
||||||
_modbusRtuMachine2 = new ModbusMachine<string, string>("2", ModbusType.Rtu, _machineCom, null, true, 2, 0, Endian.BigEndianLsb);
|
_modbusRtuMachine2 = new ModbusMachine<string, string>("2", "", ModbusType.Rtu, _machineCom, null, true, 2, 0, Endian.BigEndianLsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ namespace Modbus.Net.Tests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
_modbusTcpMachine = new ModbusMachine<string, string>("1", ModbusType.Tcp, _machineIp, null, true, 2, 0, Endian.BigEndianLsb);
|
_modbusTcpMachine = new ModbusMachine<string, string>("1", "", ModbusType.Tcp, _machineIp, null, true, 2, 0, Endian.BigEndianLsb);
|
||||||
|
|
||||||
_modbusRtuMachine = new ModbusMachine<string, string>("2", ModbusType.Rtu, _machineCom, null, true, 2, 0, Endian.BigEndianLsb);
|
_modbusRtuMachine = new ModbusMachine<string, string>("2", "", ModbusType.Rtu, _machineCom, null, true, 2, 0, Endian.BigEndianLsb);
|
||||||
|
|
||||||
_modbusAsciiMachine = new ModbusMachine<string, string>("3", ModbusType.Ascii, _machineCom2, null, true, 2, 0, Endian.BigEndianLsb);
|
_modbusAsciiMachine = new ModbusMachine<string, string>("3", "", ModbusType.Ascii, _machineCom2, null, true, 2, 0, Endian.BigEndianLsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ namespace Modbus.Net.Tests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
_siemensTcpMachine = new SiemensMachine<string, string>("1", SiemensType.Tcp, _machineIp, SiemensMachineModel.S7_1200, null, true, 2, 0);
|
_siemensTcpMachine = new SiemensMachine<string, string>("1", "", SiemensType.Tcp, _machineIp, SiemensMachineModel.S7_1200, null, true, 2, 0);
|
||||||
|
|
||||||
_siemensPpiMachine = new SiemensMachine<string, string>("2", SiemensType.Ppi, _machineCom, SiemensMachineModel.S7_200, null, true, 2, 0, 1, 0);
|
_siemensPpiMachine = new SiemensMachine<string, string>("2", "", SiemensType.Ppi, _machineCom, SiemensMachineModel.S7_200, null, true, 2, 0, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|||||||
Reference in New Issue
Block a user