From 0e1f5cd12b1f099c11b679d492a3f509d4750868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Wei=C3=9F?= <72068105+Sandoun@users.noreply.github.com> Date: Tue, 19 Jul 2022 09:28:18 +0200 Subject: [PATCH] Added possiblity to connect over a certain host endpoint - fixed missing docs and - fixed accessing modifiers --- MewtocolNet/Mewtocol/CpuInfo.cs | 21 ++++++-- MewtocolNet/Mewtocol/MewtocolInterface.cs | 23 +++++++-- .../Mewtocol/MewtocolInterfaceRequests.cs | 3 +- MewtocolNet/Mewtocol/PLCMode.cs | 25 +++++++++ .../RegisterAttributes/RegisterAttribute.cs | 51 ++++++++++++++++--- .../RegisterCollectionBase.cs | 9 ++++ .../Mewtocol/Subregisters/BRegister.cs | 10 ++-- .../Mewtocol/Subregisters/BRegisterResult.cs | 17 +++++-- .../Mewtocol/Subregisters/NRegister.cs | 7 +-- .../Mewtocol/Subregisters/NRegisterResult.cs | 15 +++--- MewtocolNet/Mewtocol/Subregisters/Register.cs | 6 +++ .../Mewtocol/Subregisters/SRegister.cs | 13 ++--- .../Mewtocol/Subregisters/SRegisterResult.cs | 18 ++++--- 13 files changed, 166 insertions(+), 52 deletions(-) diff --git a/MewtocolNet/Mewtocol/CpuInfo.cs b/MewtocolNet/Mewtocol/CpuInfo.cs index 124ce2a..3fa008b 100644 --- a/MewtocolNet/Mewtocol/CpuInfo.cs +++ b/MewtocolNet/Mewtocol/CpuInfo.cs @@ -1,14 +1,28 @@ using System; namespace MewtocolNet.Registers { + + /// + /// Contains information about the plc and its cpu + /// public partial class CpuInfo { + /// + /// The cpu type of the plc + /// public CpuType Cputype { get; set; } + + /// + /// Program capacity in 1K steps + /// public int ProgramCapacity { get; set; } + + /// + /// Version of the cpu + /// public string CpuVersion { get; set; } - - public static CpuInfo BuildFromHexString (string _cpuType, string _cpuVersion, string _progCapacity) { + internal static CpuInfo BuildFromHexString (string _cpuType, string _cpuVersion, string _progCapacity) { CpuInfo retInf = new CpuInfo(); @@ -47,8 +61,7 @@ namespace MewtocolNet.Registers { return retInf; } + } - - } \ No newline at end of file diff --git a/MewtocolNet/Mewtocol/MewtocolInterface.cs b/MewtocolNet/Mewtocol/MewtocolInterface.cs index ed60e05..eb0c63a 100644 --- a/MewtocolNet/Mewtocol/MewtocolInterface.cs +++ b/MewtocolNet/Mewtocol/MewtocolInterface.cs @@ -52,6 +52,11 @@ namespace MewtocolNet { set { connectTimeout = value; } } + /// + /// The host ip endpoint, leave it null to use an automatic interface + /// + public IPEndPoint HostEndpoint { get; set; } + private bool isConnected; /// /// The current connection state of the interface @@ -271,11 +276,19 @@ namespace MewtocolNet { try { - client = new TcpClient() { - ReceiveBufferSize = RecBufferSize, - NoDelay = false, - ExclusiveAddressUse = true, - }; + if(HostEndpoint != null) { + client = new TcpClient(HostEndpoint) { + ReceiveBufferSize = RecBufferSize, + NoDelay = false, + ExclusiveAddressUse = true, + }; + } else { + client = new TcpClient() { + ReceiveBufferSize = RecBufferSize, + NoDelay = false, + ExclusiveAddressUse = true, + }; + } var result = client.BeginConnect(targetIP, port, null, null); var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(ConnectTimeout)); diff --git a/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs b/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs index 0c6636b..3df69b5 100644 --- a/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs +++ b/MewtocolNet/Mewtocol/MewtocolInterfaceRequests.cs @@ -190,6 +190,7 @@ namespace MewtocolNet { /// Writes to the given bool register on the PLC /// /// The register to write to + /// The value to write /// The success state of the write operation public async Task WriteBoolRegister (BRegister _toWrite, bool value) { @@ -294,7 +295,7 @@ namespace MewtocolNet { /// /// Type of number (short, ushort, int, uint, float) /// The register to write - /// Station number to access + /// The value to write /// The success state of the write operation public async Task WriteNumRegister (NRegister _toWrite, T _value) { diff --git a/MewtocolNet/Mewtocol/PLCMode.cs b/MewtocolNet/Mewtocol/PLCMode.cs index f3b0e58..e9a10eb 100644 --- a/MewtocolNet/Mewtocol/PLCMode.cs +++ b/MewtocolNet/Mewtocol/PLCMode.cs @@ -6,13 +6,38 @@ namespace MewtocolNet.Registers { /// All modes /// public class PLCMode { + + /// + /// PLC is running + /// public bool RunMode { get; set; } + /// + /// PLC is in test + /// public bool TestRunMode { get; set; } + /// + /// BreakExcecuting + /// public bool BreakExcecuting { get; set; } + /// + /// BreakValid + /// public bool BreakValid { get; set; } + /// + /// PLC output is enabled + /// public bool OutputEnabled { get; set; } + /// + /// PLC runs step per step + /// public bool StepRunMode { get; set; } + /// + /// Message executing + /// public bool MessageExecuting { get; set; } + /// + /// PLC is in remote mode + /// public bool RemoteMode { get; set; } /// diff --git a/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs b/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs index f5c45c3..382c574 100644 --- a/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs +++ b/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs @@ -6,22 +6,39 @@ using System.Threading.Tasks; namespace MewtocolNet.RegisterAttributes { + /// + /// The size of the bitwise register + /// public enum BitCount { + /// + /// 16 bit + /// B16, + /// + /// 32 bit + /// B32 } + /// + /// Defines the behavior of a register property + /// [AttributeUsage(AttributeTargets.Property)] public class RegisterAttribute : Attribute { - public int MemoryArea; - public int StringLength; - public RegisterType RegisterType; - public SpecialAddress SpecialAddress = SpecialAddress.None; - public BitCount BitCount; - public int AssignedBitIndex = -1; + internal int MemoryArea; + internal int StringLength; + internal RegisterType RegisterType; + internal SpecialAddress SpecialAddress = SpecialAddress.None; + internal BitCount BitCount; + internal int AssignedBitIndex = -1; + /// + /// Attribute for string type or numeric registers + /// + /// The area in the plcs memory + /// The max string length in the plc public RegisterAttribute (int memoryArea, int stringLength = 1) { MemoryArea = memoryArea; @@ -29,6 +46,11 @@ namespace MewtocolNet.RegisterAttributes { } + /// + /// Attribute for boolean registers + /// + /// The area in the plcs memory + /// The type of boolean register public RegisterAttribute (int memoryArea, RegisterType type) { if (type.ToString().StartsWith("DT")) @@ -40,6 +62,11 @@ namespace MewtocolNet.RegisterAttributes { } + /// + /// Attribute for boolean registers + /// + /// The special area in the plcs memory + /// The type of boolean register public RegisterAttribute (RegisterType type, SpecialAddress spAdress) { if (type.ToString().StartsWith("DT")) @@ -50,7 +77,11 @@ namespace MewtocolNet.RegisterAttributes { } - + /// + /// Attribute to read numeric registers as bitwise + /// + /// The area in the plcs memory + /// The number of bits to parse public RegisterAttribute (int memoryArea, BitCount bitcount) { MemoryArea = memoryArea; @@ -59,6 +90,12 @@ namespace MewtocolNet.RegisterAttributes { } + /// + /// Attribute to read numeric registers as bitwise + /// + /// The area in the plcs memory + /// The number of bits to parse + /// The index of the bit that gets linked to the bool public RegisterAttribute (int memoryArea, uint assignBit, BitCount bitcount) { if(assignBit > 15 && bitcount == BitCount.B16) { diff --git a/MewtocolNet/Mewtocol/RegisterAttributes/RegisterCollectionBase.cs b/MewtocolNet/Mewtocol/RegisterAttributes/RegisterCollectionBase.cs index 42ad25d..1a1a829 100644 --- a/MewtocolNet/Mewtocol/RegisterAttributes/RegisterCollectionBase.cs +++ b/MewtocolNet/Mewtocol/RegisterAttributes/RegisterCollectionBase.cs @@ -34,8 +34,17 @@ namespace MewtocolNet.RegisterAttributes { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + /// + /// Gets called when the register collection base was linked to its parent mewtocol interface + /// + /// The parent interface public virtual void OnInterfaceLinked (MewtocolInterface plc) { } + /// + /// Gets called when the register collection base was linked to its parent mewtocol interface + /// and the plc connection is established + /// + /// The parent interface public virtual void OnInterfaceLinkedAndOnline (MewtocolInterface plc) { } } diff --git a/MewtocolNet/Mewtocol/Subregisters/BRegister.cs b/MewtocolNet/Mewtocol/Subregisters/BRegister.cs index 90d2735..d304890 100644 --- a/MewtocolNet/Mewtocol/Subregisters/BRegister.cs +++ b/MewtocolNet/Mewtocol/Subregisters/BRegister.cs @@ -12,8 +12,7 @@ namespace MewtocolNet.Registers { internal RegisterType RegType { get; private set; } internal SpecialAddress SpecialAddress { get; private set; } - public bool NeedValue; - public bool LastValue; + internal bool LastValue; /// /// The value of the register @@ -54,6 +53,9 @@ namespace MewtocolNet.Registers { } + /// + /// Builds the register area name + /// public override string BuildMewtocolIdent () { //build area code from register type @@ -73,9 +75,7 @@ namespace MewtocolNet.Registers { TriggerChangedEvnt(this); TriggerNotifyChange(); } - public override string ToString() { - return $"Adress: {MemoryAdress} Val: {Value}"; - } + } } diff --git a/MewtocolNet/Mewtocol/Subregisters/BRegisterResult.cs b/MewtocolNet/Mewtocol/Subregisters/BRegisterResult.cs index 62d1c8a..8a39277 100644 --- a/MewtocolNet/Mewtocol/Subregisters/BRegisterResult.cs +++ b/MewtocolNet/Mewtocol/Subregisters/BRegisterResult.cs @@ -1,13 +1,20 @@ namespace MewtocolNet.Registers { + + /// + /// Result for a boolean register + /// public class BRegisterResult { + /// + /// The command result + /// public CommandResult Result { get; set; } + + /// + /// The used register + /// public BRegister Register { get; set; } - public override string ToString() { - string errmsg = Result.Success ? "" : $", Error [{Result.ErrorDescription}]"; - return $"Result [{Result.Success}], Register [{Register.ToString()}]{errmsg}"; - } - } + } diff --git a/MewtocolNet/Mewtocol/Subregisters/NRegister.cs b/MewtocolNet/Mewtocol/Subregisters/NRegister.cs index 2eff9a4..760d9c1 100644 --- a/MewtocolNet/Mewtocol/Subregisters/NRegister.cs +++ b/MewtocolNet/Mewtocol/Subregisters/NRegister.cs @@ -7,8 +7,7 @@ namespace MewtocolNet.Registers { /// The type of the numeric value public class NRegister : Register { - public T NeedValue; - public T LastValue; + internal T LastValue; /// /// The value of the register @@ -78,10 +77,6 @@ namespace MewtocolNet.Registers { TriggerNotifyChange(); } - public override string ToString() { - return $"Adress: {MemoryAdress} Val: {Value}"; - } - } diff --git a/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs b/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs index 79169df..2296042 100644 --- a/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs +++ b/MewtocolNet/Mewtocol/Subregisters/NRegisterResult.cs @@ -6,13 +6,16 @@ namespace MewtocolNet.Registers { /// /// The type of the numeric value public class NRegisterResult { - public CommandResult Result { get; set; } - public NRegister Register { get; set; } - public override string ToString() { - string errmsg = Result.Success ? "" : $", Error [{Result.ErrorDescription}]"; - return $"Result [{Result.Success}], Register [{Register.ToString()}]{errmsg}"; - } + /// + /// Command result + /// + public CommandResult Result { get; set; } + + /// + /// The used register + /// + public NRegister Register { get; set; } /// /// Trys to get the value of there is one diff --git a/MewtocolNet/Mewtocol/Subregisters/Register.cs b/MewtocolNet/Mewtocol/Subregisters/Register.cs index eebf7e1..fc1b98a 100644 --- a/MewtocolNet/Mewtocol/Subregisters/Register.cs +++ b/MewtocolNet/Mewtocol/Subregisters/Register.cs @@ -75,6 +75,9 @@ namespace MewtocolNet.Registers { }; } + /// + /// Builds the register area name + /// public virtual string BuildMewtocolIdent() { StringBuilder asciistring = new StringBuilder("D"); @@ -178,6 +181,9 @@ namespace MewtocolNet.Registers { } + /// + /// Gets the register dataarea string DT for 16bit and DDT for 32 bit types + /// public string GetRegisterString () { if (this is NRegister shortReg) { diff --git a/MewtocolNet/Mewtocol/Subregisters/SRegister.cs b/MewtocolNet/Mewtocol/Subregisters/SRegister.cs index 89d2742..164ae91 100644 --- a/MewtocolNet/Mewtocol/Subregisters/SRegister.cs +++ b/MewtocolNet/Mewtocol/Subregisters/SRegister.cs @@ -9,9 +9,12 @@ namespace MewtocolNet.Registers { private string lastVal = ""; + /// + /// The current value of the register + /// public string Value => lastVal; - public short ReservedSize { get; set; } + internal short ReservedSize { get; set; } /// /// Defines a register containing a string @@ -32,10 +35,9 @@ namespace MewtocolNet.Registers { memoryLength = (int)Math.Round(wordsize + 1); } - public override string ToString() { - return $"Adress: {MemoryAdress} Val: {Value}"; - } - + /// + /// Builds the register identifier for the mewotocol protocol + /// public override string BuildMewtocolIdent() { StringBuilder asciistring = new StringBuilder("D"); @@ -65,7 +67,6 @@ namespace MewtocolNet.Registers { TriggerNotifyChange(); } - } } diff --git a/MewtocolNet/Mewtocol/Subregisters/SRegisterResult.cs b/MewtocolNet/Mewtocol/Subregisters/SRegisterResult.cs index f3cc1bf..45129a6 100644 --- a/MewtocolNet/Mewtocol/Subregisters/SRegisterResult.cs +++ b/MewtocolNet/Mewtocol/Subregisters/SRegisterResult.cs @@ -1,15 +1,19 @@ namespace MewtocolNet.Registers { + + /// + /// The results of a string register operation + /// public class SRegisterResult { + + /// + /// The command result + /// public CommandResult Result { get; set; } + /// + /// The register definition used + /// public SRegister Register { get; set; } - public override string ToString() { - string errmsg = Result.Success ? "" : $", Error [{Result.ErrorDescription}]"; - return $"Result [{Result.Success}], Register [{Register.ToString()}]{errmsg}"; - } } - - - }