From da984338e353bbd35fe298ec6ec6b6b12d1a5500 Mon Sep 17 00:00:00 2001 From: "parallelbgls@outlook.com" Date: Wed, 20 Jan 2016 09:53:48 +0800 Subject: [PATCH] 2016-01-20 update 1 change SetDatasAsync code --- Modbus.Net/ModBus.Net/BaseMachine.cs | 15 +++++++-------- Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs | 7 +++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Modbus.Net/ModBus.Net/BaseMachine.cs b/Modbus.Net/ModBus.Net/BaseMachine.cs index 1b3941a..cd10049 100644 --- a/Modbus.Net/ModBus.Net/BaseMachine.cs +++ b/Modbus.Net/ModBus.Net/BaseMachine.cs @@ -166,7 +166,7 @@ namespace ModBus.Net if (address == null) return false; addresses.Add(address); } - var communcationUnits = AddressCombiner.Combine(addresses); + var communcationUnits = new AddressCombinerContinus().Combine(addresses); foreach (var communicateAddress in communcationUnits) { List datasList = new List(); @@ -175,7 +175,8 @@ namespace ModBus.Net BigEndianValueHelper.Instance.ByteLength[ communicateAddress.DataType.FullName]); var allBytes = setCount; - + var addressStart = AddressFormater.FormatAddress(communicateAddress.Area, + communicateAddress.Address); while (setCount > 0) { var address = AddressFormater.FormatAddress(communicateAddress.Area, @@ -191,22 +192,20 @@ namespace ModBus.Net case MachineSetDataType.Address: { var value = values.SingleOrDefault(p => p.Key == address); - await - BaseUtility.SetDatasAsync(2, 0, address, - new object[] {Convert.ChangeType(value.Value, dataType)}); + datasList.Add(Convert.ChangeType(value.Value, dataType)); break; } case MachineSetDataType.CommunicationTag: { var value = values.SingleOrDefault(p => p.Key == addressUnit.CommunicationTag); - await - BaseUtility.SetDatasAsync(2, 0, address, - new object[] {Convert.ChangeType(value.Value, dataType)}); + datasList.Add(Convert.ChangeType(value.Value, dataType)); break; } } setCount -= (int) BigEndianValueHelper.Instance.ByteLength[dataType.FullName]; } + + await BaseUtility.SetDatasAsync(2, 0, addressStart, datasList.ToArray()); } } catch (Exception e) diff --git a/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs b/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs index a6f1a51..187bd03 100644 --- a/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs +++ b/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs @@ -48,6 +48,7 @@ namespace NA200H.UI.WPF //new AddressUnit() {Id = 3, Area = "NW", Address = 5, CommunicationTag = "Add3", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0}, //new AddressUnit() {Id = 4, Area = "NW", Address = 7, CommunicationTag = "Ans", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0} //}); + //machine.AddressFormater = new AddressFormaterNA200H(); //machine.AddressTranslator = new AddressTranslatorNA200H(); machine = new SiemensMachine(SiemensType.Tcp, "192.168.3.11", SiemensMachineModel.S7_300, new List() { @@ -94,8 +95,10 @@ namespace NA200H.UI.WPF ushort.TryParse(Add1.Text, out add1); ushort.TryParse(Add2.Text, out add2); ushort.TryParse(Add3.Text, out add3); - var setDic = new Dictionary{{"V 1", add1}, {"V 3", add2}, {"V 5", add3}}; - machine.SetDatas(MachineSetDataType.Address, setDic); + var setDic = new Dictionary {{"Add1", add1}, {"Add2", add2}, {"Add3", add3}}; + machine.SetDatas(MachineSetDataType.CommunicationTag, setDic); + //var setDic = new Dictionary{{"V 1", add1}, {"V 3", add2}, {"V 5", add3}}; + //machine.SetDatas(MachineSetDataType.Address, setDic); GetMachineEnter(); } }