mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Further implementation
- added new parsing method
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
using MewtocolNet.RegisterBuilding;
|
||||
using System.Collections.Generic;
|
||||
using MewtocolNet.Registers;
|
||||
|
||||
namespace Examples;
|
||||
|
||||
@@ -46,7 +47,7 @@ public class ExampleScenarios {
|
||||
while (interf.IsConnected) {
|
||||
|
||||
//flip the bool register each tick and wait for it to be registered
|
||||
await interf.SetRegisterAsync(nameof(registers.TestBool1), !registers.TestBool1);
|
||||
//await interf.SetRegisterAsync(nameof(registers.TestBool1), !registers.TestBool1);
|
||||
|
||||
Console.Title = $"Polling Paused: {interf.PollingPaused}, " +
|
||||
$"Poller active: {interf.PollerActive}, " +
|
||||
@@ -167,7 +168,7 @@ public class ExampleScenarios {
|
||||
await interf.ConnectAsync();
|
||||
|
||||
//use the async method to make sure the cycling is stopped
|
||||
await interf.SetRegisterAsync(nameof(registers.StartCyclePLC), false);
|
||||
//await interf.SetRegisterAsync(nameof(registers.StartCyclePLC), false);
|
||||
|
||||
await Task.Delay(5000);
|
||||
|
||||
@@ -182,4 +183,49 @@ public class ExampleScenarios {
|
||||
|
||||
}
|
||||
|
||||
[Scenario("Read register test")]
|
||||
public async Task RunReadTest () {
|
||||
|
||||
Console.WriteLine("Starting auto enums and bitwise");
|
||||
|
||||
//setting up a new PLC interface and register collection
|
||||
MewtocolInterface interf = new MewtocolInterface("192.168.115.210").WithPoller();
|
||||
|
||||
//auto add all built registers to the interface
|
||||
var builder = RegBuilder.ForInterface(interf);
|
||||
var r0reg = builder.FromPlcRegName("R0").Build();
|
||||
builder.FromPlcRegName("R1").Build();
|
||||
builder.FromPlcRegName("R1F").Build();
|
||||
builder.FromPlcRegName("R101A").Build();
|
||||
|
||||
var shortReg = builder.FromPlcRegName("DT35").AsPlcType(PlcVarType.INT).Build();
|
||||
builder.FromPlcRegName("DDT36").AsPlcType(PlcVarType.DINT).Build();
|
||||
|
||||
//builder.FromPlcRegName("DDT38").AsPlcType(PlcVarType.TIME).Build();
|
||||
//builder.FromPlcRegName("DT40").AsPlcType(PlcVarType.STRING).Build();
|
||||
|
||||
//connect
|
||||
await interf.ConnectAsync();
|
||||
|
||||
//var res = await interf.SendCommandAsync("%01#RCSR000F");
|
||||
|
||||
while(true) {
|
||||
|
||||
await interf.SetRegisterAsync(r0reg, !(bool)r0reg.Value);
|
||||
await interf.SetRegisterAsync(shortReg, (short)new Random().Next(0, 100));
|
||||
|
||||
foreach (var reg in interf.Registers) {
|
||||
|
||||
Console.WriteLine($"Register {reg.GetRegisterPLCName()} val: {reg.Value}");
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ class Program {
|
||||
|
||||
static void Main(string[] args) {
|
||||
|
||||
RegBuilder.FromPlcRegName("DT303").AsPlcType(PlcVarType.INT).Build();
|
||||
var res = RegBuilder.FromPlcRegName("DT100").AsPlcType(PlcVarType.INT).Build();
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += (s,e) => {
|
||||
Console.WriteLine(e.ExceptionObject.ToString());
|
||||
};
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace Examples {
|
||||
public BitArray TestBitRegister { get; private set; }
|
||||
|
||||
//corresponds to a DT1204 as a 16bit word/int takes the bit at index 9 and writes it back as a boolean
|
||||
[Register(1204, 9, BitCount.B16)]
|
||||
[Register(1204, BitCount.B16, 9)]
|
||||
public bool BitValue { get; private set; }
|
||||
|
||||
[Register(1204, 5, BitCount.B16)]
|
||||
[Register(1204, BitCount.B16, 5)]
|
||||
public bool FillTest { get; private set; }
|
||||
|
||||
//corresponds to a DT7012 - DT7013 as a 32bit time value that gets parsed as a timespan (TIME)
|
||||
|
||||
@@ -53,52 +53,52 @@ namespace Examples {
|
||||
|
||||
//you can also extract single bits from DT503
|
||||
|
||||
[Register(503, 0, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 0)]
|
||||
public bool BitValue0 { get; private set; }
|
||||
|
||||
[Register(503, 1, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 1)]
|
||||
public bool BitValue1 { get; private set; }
|
||||
|
||||
[Register(503, 2, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 2)]
|
||||
public bool BitValue2 { get; private set; }
|
||||
|
||||
[Register(503, 3, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 3)]
|
||||
public bool BitValue3 { get; private set; }
|
||||
|
||||
[Register(503, 4, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 4)]
|
||||
public bool BitValue4 { get; private set; }
|
||||
|
||||
[Register(503, 5, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 5)]
|
||||
public bool BitValue5 { get; private set; }
|
||||
|
||||
[Register(503, 6, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 6)]
|
||||
public bool BitValue6 { get; private set; }
|
||||
|
||||
[Register(503, 7, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 7)]
|
||||
public bool BitValue7 { get; private set; }
|
||||
|
||||
[Register(503, 8, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 8)]
|
||||
public bool BitValue8 { get; private set; }
|
||||
|
||||
[Register(503, 9, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 9)]
|
||||
public bool BitValue9 { get; private set; }
|
||||
|
||||
[Register(503, 10, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 10)]
|
||||
public bool BitValue10 { get; private set; }
|
||||
|
||||
[Register(503, 11, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 11)]
|
||||
public bool BitValue11 { get; private set; }
|
||||
|
||||
[Register(503, 12, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 12)]
|
||||
public bool BitValue12 { get; private set; }
|
||||
|
||||
[Register(503, 13, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 13)]
|
||||
public bool BitValue13 { get; private set; }
|
||||
|
||||
[Register(503, 14, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 14)]
|
||||
public bool BitValue14 { get; private set; }
|
||||
|
||||
[Register(503, 15, BitCount.B16)]
|
||||
[Register(503, BitCount.B16, 15)]
|
||||
public bool BitValue15 { get; private set; }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user