diff --git a/Modbus.Net/Modbus.Net.Modbus/Modbus.Net.Modbus.nuspec b/Modbus.Net/Modbus.Net.Modbus/Modbus.Net.Modbus.nuspec index 4abb43c..2e07d65 100644 --- a/Modbus.Net/Modbus.Net.Modbus/Modbus.Net.Modbus.nuspec +++ b/Modbus.Net/Modbus.Net.Modbus/Modbus.Net.Modbus.nuspec @@ -2,7 +2,7 @@ Modbus.Net.Modbus - 1.2.3.2 + 1.2.4 Modbus.Net.Modbus Chris L.(Luo Sheng) Hangzhou Delian IoT Science Technology Co.,Ltd. @@ -13,7 +13,7 @@ Copyright 2017 Hangzhou Delian IoT Science Technology Co.,Ltd. hardware communicate protocal modbus Delian - + diff --git a/Modbus.Net/Modbus.Net.Modbus/Properties/AssemblyInfo.cs b/Modbus.Net/Modbus.Net.Modbus/Properties/AssemblyInfo.cs index ec13ce6..09ecdc4 100644 --- a/Modbus.Net/Modbus.Net.Modbus/Properties/AssemblyInfo.cs +++ b/Modbus.Net/Modbus.Net.Modbus/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.3")] -[assembly: AssemblyFileVersion("1.2.3")] +[assembly: AssemblyVersion("1.2.4")] +[assembly: AssemblyFileVersion("1.2.4")] diff --git a/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.nuspec b/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.nuspec index e8e8965..27bd364 100644 --- a/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.nuspec +++ b/Modbus.Net/Modbus.Net.OPC/Modbus.Net.OPC.nuspec @@ -13,7 +13,7 @@ Copyright 2017 Hangzhou Delian IoT Science Technology Co.,Ltd. hardware communicate protocal OPC DA Delian - + diff --git a/Modbus.Net/Modbus.Net.Siemens/Modbus.Net.Siemens.nuspec b/Modbus.Net/Modbus.Net.Siemens/Modbus.Net.Siemens.nuspec index 82af50d..1be25ce 100644 --- a/Modbus.Net/Modbus.Net.Siemens/Modbus.Net.Siemens.nuspec +++ b/Modbus.Net/Modbus.Net.Siemens/Modbus.Net.Siemens.nuspec @@ -2,7 +2,7 @@ Modbus.Net.Siemens - 1.2.3 + 1.2.4 Modbus.Net.Siemens Chris L.(Luo Sheng) Hangzhou Delian IoT Science Technology Co.,Ltd. @@ -13,7 +13,7 @@ Copyright 2017 Hangzhou Delian IoT Science Technology Co.,Ltd. hardware communicate protocal Siemens profinet Delian - + diff --git a/Modbus.Net/Modbus.Net.Siemens/Properties/AssemblyInfo.cs b/Modbus.Net/Modbus.Net.Siemens/Properties/AssemblyInfo.cs index 7c69fed..0313934 100644 --- a/Modbus.Net/Modbus.Net.Siemens/Properties/AssemblyInfo.cs +++ b/Modbus.Net/Modbus.Net.Siemens/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.3")] -[assembly: AssemblyFileVersion("1.2.3")] +[assembly: AssemblyVersion("1.2.4")] +[assembly: AssemblyFileVersion("1.2.4")] diff --git a/Modbus.Net/Modbus.Net/BaseUtility.cs b/Modbus.Net/Modbus.Net/BaseUtility.cs index ee2b9f9..fc26997 100644 --- a/Modbus.Net/Modbus.Net/BaseUtility.cs +++ b/Modbus.Net/Modbus.Net/BaseUtility.cs @@ -52,7 +52,7 @@ namespace Modbus.Net /// /// 标识设备的连接关键字 /// - public string ConnectionToken => Wrapper.ProtocalLinker.ConnectionToken; + public string ConnectionToken => Wrapper?.ProtocalLinker == null ? ConnectionString : Wrapper.ProtocalLinker.ConnectionToken; /// /// 地址翻译器 diff --git a/Modbus.Net/Modbus.Net/ModBus.Net.nuspec b/Modbus.Net/Modbus.Net/ModBus.Net.nuspec index a66ad0c..e2680e0 100644 --- a/Modbus.Net/Modbus.Net/ModBus.Net.nuspec +++ b/Modbus.Net/Modbus.Net/ModBus.Net.nuspec @@ -2,7 +2,7 @@ Modbus.Net - 1.2.3.2 + 1.2.4 Modbus.Net Chris L.(Luo Sheng) Hangzhou Delian IoT Science Technology Co.,Ltd. diff --git a/Modbus.Net/Modbus.Net/Properties/AssemblyInfo.cs b/Modbus.Net/Modbus.Net/Properties/AssemblyInfo.cs index f30fc33..9096ba7 100644 --- a/Modbus.Net/Modbus.Net/Properties/AssemblyInfo.cs +++ b/Modbus.Net/Modbus.Net/Properties/AssemblyInfo.cs @@ -35,5 +35,5 @@ using System.Runtime.InteropServices; // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.3")] -[assembly: AssemblyFileVersion("1.2.3")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.4")] +[assembly: AssemblyFileVersion("1.2.4")] \ No newline at end of file diff --git a/Tests/Modbus.Net.Tests/BaseTest.cs b/Tests/Modbus.Net.Tests/BaseTest.cs index f09620f..45f9b1a 100644 --- a/Tests/Modbus.Net.Tests/BaseTest.cs +++ b/Tests/Modbus.Net.Tests/BaseTest.cs @@ -1,120 +1,157 @@ -using Modbus.Net; -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Modbus.Net.Modbus; +using Modbus.Net.Siemens; namespace Modbus.Net.Tests { [TestClass] public class BaseTest { - private List _addressUnits; + private List> _addressUnits; + + private TaskManager _taskManager; + + private BaseMachine _baseMachine; + + private BaseMachine _baseMachine2; [TestInitialize] public void Init() { - _addressUnits = new List + _addressUnits = new List> { - new AddressUnit + new AddressUnit { + Id = 1, Area = "3X", Address = 1, SubAddress = 0, DataType = typeof(bool) }, - new AddressUnit + new AddressUnit { + Id = 2, Area = "3X", Address = 1, SubAddress = 1, DataType = typeof(bool) }, - new AddressUnit + new AddressUnit { + Id = 3, Area = "3X", Address = 1, SubAddress = 2, DataType = typeof(bool) }, - new AddressUnit + new AddressUnit { + Id = 4, Area = "3X", Address = 2, SubAddress = 0, DataType = typeof(byte) }, - new AddressUnit + new AddressUnit { + Id = 5, Area = "3X", Address = 2, SubAddress = 8, DataType = typeof(byte) }, - new AddressUnit + new AddressUnit { + Id = 6, Area = "3X", Address = 3, SubAddress = 0, DataType = typeof(ushort) }, - new AddressUnit + new AddressUnit { + Id = 7, Area = "3X", Address = 4, SubAddress = 0, DataType = typeof(ushort) }, - new AddressUnit + new AddressUnit { + Id = 8, Area = "3X", Address = 6, SubAddress = 0, DataType = typeof(ushort) }, - new AddressUnit + new AddressUnit { + Id = 9, Area = "3X", Address = 9, SubAddress = 0, DataType = typeof(ushort) }, - new AddressUnit + new AddressUnit { + Id = 10, Area = "3X", Address = 10, SubAddress = 0, DataType = typeof(ushort) }, - new AddressUnit + new AddressUnit { + Id = 11, Area = "3X", Address = 100, SubAddress = 0, DataType = typeof(ushort) }, - new AddressUnit + new AddressUnit { + Id = 12, Area = "4X", Address = 1, SubAddress = 0, DataType = typeof(uint) }, - new AddressUnit + new AddressUnit { + Id = 13, Area = "4X", Address = 4, SubAddress = 0, DataType = typeof(ushort) }, }; + + _baseMachine = new ModbusMachine(ModbusType.Tcp, "192.168.1.1", _addressUnits, true, 2, 0) + { + Id = 1, + ProjectName = "Project 1", + MachineName = "Test 1" + }; + _baseMachine2 = new SiemensMachine(SiemensType.Tcp, "192.168.1.2", SiemensMachineModel.S7_300, _addressUnits, true, 2, 0) + { + Id = 2, + ProjectName = "Project 1", + MachineName = "Test 2" + }; + + _taskManager = new TaskManager(10, 3000, true); + + _taskManager.AddMachine(_baseMachine); + _taskManager.AddMachine(_baseMachine2); } [TestMethod] public void AddressCombinerContinusTest() { - var addressCombiner = new AddressCombinerContinus(new AddressTranslatorModbus()); + var addressCombiner = new AddressCombinerContinus(new AddressTranslatorModbus()); var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Address, 1); @@ -142,7 +179,7 @@ namespace Modbus.Net.Tests [TestMethod] public void AddressCombinerSingleTest() { - var addressCombiner = new AddressCombinerSingle(); + var addressCombiner = new AddressCombinerSingle(); var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Address, 1); @@ -166,7 +203,7 @@ namespace Modbus.Net.Tests [TestMethod] public void AddressCombinerNumericJumpTest() { - var addressCombiner = new AddressCombinerNumericJump(10, new AddressTranslatorModbus()); + var addressCombiner = new AddressCombinerNumericJump(10, new AddressTranslatorModbus()); var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Address, 1); @@ -182,7 +219,7 @@ namespace Modbus.Net.Tests [TestMethod] public void AddressCombinerPercentageJumpTest() { - var addressCombiner = new AddressCombinerPercentageJump(30.0, new AddressTranslatorModbus()); + var addressCombiner = new AddressCombinerPercentageJump(30.0, new AddressTranslatorModbus()); var combinedAddresses = addressCombiner.Combine(_addressUnits).ToArray(); Assert.AreEqual(combinedAddresses[0].Area, "3X"); Assert.AreEqual(combinedAddresses[0].Address, 1); @@ -197,5 +234,23 @@ namespace Modbus.Net.Tests Assert.AreEqual(combinedAddresses[3].Address, 1); Assert.AreEqual(combinedAddresses[3].GetCount, 8); } + + [TestMethod] + public void TaskManagerGetMachineTest() + { + var machine = _taskManager.GetMachineById(1); + Assert.AreEqual(machine.MachineName, "Test 1"); + + var machine2 = _taskManager.GetMachineByConnectionToken("192.168.1.2"); + Assert.AreEqual(machine2.MachineName, "Test 2"); + } + + [TestMethod] + public void BaseMachineGetAddressTest() + { + var addressUnit = _baseMachine.GetAddressUnitById(1); + Assert.AreEqual(addressUnit.Area, "3X"); + Assert.AreEqual(addressUnit.Address, 1); + } } }