2016-01-19 update 1 Add SetDatasAsync in BaseMachine and TaskManager
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using ModBus.Net;
|
||||
using System.Windows;
|
||||
using ModBus.Net.Modbus;
|
||||
using ModBus.Net.Siemens;
|
||||
|
||||
|
||||
@@ -14,6 +15,7 @@ namespace NA200H.UI.WPF
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private BaseUtility utility;
|
||||
private BaseMachine machine;
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -21,16 +23,44 @@ namespace NA200H.UI.WPF
|
||||
|
||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//utility = new ModbusUtility(ModbusType.Tcp, "192.168.3.247");
|
||||
//GetUtilityEnter();
|
||||
GetMachineEnter();
|
||||
}
|
||||
|
||||
private void GetUtilityEnter()
|
||||
{
|
||||
//utility = new ModbusUtility(ModbusType.Tcp, "192.168.3.12");
|
||||
//utility.AddressTranslator = new AddressTranslatorNA200H();
|
||||
//object[] getNum = utility.GetDatas(0x02, 0x00, "NW 1", new KeyValuePair<Type, int>(typeof(ushort), 4));
|
||||
utility = new SiemensUtility(SiemensType.Tcp, "192.168.3.191", SiemensMachineModel.S7_200);
|
||||
utility = new SiemensUtility(SiemensType.Tcp, "192.168.3.11", SiemensMachineModel.S7_300);
|
||||
utility.AddressTranslator = new AddressTranslatorSiemens();
|
||||
object[] getNum = utility.GetDatas(0x02, 0x00, "V 1", new KeyValuePair<Type, int>(typeof(ushort), 4));
|
||||
ushort[] getNumUshorts = BigEndianValueHelper.Instance.ObjectArrayToDestinationArray<ushort>(getNum);
|
||||
SetValue(getNumUshorts);
|
||||
}
|
||||
|
||||
private void GetMachineEnter()
|
||||
{
|
||||
//machine = new ModbusMachine(ModbusType.Tcp, "192.168.3.12", new List<AddressUnit>()
|
||||
//{
|
||||
//new AddressUnit() {Id = 1, Area = "NW", Address = 1, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||
//new AddressUnit() {Id = 2, Area = "NW", Address = 3, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||
//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.AddressTranslator = new AddressTranslatorNA200H();
|
||||
machine = new SiemensMachine(SiemensType.Tcp, "192.168.3.11", SiemensMachineModel.S7_300, new List<AddressUnit>()
|
||||
{
|
||||
new AddressUnit() {Id = 1, Area = "V", Address = 1, CommunicationTag = "Add1", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||
new AddressUnit() {Id = 2, Area = "V", Address = 3, CommunicationTag = "Add2", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||
new AddressUnit() {Id = 3, Area = "V", Address = 5, CommunicationTag = "Add3", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0},
|
||||
new AddressUnit() {Id = 4, Area = "V", Address = 7, CommunicationTag = "Ans", DataType = typeof(ushort), Zoom = 1, DecimalPos = 0}
|
||||
});
|
||||
var result = machine.GetDatas();
|
||||
var resultFormat = BaseMachine.MapGetValuesToSetValues(result);
|
||||
SetValue(new ushort[4] {(ushort)resultFormat["Add1"], (ushort)resultFormat["Add2"], (ushort)resultFormat["Add3"], (ushort)resultFormat["Ans"]});
|
||||
}
|
||||
|
||||
private void SetValue(ushort[] getNum)
|
||||
{
|
||||
Add1.Text = getNum[0].ToString();
|
||||
@@ -40,6 +70,12 @@ namespace NA200H.UI.WPF
|
||||
}
|
||||
|
||||
private void Calc_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//SetUtilityEnter();
|
||||
SetMachineEnter();
|
||||
}
|
||||
|
||||
private void SetUtilityEnter()
|
||||
{
|
||||
ushort add1 = 0, add2 = 0, add3 = 0;
|
||||
ushort.TryParse(Add1.Text, out add1);
|
||||
@@ -49,9 +85,18 @@ namespace NA200H.UI.WPF
|
||||
utility.SetDatas(0x02, 0x00, "V 1", new object[] { add1, add2, add3 });
|
||||
Thread.Sleep(100);
|
||||
//object[] getNum = utility.GetDatas(0x02, 0x00, "NW 1", new KeyValuePair<Type, int>(typeof(ushort), 4));
|
||||
object[] getNum = utility.GetDatas(0x02, 0x00, "V 1", new KeyValuePair<Type, int>(typeof(ushort), 4));
|
||||
ushort[] getNumUshorts = BigEndianValueHelper.Instance.ObjectArrayToDestinationArray<ushort>(getNum);
|
||||
SetValue(getNumUshorts);
|
||||
GetUtilityEnter();
|
||||
}
|
||||
|
||||
private void SetMachineEnter()
|
||||
{
|
||||
ushort add1 = 0, add2 = 0, add3 = 0;
|
||||
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);
|
||||
GetMachineEnter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user