mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 11:11:23 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea106416ee | ||
|
|
0afa146712 | ||
|
|
325aa56d8a | ||
|
|
f4fad297fb | ||
|
|
664b32b92e | ||
|
|
a639a8eda8 | ||
|
|
23c2b0efb4 | ||
|
|
eed19f84d7 | ||
|
|
da90a45e15 | ||
|
|
614426207c | ||
|
|
3aa8aa227c | ||
|
|
26c0e9add0 | ||
|
|
4a63fb10bd | ||
|
|
881253130b | ||
|
|
3a5cdb11c2 |
23
.github/workflows/dotnet-windows.yml
vendored
Normal file
23
.github/workflows/dotnet-windows.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: .NET Windows
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: windows-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
dotnet-version: [ '3.0', '3.1.x', '5.0.x' ]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup dotnet ${{ matrix.dotnet-version }}
|
||||||
|
uses: actions/setup-dotnet@v2
|
||||||
|
with:
|
||||||
|
dotnet-version: ${{ matrix.dotnet-version }}
|
||||||
|
# You can test your matrix by printing the current dotnet version
|
||||||
|
- name: Display dotnet version
|
||||||
|
run: dotnet --version
|
||||||
@@ -33,6 +33,9 @@ namespace Examples {
|
|||||||
//writing a value to the registers
|
//writing a value to the registers
|
||||||
Task.Factory.StartNew(async () => {
|
Task.Factory.StartNew(async () => {
|
||||||
|
|
||||||
|
//set plc to run mode if not already
|
||||||
|
await interf.SetOperationMode(OPMode.Run);
|
||||||
|
|
||||||
await Task.Delay(2000);
|
await Task.Delay(2000);
|
||||||
|
|
||||||
//inverts the boolean register
|
//inverts the boolean register
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ namespace Examples {
|
|||||||
//corresponds to a DT7012 - DT7013 as a 32bit time value that gets parsed as a timespan (TIME)
|
//corresponds to a DT7012 - DT7013 as a 32bit time value that gets parsed as a timespan (TIME)
|
||||||
//the smallest value to communicate to the PLC is 10ms
|
//the smallest value to communicate to the PLC is 10ms
|
||||||
[Register(7012)]
|
[Register(7012)]
|
||||||
public TimeSpan TestTime { get; private set; }
|
public TimeSpan TestTime { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet.Registers {
|
||||||
public class CpuInfo {
|
public partial class CpuInfo {
|
||||||
/// <summary>
|
|
||||||
/// CPU type of the PLC
|
|
||||||
/// </summary>
|
|
||||||
public enum CpuType {
|
|
||||||
/// <summary>
|
|
||||||
/// FP 0 / FP 2.7K
|
|
||||||
/// </summary>
|
|
||||||
FP0_FP1_2_7K,
|
|
||||||
/// <summary>
|
|
||||||
/// FP0 / FP1, 5K / 10K
|
|
||||||
/// </summary>
|
|
||||||
FP0_FP1_5K_10K,
|
|
||||||
/// <summary>
|
|
||||||
/// FP1 M 0.9K
|
|
||||||
/// </summary>
|
|
||||||
FP1_M_0_9K,
|
|
||||||
/// <summary>
|
|
||||||
/// FP2 16k / 32k
|
|
||||||
/// </summary>
|
|
||||||
FP2_16K_32K,
|
|
||||||
/// <summary>
|
|
||||||
/// FP3 C 10K
|
|
||||||
/// </summary>
|
|
||||||
FP3_C_10K,
|
|
||||||
/// <summary>
|
|
||||||
/// FP3 C 16K
|
|
||||||
/// </summary>
|
|
||||||
FP3_C_16K,
|
|
||||||
/// <summary>
|
|
||||||
/// FP5 16K
|
|
||||||
/// </summary>
|
|
||||||
FP5_16K,
|
|
||||||
/// <summary>
|
|
||||||
/// FP 5 24K
|
|
||||||
/// </summary>
|
|
||||||
FP5_24K,
|
|
||||||
/// <summary>
|
|
||||||
/// Includes panasonic FPX, FPX-H, Sigma
|
|
||||||
/// </summary>
|
|
||||||
FP_Sigma_X_H_30K_60K_120K
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public CpuType Cputype { get; set; }
|
public CpuType Cputype { get; set; }
|
||||||
public int ProgramCapacity { get; set; }
|
public int ProgramCapacity { get; set; }
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace MewtocolNet {
|
|||||||
internal void KillPoller () {
|
internal void KillPoller () {
|
||||||
|
|
||||||
ContinousReaderRunning = false;
|
ContinousReaderRunning = false;
|
||||||
cTokenAutoUpdater.Cancel();
|
cTokenAutoUpdater?.Cancel();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +71,8 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
ContinousReaderRunning = true;
|
ContinousReaderRunning = true;
|
||||||
|
|
||||||
|
int getPLCinfoCycleCount = 0;
|
||||||
|
|
||||||
while (ContinousReaderRunning) {
|
while (ContinousReaderRunning) {
|
||||||
|
|
||||||
//do priority tasks first
|
//do priority tasks first
|
||||||
@@ -78,6 +80,11 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
await PriorityTasks.FirstOrDefault(x => !x.IsCompleted);
|
await PriorityTasks.FirstOrDefault(x => !x.IsCompleted);
|
||||||
|
|
||||||
|
} else if (getPLCinfoCycleCount > 25) {
|
||||||
|
|
||||||
|
await GetPLCInfoAsync();
|
||||||
|
getPLCinfoCycleCount = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var registerPair in Registers) {
|
foreach (var registerPair in Registers) {
|
||||||
@@ -86,7 +93,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
if (reg is NRegister<short> shortReg) {
|
if (reg is NRegister<short> shortReg) {
|
||||||
var lastVal = shortReg.Value;
|
var lastVal = shortReg.Value;
|
||||||
var readout = (await ReadNumRegister(shortReg, stationNumber)).Register.Value;
|
var readout = (await ReadNumRegister(shortReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
shortReg.LastValue = readout;
|
shortReg.LastValue = readout;
|
||||||
InvokeRegisterChanged(shortReg);
|
InvokeRegisterChanged(shortReg);
|
||||||
@@ -95,7 +102,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
if (reg is NRegister<ushort> ushortReg) {
|
if (reg is NRegister<ushort> ushortReg) {
|
||||||
var lastVal = ushortReg.Value;
|
var lastVal = ushortReg.Value;
|
||||||
var readout = (await ReadNumRegister(ushortReg, stationNumber)).Register.Value;
|
var readout = (await ReadNumRegister(ushortReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
ushortReg.LastValue = readout;
|
ushortReg.LastValue = readout;
|
||||||
InvokeRegisterChanged(ushortReg);
|
InvokeRegisterChanged(ushortReg);
|
||||||
@@ -104,7 +111,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
if (reg is NRegister<int> intReg) {
|
if (reg is NRegister<int> intReg) {
|
||||||
var lastVal = intReg.Value;
|
var lastVal = intReg.Value;
|
||||||
var readout = (await ReadNumRegister(intReg, stationNumber)).Register.Value;
|
var readout = (await ReadNumRegister(intReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
intReg.LastValue = readout;
|
intReg.LastValue = readout;
|
||||||
InvokeRegisterChanged(intReg);
|
InvokeRegisterChanged(intReg);
|
||||||
@@ -113,7 +120,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
if (reg is NRegister<uint> uintReg) {
|
if (reg is NRegister<uint> uintReg) {
|
||||||
var lastVal = uintReg.Value;
|
var lastVal = uintReg.Value;
|
||||||
var readout = (await ReadNumRegister(uintReg, stationNumber)).Register.Value;
|
var readout = (await ReadNumRegister(uintReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
uintReg.LastValue = readout;
|
uintReg.LastValue = readout;
|
||||||
InvokeRegisterChanged(uintReg);
|
InvokeRegisterChanged(uintReg);
|
||||||
@@ -122,7 +129,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
if (reg is NRegister<float> floatReg) {
|
if (reg is NRegister<float> floatReg) {
|
||||||
var lastVal = floatReg.Value;
|
var lastVal = floatReg.Value;
|
||||||
var readout = (await ReadNumRegister(floatReg, stationNumber)).Register.Value;
|
var readout = (await ReadNumRegister(floatReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
floatReg.LastValue = readout;
|
floatReg.LastValue = readout;
|
||||||
InvokeRegisterChanged(floatReg);
|
InvokeRegisterChanged(floatReg);
|
||||||
@@ -131,7 +138,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
if (reg is NRegister<TimeSpan> tsReg) {
|
if (reg is NRegister<TimeSpan> tsReg) {
|
||||||
var lastVal = tsReg.Value;
|
var lastVal = tsReg.Value;
|
||||||
var readout = (await ReadNumRegister(tsReg, stationNumber)).Register.Value;
|
var readout = (await ReadNumRegister(tsReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
tsReg.LastValue = readout;
|
tsReg.LastValue = readout;
|
||||||
InvokeRegisterChanged(tsReg);
|
InvokeRegisterChanged(tsReg);
|
||||||
@@ -140,7 +147,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
if (reg is BRegister boolReg) {
|
if (reg is BRegister boolReg) {
|
||||||
var lastVal = boolReg.Value;
|
var lastVal = boolReg.Value;
|
||||||
var readout = (await ReadBoolRegister(boolReg, stationNumber)).Register.Value;
|
var readout = (await ReadBoolRegister(boolReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
boolReg.LastValue = readout;
|
boolReg.LastValue = readout;
|
||||||
InvokeRegisterChanged(boolReg);
|
InvokeRegisterChanged(boolReg);
|
||||||
@@ -149,7 +156,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
if (reg is SRegister stringReg) {
|
if (reg is SRegister stringReg) {
|
||||||
var lastVal = stringReg.Value;
|
var lastVal = stringReg.Value;
|
||||||
var readout = (await ReadStringRegister(stringReg, stationNumber)).Register.Value;
|
var readout = (await ReadStringRegister(stringReg)).Register.Value;
|
||||||
if (lastVal != readout) {
|
if (lastVal != readout) {
|
||||||
InvokeRegisterChanged(stringReg);
|
InvokeRegisterChanged(stringReg);
|
||||||
stringReg.TriggerNotifyChange();
|
stringReg.TriggerNotifyChange();
|
||||||
@@ -159,6 +166,8 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPLCinfoCycleCount++;
|
||||||
|
|
||||||
//invoke cycle polled event
|
//invoke cycle polled event
|
||||||
InvokePolledCycleDone();
|
InvokePolledCycleDone();
|
||||||
|
|
||||||
|
|||||||
@@ -159,19 +159,42 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
internal static byte[] HexStringToByteArray(this string hex) {
|
internal static byte[] HexStringToByteArray(this string hex) {
|
||||||
return Enumerable.Range(0, hex.Length)
|
return Enumerable.Range(0, hex.Length)
|
||||||
.Where(x => x % 2 == 0)
|
.Where(x => x % 2 == 0)
|
||||||
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
|
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ToHexString (this byte[] arr) {
|
internal static string ToHexString (this byte[] arr) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
foreach (var b in arr) {
|
for (int i = 0; i < arr.Length; i++) {
|
||||||
|
byte b = arr[i];
|
||||||
sb.Append(b.ToString("X2"));
|
sb.Append(b.ToString("X2"));
|
||||||
}
|
}
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static byte[] BigToMixedEndian (this byte[] arr) {
|
||||||
|
|
||||||
|
List<byte> oldBL = new List<byte>(arr);
|
||||||
|
|
||||||
|
List<byte> tempL = new List<byte>();
|
||||||
|
|
||||||
|
//make the input list even
|
||||||
|
if(arr.Length % 2 != 0)
|
||||||
|
oldBL.Add((byte)0);
|
||||||
|
|
||||||
|
for (int i = 0; i < oldBL.Count; i+=2) {
|
||||||
|
byte firstByte = oldBL[i];
|
||||||
|
byte lastByte = oldBL[i + 1];
|
||||||
|
tempL.Add(lastByte);
|
||||||
|
tempL.Add(firstByte);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return tempL.ToArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -115,6 +115,8 @@ namespace MewtocolNet {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<MewtocolInterface> ConnectAsync (Action<PLCInfo> OnConnected = null, Action OnFailed = null) {
|
public async Task<MewtocolInterface> ConnectAsync (Action<PLCInfo> OnConnected = null, Action OnFailed = null) {
|
||||||
|
|
||||||
|
Logger.Log("Connecting to PLC...", LogLevel.Info, this);
|
||||||
|
|
||||||
var plcinf = await GetPLCInfoAsync();
|
var plcinf = await GetPLCInfoAsync();
|
||||||
|
|
||||||
if (plcinf != null) {
|
if (plcinf != null) {
|
||||||
@@ -354,6 +356,14 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (collection != null)
|
||||||
|
collection.OnInterfaceLinked(this);
|
||||||
|
|
||||||
|
Connected += (i) => {
|
||||||
|
if(collection != null)
|
||||||
|
collection.OnInterfaceLinkedAndOnline(this);
|
||||||
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -394,49 +404,49 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
if (foundRegister.GetType() == typeof(BRegister)) {
|
if (foundRegister.GetType() == typeof(BRegister)) {
|
||||||
|
|
||||||
return await WriteBoolRegister((BRegister)foundRegister, (bool)value, StationNumber);
|
return await WriteBoolRegister((BRegister)foundRegister, (bool)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundRegister.GetType() == typeof(NRegister<short>)) {
|
if (foundRegister.GetType() == typeof(NRegister<short>)) {
|
||||||
|
|
||||||
return await WriteNumRegister((NRegister<short>)foundRegister, (short)value, StationNumber);
|
return await WriteNumRegister((NRegister<short>)foundRegister, (short)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundRegister.GetType() == typeof(NRegister<ushort>)) {
|
if (foundRegister.GetType() == typeof(NRegister<ushort>)) {
|
||||||
|
|
||||||
return await WriteNumRegister((NRegister<ushort>)foundRegister, (ushort)value, StationNumber);
|
return await WriteNumRegister((NRegister<ushort>)foundRegister, (ushort)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundRegister.GetType() == typeof(NRegister<int>)) {
|
if (foundRegister.GetType() == typeof(NRegister<int>)) {
|
||||||
|
|
||||||
return await WriteNumRegister((NRegister<int>)foundRegister, (int)value, StationNumber);
|
return await WriteNumRegister((NRegister<int>)foundRegister, (int)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundRegister.GetType() == typeof(NRegister<uint>)) {
|
if (foundRegister.GetType() == typeof(NRegister<uint>)) {
|
||||||
|
|
||||||
return await WriteNumRegister((NRegister<uint>)foundRegister, (uint)value, StationNumber);
|
return await WriteNumRegister((NRegister<uint>)foundRegister, (uint)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundRegister.GetType() == typeof(NRegister<float>)) {
|
if (foundRegister.GetType() == typeof(NRegister<float>)) {
|
||||||
|
|
||||||
return await WriteNumRegister((NRegister<float>)foundRegister, (float)value, StationNumber);
|
return await WriteNumRegister((NRegister<float>)foundRegister, (float)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundRegister.GetType() == typeof(NRegister<TimeSpan>)) {
|
if (foundRegister.GetType() == typeof(NRegister<TimeSpan>)) {
|
||||||
|
|
||||||
return await WriteNumRegister((NRegister<TimeSpan>)foundRegister, (TimeSpan)value, StationNumber);
|
return await WriteNumRegister((NRegister<TimeSpan>)foundRegister, (TimeSpan)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundRegister.GetType() == typeof(SRegister)) {
|
if (foundRegister.GetType() == typeof(SRegister)) {
|
||||||
|
|
||||||
return await WriteStringRegister((SRegister)foundRegister, (string)value, StationNumber);
|
return await WriteStringRegister((SRegister)foundRegister, (string)value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using MewtocolNet.Registers;
|
using MewtocolNet.Registers;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using MewtocolNet.Logging;
|
||||||
|
|
||||||
namespace MewtocolNet {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
@@ -43,6 +44,8 @@ namespace MewtocolNet {
|
|||||||
ErrorCode = error,
|
ErrorCode = error,
|
||||||
StationNumber = int.Parse(station ?? "0"),
|
StationNumber = int.Parse(station ?? "0"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PlcInfo = retInfo;
|
||||||
return retInfo;
|
return retInfo;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -51,16 +54,101 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Operation mode changing
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the PLCs operation mode to the given one
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mode">The mode to change to</param>
|
||||||
|
/// <returns>The success state of the write operation</returns>
|
||||||
|
public async Task<bool> SetOperationMode (OPMode mode) {
|
||||||
|
|
||||||
|
string modeChar = mode == OPMode.Prog ? "P" : "R";
|
||||||
|
|
||||||
|
string requeststring = $"%{GetStationNumber()}#RM{modeChar}";
|
||||||
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
|
if (result.Success) {
|
||||||
|
Logger.Log($"operation mode was changed to {mode}", LogLevel.Info, this);
|
||||||
|
} else {
|
||||||
|
Logger.Log("Operation mode change failed", LogLevel.Error, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.Success;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Byte range writingv / reading to registers
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a byte array to a span over multiple registers at once,
|
||||||
|
/// Rembember the plc can only store word so in order to write to a word array
|
||||||
|
/// your byte array should be double the size
|
||||||
|
/// </summary>
|
||||||
|
/// /// <param name="start">start address of the array</param>
|
||||||
|
/// <param name="byteArr"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> WriteByteRange (int start, byte[] byteArr) {
|
||||||
|
|
||||||
|
string byteString = byteArr.BigToMixedEndian().ToHexString();
|
||||||
|
var wordLength = byteArr.Length / 2;
|
||||||
|
if (byteArr.Length % 2 != 0)
|
||||||
|
wordLength++;
|
||||||
|
|
||||||
|
string startStr = start.ToString().PadLeft(5, '0');
|
||||||
|
string endStr = (start + wordLength - 1).ToString().PadLeft(5, '0');
|
||||||
|
|
||||||
|
string requeststring = $"%{GetStationNumber()}#WDD{startStr}{endStr}{byteString}";
|
||||||
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
|
return result.Success;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the bytes from the start adress for counts byte length
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="start">Start adress</param>
|
||||||
|
/// <param name="count">Number of bytes to get</param>
|
||||||
|
/// <returns>A byte array or null of there was an error</returns>
|
||||||
|
public async Task<byte[]> ReadByteRange (int start, int count) {
|
||||||
|
|
||||||
|
string startStr = start.ToString().PadLeft(5, '0');
|
||||||
|
var wordLength = count / 2;
|
||||||
|
bool wasOdd = false;
|
||||||
|
if (count % 2 != 0)
|
||||||
|
wordLength++;
|
||||||
|
|
||||||
|
string endStr = (start + wordLength - 1).ToString().PadLeft(5, '0');
|
||||||
|
|
||||||
|
string requeststring = $"%{GetStationNumber()}#RDD{startStr}{endStr}";
|
||||||
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
|
if(result.Success && !string.IsNullOrEmpty(result.Response)) {
|
||||||
|
|
||||||
|
var bytes = result.Response.ParseDTByteString(wordLength * 4).HexStringToByteArray();
|
||||||
|
|
||||||
|
return bytes.BigToMixedEndian().Take(count).ToArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Bool register reading / writing
|
#region Bool register reading / writing
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads the given boolean register from the PLC
|
/// Reads the given boolean register from the PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="_toRead">The register to read</param>
|
/// <param name="_toRead">The register to read</param>
|
||||||
/// <param name="_stationNumber">Station number to access</param>
|
public async Task<BRegisterResult> ReadBoolRegister (BRegister _toRead) {
|
||||||
public async Task<BRegisterResult> ReadBoolRegister (BRegister _toRead, int _stationNumber = 1) {
|
|
||||||
|
|
||||||
string requeststring = $"%{_stationNumber.ToString().PadLeft(2, '0')}#RCS{_toRead.BuildMewtocolIdent()}";
|
string requeststring = $"%{GetStationNumber()}#RCS{_toRead.BuildMewtocolIdent()}";
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
if(!result.Success) {
|
if(!result.Success) {
|
||||||
@@ -88,15 +176,14 @@ namespace MewtocolNet {
|
|||||||
/// Writes to the given bool register on the PLC
|
/// Writes to the given bool register on the PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="_toWrite">The register to write to</param>
|
/// <param name="_toWrite">The register to write to</param>
|
||||||
/// <param name="_stationNumber">Station number to access</param>
|
|
||||||
/// <returns>The success state of the write operation</returns>
|
/// <returns>The success state of the write operation</returns>
|
||||||
public async Task<bool> WriteBoolRegister (BRegister _toWrite, bool value, int _stationNumber = 1) {
|
public async Task<bool> WriteBoolRegister (BRegister _toWrite, bool value) {
|
||||||
|
|
||||||
string requeststring = $"%{_stationNumber.ToString().PadLeft(2, '0')}#WCS{_toWrite.BuildMewtocolIdent()}{(value ? "1" : "0")}";
|
string requeststring = $"%{GetStationNumber()}#WCS{_toWrite.BuildMewtocolIdent()}{(value ? "1" : "0")}";
|
||||||
|
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
return result.Success && result.Response.StartsWith($"%{ _stationNumber.ToString().PadLeft(2, '0')}#WC");
|
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WC");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,11 +198,11 @@ namespace MewtocolNet {
|
|||||||
/// <param name="_toRead">The register to read</param>
|
/// <param name="_toRead">The register to read</param>
|
||||||
/// <param name="_stationNumber">Station number to access</param>
|
/// <param name="_stationNumber">Station number to access</param>
|
||||||
/// <returns>A result with the given NumberRegister containing the readback value and a result struct</returns>
|
/// <returns>A result with the given NumberRegister containing the readback value and a result struct</returns>
|
||||||
public async Task<NRegisterResult<T>> ReadNumRegister<T> (NRegister<T> _toRead, int _stationNumber = 1) {
|
public async Task<NRegisterResult<T>> ReadNumRegister<T> (NRegister<T> _toRead) {
|
||||||
|
|
||||||
Type numType = typeof(T);
|
Type numType = typeof(T);
|
||||||
|
|
||||||
string requeststring = $"%{_stationNumber.ToString().PadLeft(2, '0')}#RD{_toRead.BuildMewtocolIdent()}";
|
string requeststring = $"%{GetStationNumber()}#RD{_toRead.BuildMewtocolIdent()}";
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
if(!result.Success || string.IsNullOrEmpty(result.Response)) {
|
if(!result.Success || string.IsNullOrEmpty(result.Response)) {
|
||||||
@@ -188,7 +275,7 @@ namespace MewtocolNet {
|
|||||||
/// <param name="_toWrite">The register to write</param>
|
/// <param name="_toWrite">The register to write</param>
|
||||||
/// <param name="_stationNumber">Station number to access</param>
|
/// <param name="_stationNumber">Station number to access</param>
|
||||||
/// <returns>The success state of the write operation</returns>
|
/// <returns>The success state of the write operation</returns>
|
||||||
public async Task<bool> WriteNumRegister<T> (NRegister<T> _toWrite, T _value, int _stationNumber = 1) {
|
public async Task<bool> WriteNumRegister<T> (NRegister<T> _toWrite, T _value) {
|
||||||
|
|
||||||
byte[] toWriteVal;
|
byte[] toWriteVal;
|
||||||
Type numType = typeof(T);
|
Type numType = typeof(T);
|
||||||
@@ -222,11 +309,11 @@ namespace MewtocolNet {
|
|||||||
toWriteVal = null;
|
toWriteVal = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string requeststring = $"%{_stationNumber.ToString().PadLeft(2, '0')}#WD{_toWrite.BuildMewtocolIdent()}{toWriteVal.ToHexString()}";
|
string requeststring = $"%{GetStationNumber()}#WD{_toWrite.BuildMewtocolIdent()}{toWriteVal.ToHexString()}";
|
||||||
|
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
return result.Success && result.Response.StartsWith($"%{ _stationNumber.ToString().PadLeft(2, '0')}#WD");
|
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WD");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +336,7 @@ namespace MewtocolNet {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<SRegisterResult> ReadStringRegister (SRegister _toRead, int _stationNumber = 1) {
|
public async Task<SRegisterResult> ReadStringRegister (SRegister _toRead, int _stationNumber = 1) {
|
||||||
|
|
||||||
string requeststring = $"%{_stationNumber.ToString().PadLeft(2, '0')}#RD{_toRead.BuildMewtocolIdent()}";
|
string requeststring = $"%{GetStationNumber()}#RD{_toRead.BuildMewtocolIdent()}";
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
if (result.Success)
|
if (result.Success)
|
||||||
_toRead.SetValueFromPLC(result.Response.ParseDTString());
|
_toRead.SetValueFromPLC(result.Response.ParseDTString());
|
||||||
@@ -273,7 +360,7 @@ namespace MewtocolNet {
|
|||||||
throw new ArgumentException("Write string size cannot be longer than reserved string size");
|
throw new ArgumentException("Write string size cannot be longer than reserved string size");
|
||||||
}
|
}
|
||||||
|
|
||||||
string stationNum = _stationNumber.ToString().PadLeft(2, '0');
|
string stationNum = GetStationNumber();
|
||||||
string dataString = _value.BuildDTString(_toWrite.ReservedSize);
|
string dataString = _value.BuildDTString(_toWrite.ReservedSize);
|
||||||
string dataArea = _toWrite.BuildCustomIdent(dataString.Length / 4);
|
string dataArea = _toWrite.BuildCustomIdent(dataString.Length / 4);
|
||||||
|
|
||||||
@@ -282,7 +369,18 @@ namespace MewtocolNet {
|
|||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
|
|
||||||
return result.Success && result.Response.StartsWith($"%{ _stationNumber.ToString().PadLeft(2, '0')}#WD");
|
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}#WD");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Helpers
|
||||||
|
|
||||||
|
internal string GetStationNumber () {
|
||||||
|
|
||||||
|
return StationNumber.ToString().PadLeft(2, '0');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
46
MewtocolNet/Mewtocol/PLCEnums/CpuType.cs
Normal file
46
MewtocolNet/Mewtocol/PLCEnums/CpuType.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
namespace MewtocolNet {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CPU type of the PLC
|
||||||
|
/// </summary>
|
||||||
|
public enum CpuType {
|
||||||
|
/// <summary>
|
||||||
|
/// FP 0 / FP 2.7K
|
||||||
|
/// </summary>
|
||||||
|
FP0_FP1_2_7K,
|
||||||
|
/// <summary>
|
||||||
|
/// FP0 / FP1, 5K / 10K
|
||||||
|
/// </summary>
|
||||||
|
FP0_FP1_5K_10K,
|
||||||
|
/// <summary>
|
||||||
|
/// FP1 M 0.9K
|
||||||
|
/// </summary>
|
||||||
|
FP1_M_0_9K,
|
||||||
|
/// <summary>
|
||||||
|
/// FP2 16k / 32k
|
||||||
|
/// </summary>
|
||||||
|
FP2_16K_32K,
|
||||||
|
/// <summary>
|
||||||
|
/// FP3 C 10K
|
||||||
|
/// </summary>
|
||||||
|
FP3_C_10K,
|
||||||
|
/// <summary>
|
||||||
|
/// FP3 C 16K
|
||||||
|
/// </summary>
|
||||||
|
FP3_C_16K,
|
||||||
|
/// <summary>
|
||||||
|
/// FP5 16K
|
||||||
|
/// </summary>
|
||||||
|
FP5_16K,
|
||||||
|
/// <summary>
|
||||||
|
/// FP 5 24K
|
||||||
|
/// </summary>
|
||||||
|
FP5_24K,
|
||||||
|
/// <summary>
|
||||||
|
/// Includes panasonic FPX, FPX-H, Sigma
|
||||||
|
/// </summary>
|
||||||
|
FP_Sigma_X_H_30K_60K_120K
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
MewtocolNet/Mewtocol/PLCEnums/OPMode.cs
Normal file
21
MewtocolNet/Mewtocol/PLCEnums/OPMode.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MewtocolNet {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CPU type of the PLC
|
||||||
|
/// </summary>
|
||||||
|
public enum OPMode {
|
||||||
|
/// <summary>
|
||||||
|
/// PLC run mode
|
||||||
|
/// </summary>
|
||||||
|
Run,
|
||||||
|
/// <summary>
|
||||||
|
/// PLC programming mode
|
||||||
|
/// </summary>
|
||||||
|
Prog,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,17 +10,34 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace MewtocolNet.RegisterAttributes {
|
namespace MewtocolNet.RegisterAttributes {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A register collection base with full auto read and notification support built in
|
||||||
|
/// </summary>
|
||||||
public class RegisterCollectionBase : INotifyPropertyChanged {
|
public class RegisterCollectionBase : INotifyPropertyChanged {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to its bound interface
|
||||||
|
/// </summary>
|
||||||
public MewtocolInterface PLCInterface { get; set; }
|
public MewtocolInterface PLCInterface { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whenever one of its props changes
|
||||||
|
/// </summary>
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
internal void TriggerPropertyChanged (string propertyName = null) {
|
/// <summary>
|
||||||
|
/// Triggers a property changed event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyName">Name of the property to trigger for</param>
|
||||||
|
public void TriggerPropertyChanged (string propertyName = null) {
|
||||||
var handler = PropertyChanged;
|
var handler = PropertyChanged;
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void OnInterfaceLinked (MewtocolInterface plc) { }
|
||||||
|
|
||||||
|
public virtual void OnInterfaceLinkedAndOnline (MewtocolInterface plc) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<PackageId>AppLogger</PackageId>
|
<PackageId>MewtocolNet</PackageId>
|
||||||
<Version>0.2.5</Version>
|
<Version>0.3.2</Version>
|
||||||
<Authors>Felix Weiss</Authors>
|
<Authors>Felix Weiss</Authors>
|
||||||
<Company>Womed</Company>
|
<Company>Womed</Company>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<Description>A Mewtocol protocol library to interface with Panasonic PLCs over TCP/Serial.</Description>
|
||||||
|
<Copyright>Copyright (c) 2022 WOLF Medizintechnik GmbH</Copyright>
|
||||||
|
<PackageProjectUrl>https://github.com/WOmed/MewtocolNet</PackageProjectUrl>
|
||||||
|
<RepositoryUrl>https://github.com/WOmed/MewtocolNet</RepositoryUrl>
|
||||||
|
<PackageTags>plc;panasonic;mewtocol;automation;</PackageTags>
|
||||||
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
<UserSecretsId>2ccdcc9b-94a3-4e76-8827-453ab889ea33</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<DocumentationFile>C:\Users\Felix Weiß\source\repos\WOmed\MewtocolNet\Builds\MewtocolNet.xml</DocumentationFile>
|
<DocumentationFile>..\Builds\MewtocolNet.xml</DocumentationFile>
|
||||||
<OutputPath>C:\Users\Felix Weiß\source\repos\WOmed\MewtocolNet\Builds</OutputPath>
|
<OutputPath>..\Builds</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
68
README.md
68
README.md
@@ -1,3 +1,4 @@
|
|||||||
|
[](https://github.com/WOmed/MewtocolNet/actions/workflows/dotnet-windows.yml)
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
@@ -17,11 +18,10 @@ This software was written by WOLF Medizintechnik GmbH (@WOmed/dev).
|
|||||||
|
|
||||||
- [x] Read out stats from your PLC
|
- [x] Read out stats from your PLC
|
||||||
- [x] Read and write registers in real time
|
- [x] Read and write registers in real time
|
||||||
- [X] Dynamic register type casting from properties
|
- [x] Dynamic register type casting from properties
|
||||||
- [ ] Change run / prog modes
|
- [x] Change run / prog modes
|
||||||
- [ ] Write byte blocks in a whole chain
|
- [x] Write / read byte blocks in a whole chain
|
||||||
- [ ] Upload programs to the PLC
|
- [ ] Upload / Download programs to the PLC
|
||||||
- [ ] Download programs from the PLC
|
|
||||||
- [ ] Reading / writing PLC system registers
|
- [ ] Reading / writing PLC system registers
|
||||||
|
|
||||||
# Support
|
# Support
|
||||||
@@ -53,7 +53,7 @@ Where is the RS232/Serial support?
|
|||||||
|
|
||||||
Install this package by using [Nuget](https://www.nuget.org/packages/MewtocolNet/) or reference
|
Install this package by using [Nuget](https://www.nuget.org/packages/MewtocolNet/) or reference
|
||||||
```XML
|
```XML
|
||||||
<PackageReference Include="MewtocolNet" Version="0.2.5" />
|
<PackageReference Include="MewtocolNet" Version="0.3.0" />
|
||||||
```
|
```
|
||||||
in your dependencies.
|
in your dependencies.
|
||||||
Alternatively use the dotnet CLI and run
|
Alternatively use the dotnet CLI and run
|
||||||
@@ -84,28 +84,15 @@ Logger.OnNewLogMessage((date, msg) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//setting up a new PLC interface
|
//setting up a new PLC interface
|
||||||
MewtocolInterface interf = new MewtocolInterface("192.168.115.5");
|
MewtocolInterface plc = new MewtocolInterface("192.168.115.5");
|
||||||
|
|
||||||
await interf.ConnectAsync();
|
await plc.ConnectAsync();
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use the callbacks of the `ConnectAsync()` method to do something after the initial connection establishment.
|
|
||||||
|
|
||||||
```C#
|
|
||||||
await interf.ConnectAsync(
|
|
||||||
//PLC connected
|
|
||||||
(plc) => {
|
|
||||||
if(plcinf.OperationMode.RunMode)
|
|
||||||
Console.WriteLine("PLC is in RUN");
|
|
||||||
},
|
|
||||||
//Connection failed
|
|
||||||
() => {
|
|
||||||
Console.WriteLine("PLC failed to connect");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
```
|
|
||||||
## Reading data registers / contacts
|
## Reading data registers / contacts
|
||||||
|
|
||||||
|
[Detailed instructions](https://github.com/WOmed/MewtocolNet/wiki/Attribute-handled-reading)
|
||||||
|
|
||||||
- Create a new class that inherits from `RegisterCollectionBase`
|
- Create a new class that inherits from `RegisterCollectionBase`
|
||||||
|
|
||||||
```C#
|
```C#
|
||||||
@@ -135,20 +122,14 @@ public class TestRegisters : RegisterCollectionBase {
|
|||||||
- attach an automatic poller by chaining `.WithPoller()` after the register attachment
|
- attach an automatic poller by chaining `.WithPoller()` after the register attachment
|
||||||
|
|
||||||
```C#
|
```C#
|
||||||
//attaching a logger
|
|
||||||
Logger.LogLevel = LogLevel.Verbose;
|
|
||||||
Logger.OnNewLogMessage((date, msg) => {
|
|
||||||
Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}");
|
|
||||||
});
|
|
||||||
|
|
||||||
//setting up a new PLC interface and register collection
|
//setting up a new PLC interface and register collection
|
||||||
MewtocolInterface interf = new MewtocolInterface("192.168.115.5");
|
MewtocolInterface plc = new MewtocolInterface("192.168.115.5");
|
||||||
TestRegisters registers = new TestRegisters();
|
TestRegisters registers = new TestRegisters();
|
||||||
|
|
||||||
//attaching the register collection and an automatic poller
|
//attaching the register collection and an automatic poller
|
||||||
interf.WithRegisterCollection(registers).WithPoller();
|
plc.WithRegisterCollection(registers).WithPoller();
|
||||||
|
|
||||||
await interf.ConnectAsync(
|
await plc.ConnectAsync(
|
||||||
(plcinf) => {
|
(plcinf) => {
|
||||||
//reading a value from the register collection
|
//reading a value from the register collection
|
||||||
Console.WriteLine($"Time Value is: {registers.TestTime}");
|
Console.WriteLine($"Time Value is: {registers.TestTime}");
|
||||||
@@ -169,37 +150,28 @@ Sets the register without feedback if it was set
|
|||||||
|
|
||||||
```C#
|
```C#
|
||||||
//inverts the boolean register
|
//inverts the boolean register
|
||||||
interf.SetRegister(nameof(registers.TestBool1), !registers.TestBool1);
|
plc.SetRegister(nameof(registers.TestBool1), !registers.TestBool1);
|
||||||
|
|
||||||
//set the current second to the PLCs TIME register
|
//set the current second to the PLCs TIME register
|
||||||
interf.SetRegister(nameof(registers.TestTime), TimeSpan.FromSeconds(DateTime.Now.Second));
|
plc.SetRegister(nameof(registers.TestTime), TimeSpan.FromSeconds(DateTime.Now.Second));
|
||||||
|
|
||||||
//writes 'Test' to the PLCs string register
|
//writes 'Test' to the PLCs string register
|
||||||
interf.SetRegister(nameof(registers.TestString1), "Test");
|
plc.SetRegister(nameof(registers.TestString1), "Test");
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also set a register by calling its name directly (Must be either in an attached register collection or added to the list manually)
|
You can also set a register by calling its name directly (Must be either in an attached register collection or added to the list manually)
|
||||||
|
|
||||||
Adding registers to a manual list
|
Adding registers to a manual list
|
||||||
```C#
|
```C#
|
||||||
interf.AddRegister<bool>(105, _name: "ManualBoolRegister");
|
plc.AddRegister<bool>(105, _name: "ManualBoolRegister");
|
||||||
```
|
```
|
||||||
|
|
||||||
Reading the value of the manually added register
|
Reading the value of the manually added register
|
||||||
```C#
|
```C#
|
||||||
//get the value as a string
|
//get the value as a string
|
||||||
string value = interf.GetRegister("ManualBoolRegister").GetValueString();
|
string value = plc.GetRegister("ManualBoolRegister").GetValueString();
|
||||||
//get the value by casting
|
//get the value by casting
|
||||||
bool value2 = interf.GetRegister<BRegister>("ManualBoolRegister").Value;
|
bool value2 = plc.GetRegister<BRegister>("ManualBoolRegister").Value;
|
||||||
//for double casted ones like numbers
|
//for double casted ones like numbers
|
||||||
var value2 = interf.GetRegister<NRegister<short>>("NumberRegister").Value;
|
var value2 = plc.GetRegister<NRegister<short>>("NumberRegister").Value;
|
||||||
```
|
|
||||||
|
|
||||||
### Asynchronous
|
|
||||||
|
|
||||||
Sets the register waiting for the PLC to confirm it was set
|
|
||||||
|
|
||||||
```C#
|
|
||||||
//inverts the boolean register
|
|
||||||
await interf.SetRegisterAsync(nameof(registers.TestBool1), !registers.TestBool1);
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user