2014-10-08 update 1
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using ModBus.Net;
|
||||
using System.Windows;
|
||||
|
||||
@@ -18,9 +20,13 @@ namespace NA200H.UI.WPF
|
||||
|
||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
utility = new ModbusUtility((int)ModbusType.Rtu);
|
||||
ushort[] getNum = utility.GetRegisters(0x02, "0", 4);
|
||||
SetValue(getNum);
|
||||
utility = new ModbusUtility((int) ModbusType.Tcp, "192.168.3.247");
|
||||
byte[] getNum = utility.GetDatas(0x02, (byte) ModbusProtocalReadDataFunctionCode.ReadHoldRegister, "10000", 4);
|
||||
object[] getNumObjects =
|
||||
ValueHelper.Instance.ByteArrayToObjectArray(getNum,
|
||||
new List<KeyValuePair<Type, int>>(){{new KeyValuePair<Type, int>(typeof(ushort), 4)}});
|
||||
ushort[] getNumUshorts = ValueHelper.Instance.ObjectArrayToDestinationArray<ushort>(getNumObjects);
|
||||
SetValue(getNumUshorts);
|
||||
}
|
||||
|
||||
private void SetValue(ushort[] getNum)
|
||||
@@ -37,9 +43,14 @@ namespace NA200H.UI.WPF
|
||||
ushort.TryParse(Add1.Text, out add1);
|
||||
ushort.TryParse(Add2.Text, out add2);
|
||||
ushort.TryParse(Add3.Text, out add3);
|
||||
utility.SetRegisters(0x02, "0", new object[] {add1, add2, add3});
|
||||
ushort[] getNum = utility.GetRegisters(0x02, "0", 4);
|
||||
SetValue(getNum);
|
||||
utility.SetDatas(0x02, (byte)ModbusProtocalWriteDataFunctionCode.WriteMultiRegister, "10000", new object[] {add1, add2, add3});
|
||||
Thread.Sleep(100);
|
||||
byte[] getNum = utility.GetDatas(0x02, (byte)ModbusProtocalReadDataFunctionCode.ReadHoldRegister, "10000", 4);
|
||||
object[] getNumObjects =
|
||||
ValueHelper.Instance.ByteArrayToObjectArray(getNum,
|
||||
new List<KeyValuePair<Type, int>>() { { new KeyValuePair<Type, int>(typeof(ushort), 4) } });
|
||||
ushort[] getNumUshorts = ValueHelper.Instance.ObjectArrayToDestinationArray<ushort>(getNumObjects);
|
||||
SetValue(getNumUshorts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user