2016-01-20 update 1 change SetDatasAsync code
This commit is contained in:
@@ -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<object> datasList = new List<object>();
|
||||
@@ -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)
|
||||
|
||||
@@ -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<AddressUnit>()
|
||||
{
|
||||
@@ -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<string, double>{{"V 1", add1}, {"V 3", add2}, {"V 5", add3}};
|
||||
machine.SetDatas(MachineSetDataType.Address, setDic);
|
||||
var setDic = new Dictionary<string, double> {{"Add1", add1}, {"Add2", add2}, {"Add3", add3}};
|
||||
machine.SetDatas(MachineSetDataType.CommunicationTag, setDic);
|
||||
//var setDic = new Dictionary<string, double>{{"V 1", add1}, {"V 3", add2}, {"V 5", add3}};
|
||||
//machine.SetDatas(MachineSetDataType.Address, setDic);
|
||||
GetMachineEnter();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user