mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Restructured files
- householding
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MewtocolNet.Links {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
internal class CodeDescriptions {
|
internal class CodeDescriptions {
|
||||||
|
|
||||||
@@ -40,7 +39,6 @@ namespace MewtocolNet.Links {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using MewtocolNet.PLCEnums;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains information about the plc and its cpu
|
/// Contains information about the plc and its cpu
|
||||||
@@ -22,7 +23,7 @@ namespace MewtocolNet.Registers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string CpuVersion { get; set; }
|
public string CpuVersion { get; set; }
|
||||||
|
|
||||||
internal static CpuInfo BuildFromHexString (string _cpuType, string _cpuVersion, string _progCapacity) {
|
internal static CpuInfo BuildFromHexString(string _cpuType, string _cpuVersion, string _progCapacity) {
|
||||||
|
|
||||||
CpuInfo retInf = new CpuInfo();
|
CpuInfo retInf = new CpuInfo();
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ namespace MewtocolNet.Registers {
|
|||||||
return retInf;
|
return retInf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
using System;
|
using MewtocolNet.Logging;
|
||||||
|
using MewtocolNet.Subregisters;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MewtocolNet.Logging;
|
|
||||||
using MewtocolNet.RegisterAttributes;
|
|
||||||
using MewtocolNet.Registers;
|
|
||||||
|
|
||||||
namespace MewtocolNet {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
@@ -41,7 +37,7 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Kills the poller completely
|
/// Kills the poller completely
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void KillPoller () {
|
internal void KillPoller() {
|
||||||
|
|
||||||
pollerTaskRunning = false;
|
pollerTaskRunning = false;
|
||||||
pollerTaskStopped = true;
|
pollerTaskStopped = true;
|
||||||
@@ -54,7 +50,7 @@ namespace MewtocolNet {
|
|||||||
/// Pauses the polling and waits for the last message to be sent
|
/// Pauses the polling and waits for the last message to be sent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task PausePollingAsync () {
|
public async Task PausePollingAsync() {
|
||||||
|
|
||||||
if (!pollerTaskRunning)
|
if (!pollerTaskRunning)
|
||||||
return;
|
return;
|
||||||
@@ -65,9 +61,9 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
if (pollerIsPaused)
|
if (pollerIsPaused)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pollerTaskRunning = false;
|
pollerTaskRunning = false;
|
||||||
@@ -77,7 +73,7 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resumes the polling
|
/// Resumes the polling
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ResumePolling () {
|
public void ResumePolling() {
|
||||||
|
|
||||||
pollerTaskRunning = true;
|
pollerTaskRunning = true;
|
||||||
|
|
||||||
@@ -86,7 +82,7 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attaches a continous reader that reads back the Registers and Contacts
|
/// Attaches a continous reader that reads back the Registers and Contacts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void AttachPoller () {
|
internal void AttachPoller() {
|
||||||
|
|
||||||
if (pollerTaskRunning)
|
if (pollerTaskRunning)
|
||||||
return;
|
return;
|
||||||
@@ -196,9 +192,9 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void PropertyRegisterWasSet (string propName, object value) {
|
internal void PropertyRegisterWasSet(string propName, object value) {
|
||||||
|
|
||||||
SetRegister(propName, value);
|
SetRegister(propName, value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +203,7 @@ namespace MewtocolNet {
|
|||||||
#region Register Adding
|
#region Register Adding
|
||||||
|
|
||||||
//Internal register adding for auto register collection building
|
//Internal register adding for auto register collection building
|
||||||
internal void AddRegister<T> (Type _colType, int _address, PropertyInfo boundProp, int _length = 1, bool _isBitwise = false, Type _enumType = null) {
|
internal void AddRegister<T>(Type _colType, int _address, PropertyInfo boundProp, int _length = 1, bool _isBitwise = false, Type _enumType = null) {
|
||||||
|
|
||||||
Type regType = typeof(T);
|
Type regType = typeof(T);
|
||||||
|
|
||||||
@@ -224,7 +220,7 @@ namespace MewtocolNet {
|
|||||||
string propName = boundProp.Name;
|
string propName = boundProp.Name;
|
||||||
|
|
||||||
//rename the property name to prevent duplicate names in case of a bitwise prop
|
//rename the property name to prevent duplicate names in case of a bitwise prop
|
||||||
if(_isBitwise && regType == typeof(short))
|
if (_isBitwise && regType == typeof(short))
|
||||||
propName = $"Auto_Bitwise_DT{_address}";
|
propName = $"Auto_Bitwise_DT{_address}";
|
||||||
|
|
||||||
if (_isBitwise && regType == typeof(int))
|
if (_isBitwise && regType == typeof(int))
|
||||||
@@ -245,7 +241,7 @@ namespace MewtocolNet {
|
|||||||
} else if (regType == typeof(TimeSpan)) {
|
} else if (regType == typeof(TimeSpan)) {
|
||||||
reg = new NRegister<TimeSpan>(_address, propName).WithCollectionType(_colType);
|
reg = new NRegister<TimeSpan>(_address, propName).WithCollectionType(_colType);
|
||||||
} else if (regType == typeof(bool)) {
|
} else if (regType == typeof(bool)) {
|
||||||
reg = new BRegister(IOType.R, 0x0, _address,propName).WithCollectionType(_colType);
|
reg = new BRegister(IOType.R, 0x0, _address, propName).WithCollectionType(_colType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reg == null) {
|
if (reg == null) {
|
||||||
@@ -270,7 +266,7 @@ namespace MewtocolNet {
|
|||||||
/// Gets a register that was added by its name
|
/// Gets a register that was added by its name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IRegister GetRegister (string name) {
|
public IRegister GetRegister(string name) {
|
||||||
|
|
||||||
return Registers.FirstOrDefault(x => x.Name == name);
|
return Registers.FirstOrDefault(x => x.Name == name);
|
||||||
|
|
||||||
@@ -281,16 +277,16 @@ namespace MewtocolNet {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of register</typeparam>
|
/// <typeparam name="T">The type of register</typeparam>
|
||||||
/// <returns>A casted register or the <code>default</code> value</returns>
|
/// <returns>A casted register or the <code>default</code> value</returns>
|
||||||
public T GetRegister<T> (string name) where T : IRegister {
|
public T GetRegister<T>(string name) where T : IRegister {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var reg = Registers.FirstOrDefault(x => x.Name == name);
|
var reg = Registers.FirstOrDefault(x => x.Name == name);
|
||||||
return (T)reg;
|
return (T)reg;
|
||||||
|
|
||||||
} catch (InvalidCastException) {
|
} catch (InvalidCastException) {
|
||||||
|
|
||||||
return default(T);
|
return default(T);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -302,7 +298,7 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list of all added registers
|
/// Gets a list of all added registers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<IRegister> GetAllRegisters () {
|
public List<IRegister> GetAllRegisters() {
|
||||||
|
|
||||||
return Registers;
|
return Registers;
|
||||||
|
|
||||||
@@ -312,19 +308,20 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
#region Event Invoking
|
#region Event Invoking
|
||||||
|
|
||||||
internal void InvokeRegisterChanged (IRegister reg) {
|
internal void InvokeRegisterChanged(IRegister reg) {
|
||||||
|
|
||||||
RegisterChanged?.Invoke(reg);
|
RegisterChanged?.Invoke(reg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void InvokePolledCycleDone () {
|
internal void InvokePolledCycleDone() {
|
||||||
|
|
||||||
PolledCycle?.Invoke();
|
PolledCycle?.Invoke();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MewtocolNet {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MewtocolNet.Logging {
|
namespace MewtocolNet.Logging {
|
||||||
|
|
||||||
@@ -12,14 +10,14 @@ namespace MewtocolNet.Logging {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the loglevel for the logger module
|
/// Sets the loglevel for the logger module
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static LogLevel LogLevel { get; set; }
|
public static LogLevel LogLevel { get; set; }
|
||||||
|
|
||||||
internal static Action<DateTime, string> LogInvoked;
|
internal static Action<DateTime, string> LogInvoked;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets invoked whenever a new log message is ready
|
/// Gets invoked whenever a new log message is ready
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void OnNewLogMessage (Action<DateTime, string> onMsg) {
|
public static void OnNewLogMessage(Action<DateTime, string> onMsg) {
|
||||||
|
|
||||||
LogInvoked += (t, m) => {
|
LogInvoked += (t, m) => {
|
||||||
onMsg(t, m);
|
onMsg(t, m);
|
||||||
@@ -27,7 +25,7 @@ namespace MewtocolNet.Logging {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Log (string message, LogLevel loglevel, MewtocolInterface sender = null) {
|
internal static void Log(string message, LogLevel loglevel, MewtocolInterface sender = null) {
|
||||||
|
|
||||||
if ((int)loglevel <= (int)LogLevel) {
|
if ((int)loglevel <= (int)LogLevel) {
|
||||||
if (sender == null) {
|
if (sender == null) {
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
namespace MewtocolNet.Logging {
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MewtocolNet.Logging {
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The loglevel of the logging module
|
/// The loglevel of the logging module
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Collections.Generic;
|
|
||||||
using MewtocolNet.Registers;
|
|
||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace MewtocolNet {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Turns a bit array into a 0 and 1 string
|
/// Turns a bit array into a 0 and 1 string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ToBitString (this BitArray arr) {
|
public static string ToBitString(this BitArray arr) {
|
||||||
|
|
||||||
var bits = new bool[arr.Length];
|
var bits = new bool[arr.Length];
|
||||||
arr.CopyTo(bits, 0);
|
arr.CopyTo(bits, 0);
|
||||||
@@ -27,29 +26,29 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a string (after converting to upper case) to ascii bytes
|
/// Converts a string (after converting to upper case) to ascii bytes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static byte[] ToHexASCIIBytes (this string _str) {
|
internal static byte[] ToHexASCIIBytes(this string _str) {
|
||||||
|
|
||||||
ASCIIEncoding ascii = new ASCIIEncoding();
|
ASCIIEncoding ascii = new ASCIIEncoding();
|
||||||
byte[] bytes = ascii.GetBytes(_str.ToUpper());
|
byte[] bytes = ascii.GetBytes(_str.ToUpper());
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string BuildBCCFrame (this string asciiArr) {
|
internal static string BuildBCCFrame(this string asciiArr) {
|
||||||
|
|
||||||
Encoding ae = Encoding.ASCII;
|
Encoding ae = Encoding.ASCII;
|
||||||
byte[] b = ae.GetBytes(asciiArr);
|
byte[] b = ae.GetBytes(asciiArr);
|
||||||
byte xorTotalByte = 0;
|
byte xorTotalByte = 0;
|
||||||
for(int i = 0; i < b.Length; i++)
|
for (int i = 0; i < b.Length; i++)
|
||||||
xorTotalByte ^= b[i];
|
xorTotalByte ^= b[i];
|
||||||
return asciiArr.Insert(asciiArr.Length, xorTotalByte.ToString("X2"));
|
return asciiArr.Insert(asciiArr.Length, xorTotalByte.ToString("X2"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses the byte string from a incoming RD message
|
/// Parses the byte string from a incoming RD message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string ParseDTByteString (this string _onString, int _blockSize = 4) {
|
internal static string ParseDTByteString(this string _onString, int _blockSize = 4) {
|
||||||
|
|
||||||
if (_onString == null)
|
if (_onString == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -63,7 +62,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool? ParseRCSingleBit (this string _onString) {
|
internal static bool? ParseRCSingleBit(this string _onString) {
|
||||||
|
|
||||||
var res = new Regex(@"\%([0-9]{2})\$RC(.)").Match(_onString);
|
var res = new Regex(@"\%([0-9]{2})\$RC(.)").Match(_onString);
|
||||||
if (res.Success) {
|
if (res.Success) {
|
||||||
@@ -74,10 +73,10 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ParseDTString (this string _onString) {
|
internal static string ParseDTString(this string _onString) {
|
||||||
|
|
||||||
var res = new Regex(@"\%([0-9]{2})\$RD.{8}(.*)...").Match(_onString);
|
var res = new Regex(@"\%([0-9]{2})\$RD.{8}(.*)...").Match(_onString);
|
||||||
if(res.Success) {
|
if (res.Success) {
|
||||||
string val = res.Groups[2].Value;
|
string val = res.Groups[2].Value;
|
||||||
return val.GetStringFromAsciiHex()?.Trim();
|
return val.GetStringFromAsciiHex()?.Trim();
|
||||||
}
|
}
|
||||||
@@ -85,9 +84,9 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ReverseByteOrder (this string _onString) {
|
internal static string ReverseByteOrder(this string _onString) {
|
||||||
|
|
||||||
if(_onString == null) return null;
|
if (_onString == null) return null;
|
||||||
|
|
||||||
//split into 2 chars
|
//split into 2 chars
|
||||||
var stringBytes = _onString.SplitInParts(2).ToList();
|
var stringBytes = _onString.SplitInParts(2).ToList();
|
||||||
@@ -98,7 +97,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static IEnumerable<String> SplitInParts (this string s, int partLength) {
|
internal static IEnumerable<String> SplitInParts(this string s, int partLength) {
|
||||||
|
|
||||||
if (s == null)
|
if (s == null)
|
||||||
throw new ArgumentNullException(nameof(s));
|
throw new ArgumentNullException(nameof(s));
|
||||||
@@ -110,7 +109,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string BuildDTString (this string _inString, short _stringReservedSize) {
|
internal static string BuildDTString(this string _inString, short _stringReservedSize) {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
@@ -140,7 +139,7 @@ namespace MewtocolNet {
|
|||||||
sb.Append(reservedSizeBytes);
|
sb.Append(reservedSizeBytes);
|
||||||
//string count actual bytes
|
//string count actual bytes
|
||||||
sb.Append(sizeBytes);
|
sb.Append(sizeBytes);
|
||||||
|
|
||||||
|
|
||||||
sb.Append(hexstring);
|
sb.Append(hexstring);
|
||||||
|
|
||||||
@@ -148,18 +147,18 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static string GetStringFromAsciiHex (this string input) {
|
internal static string GetStringFromAsciiHex(this string input) {
|
||||||
if (input.Length % 2 != 0)
|
if (input.Length % 2 != 0)
|
||||||
return null;
|
return null;
|
||||||
byte[] bytes = new byte[input.Length / 2];
|
byte[] bytes = new byte[input.Length / 2];
|
||||||
for (int i = 0; i < input.Length; i += 2) {
|
for (int i = 0; i < input.Length; i += 2) {
|
||||||
String hex = input.Substring(i, 2);
|
String hex = input.Substring(i, 2);
|
||||||
bytes[i/2] = Convert.ToByte(hex, 16);
|
bytes[i / 2] = Convert.ToByte(hex, 16);
|
||||||
}
|
}
|
||||||
return Encoding.ASCII.GetString(bytes);
|
return Encoding.ASCII.GetString(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetAsciiHexFromString (this string input) {
|
internal static string GetAsciiHexFromString(this string input) {
|
||||||
var bytes = new ASCIIEncoding().GetBytes(input);
|
var bytes = new ASCIIEncoding().GetBytes(input);
|
||||||
return bytes.ToHexString();
|
return bytes.ToHexString();
|
||||||
}
|
}
|
||||||
@@ -173,7 +172,7 @@ namespace MewtocolNet {
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string ToHexString (this byte[] arr) {
|
internal static string ToHexString(this byte[] arr) {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < arr.Length; i++) {
|
for (int i = 0; i < arr.Length; i++) {
|
||||||
@@ -184,17 +183,17 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static byte[] BigToMixedEndian (this byte[] arr) {
|
internal static byte[] BigToMixedEndian(this byte[] arr) {
|
||||||
|
|
||||||
List<byte> oldBL = new List<byte>(arr);
|
List<byte> oldBL = new List<byte>(arr);
|
||||||
|
|
||||||
List<byte> tempL = new List<byte>();
|
List<byte> tempL = new List<byte>();
|
||||||
|
|
||||||
//make the input list even
|
//make the input list even
|
||||||
if(arr.Length % 2 != 0)
|
if (arr.Length % 2 != 0)
|
||||||
oldBL.Add((byte)0);
|
oldBL.Add((byte)0);
|
||||||
|
|
||||||
for (int i = 0; i < oldBL.Count; i+=2) {
|
for (int i = 0; i < oldBL.Count; i += 2) {
|
||||||
byte firstByte = oldBL[i];
|
byte firstByte = oldBL[i];
|
||||||
byte lastByte = oldBL[i + 1];
|
byte lastByte = oldBL[i + 1];
|
||||||
tempL.Add(lastByte);
|
tempL.Add(lastByte);
|
||||||
@@ -206,7 +205,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool IsDoubleNumericRegisterType (this Type type) {
|
internal static bool IsDoubleNumericRegisterType(this Type type) {
|
||||||
|
|
||||||
//Type[] singles = new Type[] {
|
//Type[] singles = new Type[] {
|
||||||
// typeof(short),
|
// typeof(short),
|
||||||
@@ -224,7 +223,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool IsNumericSupportedType (this Type type) {
|
internal static bool IsNumericSupportedType(this Type type) {
|
||||||
|
|
||||||
Type[] supported = new Type[] {
|
Type[] supported = new Type[] {
|
||||||
typeof(short),
|
typeof(short),
|
||||||
@@ -242,7 +241,7 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the register type is non numeric
|
/// Checks if the register type is non numeric
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static bool IsBoolean (this RegisterType type) {
|
internal static bool IsBoolean(this RegisterType type) {
|
||||||
|
|
||||||
return type == RegisterType.X || type == RegisterType.Y || type == RegisterType.R;
|
return type == RegisterType.X || type == RegisterType.Y || type == RegisterType.R;
|
||||||
|
|
||||||
@@ -251,7 +250,7 @@ namespace MewtocolNet {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the register type is an physical in or output of the plc
|
/// Checks if the register type is an physical in or output of the plc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static bool IsPhysicalInOutType (this RegisterType type) {
|
internal static bool IsPhysicalInOutType(this RegisterType type) {
|
||||||
|
|
||||||
return type == RegisterType.X || type == RegisterType.Y;
|
return type == RegisterType.X || type == RegisterType.Y;
|
||||||
|
|
||||||
@@ -1,27 +1,21 @@
|
|||||||
|
using MewtocolNet.Logging;
|
||||||
|
using MewtocolNet.Queue;
|
||||||
|
using MewtocolNet.RegisterAttributes;
|
||||||
|
using MewtocolNet.Subregisters;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Linq;
|
|
||||||
using MewtocolNet.Registers;
|
|
||||||
using MewtocolNet.RegisterAttributes;
|
|
||||||
using MewtocolNet.Logging;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading;
|
|
||||||
using MewtocolNet.Queue;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Timers;
|
|
||||||
using System.Data;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace MewtocolNet
|
namespace MewtocolNet {
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The PLC com interface class
|
/// The PLC com interface class
|
||||||
@@ -63,7 +57,7 @@ namespace MewtocolNet
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int PollerDelayMs {
|
public int PollerDelayMs {
|
||||||
get => pollerDelayMs;
|
get => pollerDelayMs;
|
||||||
set {
|
set {
|
||||||
pollerDelayMs = value;
|
pollerDelayMs = value;
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PollerDelayMs)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PollerDelayMs)));
|
||||||
}
|
}
|
||||||
@@ -108,8 +102,8 @@ namespace MewtocolNet
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic information about the connected PLC
|
/// Generic information about the connected PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PLCInfo PlcInfo {
|
public PLCInfo PlcInfo {
|
||||||
get => plcInfo;
|
get => plcInfo;
|
||||||
private set {
|
private set {
|
||||||
plcInfo = value;
|
plcInfo = value;
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PlcInfo)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PlcInfo)));
|
||||||
@@ -158,7 +152,7 @@ namespace MewtocolNet
|
|||||||
/// The current transmission speed in bytes per second
|
/// The current transmission speed in bytes per second
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BytesPerSecondUpstream {
|
public int BytesPerSecondUpstream {
|
||||||
get { return bytesPerSecondUpstream; }
|
get { return bytesPerSecondUpstream; }
|
||||||
private set {
|
private set {
|
||||||
bytesPerSecondUpstream = value;
|
bytesPerSecondUpstream = value;
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BytesPerSecondUpstream)));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BytesPerSecondUpstream)));
|
||||||
@@ -195,7 +189,7 @@ namespace MewtocolNet
|
|||||||
/// <param name="_ip">IP adress of the PLC</param>
|
/// <param name="_ip">IP adress of the PLC</param>
|
||||||
/// <param name="_port">Port of the PLC</param>
|
/// <param name="_port">Port of the PLC</param>
|
||||||
/// <param name="_station">Station Number of the PLC</param>
|
/// <param name="_station">Station Number of the PLC</param>
|
||||||
public MewtocolInterface (string _ip, int _port = 9094, int _station = 1) {
|
public MewtocolInterface(string _ip, int _port = 9094, int _station = 1) {
|
||||||
|
|
||||||
ip = _ip;
|
ip = _ip;
|
||||||
port = _port;
|
port = _port;
|
||||||
@@ -203,7 +197,7 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
Connected += MewtocolInterface_Connected;
|
Connected += MewtocolInterface_Connected;
|
||||||
|
|
||||||
void MewtocolInterface_Connected (PLCInfo obj) {
|
void MewtocolInterface_Connected(PLCInfo obj) {
|
||||||
|
|
||||||
if (usePoller)
|
if (usePoller)
|
||||||
AttachPoller();
|
AttachPoller();
|
||||||
@@ -237,7 +231,7 @@ namespace MewtocolNet
|
|||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="OnFailed">Gets called when an error or timeout during connection occurs</param>
|
/// <param name="OnFailed">Gets called when an error or timeout during connection occurs</param>
|
||||||
/// <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);
|
Logger.Log("Connecting to PLC...", LogLevel.Info, this);
|
||||||
|
|
||||||
@@ -258,7 +252,7 @@ namespace MewtocolNet
|
|||||||
}
|
}
|
||||||
|
|
||||||
PolledCycle += OnPollCycleDone;
|
PolledCycle += OnPollCycleDone;
|
||||||
void OnPollCycleDone () {
|
void OnPollCycleDone() {
|
||||||
OnConnected(plcinf);
|
OnConnected(plcinf);
|
||||||
PolledCycle -= OnPollCycleDone;
|
PolledCycle -= OnPollCycleDone;
|
||||||
}
|
}
|
||||||
@@ -284,7 +278,7 @@ namespace MewtocolNet
|
|||||||
/// <param name="_ip">Ip adress</param>
|
/// <param name="_ip">Ip adress</param>
|
||||||
/// <param name="_port">Port number</param>
|
/// <param name="_port">Port number</param>
|
||||||
/// <param name="_station">Station number</param>
|
/// <param name="_station">Station number</param>
|
||||||
public void ChangeConnectionSettings (string _ip, int _port, int _station = 1) {
|
public void ChangeConnectionSettings(string _ip, int _port, int _station = 1) {
|
||||||
|
|
||||||
if (IsConnected)
|
if (IsConnected)
|
||||||
throw new Exception("Cannot change the connection settings while the PLC is connected");
|
throw new Exception("Cannot change the connection settings while the PLC is connected");
|
||||||
@@ -298,7 +292,7 @@ namespace MewtocolNet
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Closes the connection all cyclic polling
|
/// Closes the connection all cyclic polling
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Disconnect () {
|
public void Disconnect() {
|
||||||
|
|
||||||
if (!IsConnected)
|
if (!IsConnected)
|
||||||
return;
|
return;
|
||||||
@@ -311,7 +305,7 @@ namespace MewtocolNet
|
|||||||
/// Attaches a poller to the interface that continously
|
/// Attaches a poller to the interface that continously
|
||||||
/// polls the registered data registers and writes the values to them
|
/// polls the registered data registers and writes the values to them
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MewtocolInterface WithPoller () {
|
public MewtocolInterface WithPoller() {
|
||||||
|
|
||||||
usePoller = true;
|
usePoller = true;
|
||||||
|
|
||||||
@@ -323,7 +317,7 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
#region TCP connection state handling
|
#region TCP connection state handling
|
||||||
|
|
||||||
private async Task ConnectTCP () {
|
private async Task ConnectTCP() {
|
||||||
|
|
||||||
if (!IPAddress.TryParse(ip, out var targetIP)) {
|
if (!IPAddress.TryParse(ip, out var targetIP)) {
|
||||||
throw new ArgumentException("The IP adress of the PLC was no valid format");
|
throw new ArgumentException("The IP adress of the PLC was no valid format");
|
||||||
@@ -331,8 +325,8 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if(HostEndpoint != null) {
|
if (HostEndpoint != null) {
|
||||||
|
|
||||||
client = new TcpClient(HostEndpoint) {
|
client = new TcpClient(HostEndpoint) {
|
||||||
ReceiveBufferSize = RecBufferSize,
|
ReceiveBufferSize = RecBufferSize,
|
||||||
NoDelay = false,
|
NoDelay = false,
|
||||||
@@ -353,12 +347,12 @@ namespace MewtocolNet
|
|||||||
var result = client.BeginConnect(targetIP, port, null, null);
|
var result = client.BeginConnect(targetIP, port, null, null);
|
||||||
var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(ConnectTimeout));
|
var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(ConnectTimeout));
|
||||||
|
|
||||||
if(!success || !client.Connected) {
|
if (!success || !client.Connected) {
|
||||||
OnMajorSocketExceptionWhileConnecting();
|
OnMajorSocketExceptionWhileConnecting();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(HostEndpoint == null) {
|
if (HostEndpoint == null) {
|
||||||
var ep = (IPEndPoint)client.Client.LocalEndPoint;
|
var ep = (IPEndPoint)client.Client.LocalEndPoint;
|
||||||
Logger.Log($"Connecting [AUTO] endpoint: {ep.Address.MapToIPv4()}:{ep.Port}", LogLevel.Verbose, this);
|
Logger.Log($"Connecting [AUTO] endpoint: {ep.Address.MapToIPv4()}:{ep.Port}", LogLevel.Verbose, this);
|
||||||
}
|
}
|
||||||
@@ -376,7 +370,7 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMajorSocketExceptionWhileConnecting () {
|
private void OnMajorSocketExceptionWhileConnecting() {
|
||||||
|
|
||||||
Logger.Log("The PLC connection timed out", LogLevel.Error, this);
|
Logger.Log("The PLC connection timed out", LogLevel.Error, this);
|
||||||
CycleTimeMs = 0;
|
CycleTimeMs = 0;
|
||||||
@@ -385,7 +379,7 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMajorSocketExceptionWhileConnected () {
|
private void OnMajorSocketExceptionWhileConnected() {
|
||||||
|
|
||||||
if (IsConnected) {
|
if (IsConnected) {
|
||||||
|
|
||||||
@@ -400,7 +394,7 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearRegisterVals () {
|
private void ClearRegisterVals() {
|
||||||
|
|
||||||
for (int i = 0; i < Registers.Count; i++) {
|
for (int i = 0; i < Registers.Count; i++) {
|
||||||
|
|
||||||
@@ -423,7 +417,7 @@ namespace MewtocolNet
|
|||||||
/// and assert some propertys with the custom <see cref="RegisterAttribute"/>.
|
/// and assert some propertys with the custom <see cref="RegisterAttribute"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="collection">A collection inherting the <see cref="RegisterCollectionBase"/> class</param>
|
/// <param name="collection">A collection inherting the <see cref="RegisterCollectionBase"/> class</param>
|
||||||
public MewtocolInterface WithRegisterCollection (RegisterCollectionBase collection) {
|
public MewtocolInterface WithRegisterCollection(RegisterCollectionBase collection) {
|
||||||
|
|
||||||
collection.PLCInterface = this;
|
collection.PLCInterface = this;
|
||||||
|
|
||||||
@@ -516,7 +510,7 @@ namespace MewtocolNet
|
|||||||
RegisterChanged += (reg) => {
|
RegisterChanged += (reg) => {
|
||||||
|
|
||||||
//register is used bitwise
|
//register is used bitwise
|
||||||
if(reg.IsUsedBitwise()) {
|
if (reg.IsUsedBitwise()) {
|
||||||
|
|
||||||
for (int i = 0; i < props.Length; i++) {
|
for (int i = 0; i < props.Length; i++) {
|
||||||
|
|
||||||
@@ -524,7 +518,7 @@ namespace MewtocolNet
|
|||||||
var bitWiseFound = prop.GetCustomAttributes(true)
|
var bitWiseFound = prop.GetCustomAttributes(true)
|
||||||
.FirstOrDefault(y => y.GetType() == typeof(RegisterAttribute) && ((RegisterAttribute)y).MemoryArea == reg.MemoryAddress);
|
.FirstOrDefault(y => y.GetType() == typeof(RegisterAttribute) && ((RegisterAttribute)y).MemoryArea == reg.MemoryAddress);
|
||||||
|
|
||||||
if(bitWiseFound != null) {
|
if (bitWiseFound != null) {
|
||||||
|
|
||||||
var casted = (RegisterAttribute)bitWiseFound;
|
var casted = (RegisterAttribute)bitWiseFound;
|
||||||
var bitIndex = casted.AssignedBitIndex;
|
var bitIndex = casted.AssignedBitIndex;
|
||||||
@@ -534,13 +528,13 @@ namespace MewtocolNet
|
|||||||
if (reg is NRegister<short> reg16) {
|
if (reg is NRegister<short> reg16) {
|
||||||
var bytes = BitConverter.GetBytes((short)reg16.Value);
|
var bytes = BitConverter.GetBytes((short)reg16.Value);
|
||||||
bitAr = new BitArray(bytes);
|
bitAr = new BitArray(bytes);
|
||||||
} else if(reg is NRegister<int> reg32) {
|
} else if (reg is NRegister<int> reg32) {
|
||||||
var bytes = BitConverter.GetBytes((int)reg32.Value);
|
var bytes = BitConverter.GetBytes((int)reg32.Value);
|
||||||
bitAr = new BitArray(bytes);
|
bitAr = new BitArray(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitAr != null && bitIndex < bitAr.Length && bitIndex >= 0) {
|
if (bitAr != null && bitIndex < bitAr.Length && bitIndex >= 0) {
|
||||||
|
|
||||||
//set the specific bit index if needed
|
//set the specific bit index if needed
|
||||||
prop.SetValue(collection, bitAr[bitIndex]);
|
prop.SetValue(collection, bitAr[bitIndex]);
|
||||||
collection.TriggerPropertyChanged(prop.Name);
|
collection.TriggerPropertyChanged(prop.Name);
|
||||||
@@ -550,7 +544,7 @@ namespace MewtocolNet
|
|||||||
//set the specific bit array if needed
|
//set the specific bit array if needed
|
||||||
prop.SetValue(collection, bitAr);
|
prop.SetValue(collection, bitAr);
|
||||||
collection.TriggerPropertyChanged(prop.Name);
|
collection.TriggerPropertyChanged(prop.Name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -558,7 +552,7 @@ namespace MewtocolNet
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//updating normal properties
|
//updating normal properties
|
||||||
var foundToUpdate = props.FirstOrDefault(x => x.Name == reg.Name);
|
var foundToUpdate = props.FirstOrDefault(x => x.Name == reg.Name);
|
||||||
|
|
||||||
@@ -576,13 +570,13 @@ namespace MewtocolNet
|
|||||||
if (registerAttr.AssignedBitIndex == -1) {
|
if (registerAttr.AssignedBitIndex == -1) {
|
||||||
|
|
||||||
HashSet<Type> NumericTypes = new HashSet<Type> {
|
HashSet<Type> NumericTypes = new HashSet<Type> {
|
||||||
typeof(bool),
|
typeof(bool),
|
||||||
typeof(short),
|
typeof(short),
|
||||||
typeof(ushort),
|
typeof(ushort),
|
||||||
typeof(int),
|
typeof(int),
|
||||||
typeof(uint),
|
typeof(uint),
|
||||||
typeof(float),
|
typeof(float),
|
||||||
typeof(TimeSpan),
|
typeof(TimeSpan),
|
||||||
typeof(string)
|
typeof(string)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -625,7 +619,7 @@ namespace MewtocolNet
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="registerName">The name the register was given to or a property name from the RegisterCollection class</param>
|
/// <param name="registerName">The name the register was given to or a property name from the RegisterCollection class</param>
|
||||||
/// <param name="value">The value to write to the register</param>
|
/// <param name="value">The value to write to the register</param>
|
||||||
public void SetRegister (string registerName, object value) {
|
public void SetRegister(string registerName, object value) {
|
||||||
|
|
||||||
var foundRegister = GetAllRegisters().FirstOrDefault(x => x.Name == registerName);
|
var foundRegister = GetAllRegisters().FirstOrDefault(x => x.Name == registerName);
|
||||||
|
|
||||||
@@ -642,7 +636,7 @@ namespace MewtocolNet
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="registerName">The name the register was given to or a property name from the RegisterCollection class</param>
|
/// <param name="registerName">The name the register was given to or a property name from the RegisterCollection class</param>
|
||||||
/// <param name="value">The value to write to the register</param>
|
/// <param name="value">The value to write to the register</param>
|
||||||
public async Task<bool> SetRegisterAsync (string registerName, object value) {
|
public async Task<bool> SetRegisterAsync(string registerName, object value) {
|
||||||
|
|
||||||
var foundRegister = GetAllRegisters().FirstOrDefault(x => x.Name == registerName);
|
var foundRegister = GetAllRegisters().FirstOrDefault(x => x.Name == registerName);
|
||||||
|
|
||||||
@@ -711,7 +705,7 @@ namespace MewtocolNet
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="_msg">MEWTOCOL Formatted request string ex: %01#RT</param>
|
/// <param name="_msg">MEWTOCOL Formatted request string ex: %01#RT</param>
|
||||||
/// <returns>Returns the result</returns>
|
/// <returns>Returns the result</returns>
|
||||||
public async Task<CommandResult> SendCommandAsync (string _msg) {
|
public async Task<CommandResult> SendCommandAsync(string _msg) {
|
||||||
|
|
||||||
_msg = _msg.BuildBCCFrame();
|
_msg = _msg.BuildBCCFrame();
|
||||||
_msg += "\r";
|
_msg += "\r";
|
||||||
@@ -720,10 +714,10 @@ namespace MewtocolNet
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
queuedMessages++;
|
queuedMessages++;
|
||||||
|
|
||||||
var response = await queue.Enqueue(() => SendSingleBlock(_msg));
|
var response = await queue.Enqueue(() => SendSingleBlock(_msg));
|
||||||
|
|
||||||
if (queuedMessages > 0)
|
if (queuedMessages > 0)
|
||||||
queuedMessages--;
|
queuedMessages--;
|
||||||
|
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
@@ -739,7 +733,7 @@ namespace MewtocolNet
|
|||||||
Match m = errorcheck.Match(response.ToString());
|
Match m = errorcheck.Match(response.ToString());
|
||||||
if (m.Success) {
|
if (m.Success) {
|
||||||
string eCode = m.Groups[1].Value;
|
string eCode = m.Groups[1].Value;
|
||||||
string eDes = Links.CodeDescriptions.Error[Convert.ToInt32(eCode)];
|
string eDes = CodeDescriptions.Error[Convert.ToInt32(eCode)];
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine($"Response is: {response}");
|
Console.WriteLine($"Response is: {response}");
|
||||||
Logger.Log($"Error on command {_msg.Replace("\r", "")} the PLC returned error code: {eCode}, {eDes}", LogLevel.Error);
|
Logger.Log($"Error on command {_msg.Replace("\r", "")} the PLC returned error code: {eCode}, {eDes}", LogLevel.Error);
|
||||||
@@ -767,9 +761,9 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> SendSingleBlock (string _blockString) {
|
private async Task<string> SendSingleBlock(string _blockString) {
|
||||||
|
|
||||||
if (client == null || !client.Connected ) {
|
if (client == null || !client.Connected) {
|
||||||
await ConnectTCP();
|
await ConnectTCP();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,11 +773,11 @@ namespace MewtocolNet
|
|||||||
var message = _blockString.ToHexASCIIBytes();
|
var message = _blockString.ToHexASCIIBytes();
|
||||||
|
|
||||||
//time measuring
|
//time measuring
|
||||||
if(speedStopwatchUpstr == null) {
|
if (speedStopwatchUpstr == null) {
|
||||||
speedStopwatchUpstr = Stopwatch.StartNew();
|
speedStopwatchUpstr = Stopwatch.StartNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(speedStopwatchUpstr.Elapsed.TotalSeconds >= 1) {
|
if (speedStopwatchUpstr.Elapsed.TotalSeconds >= 1) {
|
||||||
speedStopwatchUpstr.Restart();
|
speedStopwatchUpstr.Restart();
|
||||||
bytesTotalCountedUpstream = 0;
|
bytesTotalCountedUpstream = 0;
|
||||||
}
|
}
|
||||||
@@ -846,15 +840,15 @@ namespace MewtocolNet
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!string.IsNullOrEmpty(response.ToString())) {
|
if (!string.IsNullOrEmpty(response.ToString())) {
|
||||||
|
|
||||||
Logger.Log($"<-- IN MSG: {response}", LogLevel.Critical, this);
|
Logger.Log($"<-- IN MSG: {response}", LogLevel.Critical, this);
|
||||||
|
|
||||||
bytesTotalCountedDownstream += Encoding.ASCII.GetByteCount(response.ToString());
|
bytesTotalCountedDownstream += Encoding.ASCII.GetByteCount(response.ToString());
|
||||||
|
|
||||||
var perSecDownstream = (double)((bytesTotalCountedDownstream / speedStopwatchDownstr.Elapsed.TotalMilliseconds) * 1000);
|
var perSecDownstream = (double)((bytesTotalCountedDownstream / speedStopwatchDownstr.Elapsed.TotalMilliseconds) * 1000);
|
||||||
|
|
||||||
if(perSecUpstream <= 10000)
|
if (perSecUpstream <= 10000)
|
||||||
BytesPerSecondDownstream = (int)Math.Round(perSecUpstream, MidpointRounding.AwayFromZero);
|
BytesPerSecondDownstream = (int)Math.Round(perSecUpstream, MidpointRounding.AwayFromZero);
|
||||||
|
|
||||||
return response.ToString();
|
return response.ToString();
|
||||||
@@ -872,7 +866,7 @@ namespace MewtocolNet
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes the current interface and clears all its members
|
/// Disposes the current interface and clears all its members
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose () {
|
public void Dispose() {
|
||||||
|
|
||||||
if (Disposed) return;
|
if (Disposed) return;
|
||||||
|
|
||||||
@@ -891,7 +885,7 @@ namespace MewtocolNet
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the connection info string
|
/// Gets the connection info string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetConnectionPortInfo () {
|
public string GetConnectionPortInfo() {
|
||||||
|
|
||||||
return $"{IpAddress}:{Port}";
|
return $"{IpAddress}:{Port}";
|
||||||
|
|
||||||
@@ -901,5 +895,4 @@ namespace MewtocolNet
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
|
using MewtocolNet.Logging;
|
||||||
|
using MewtocolNet.PLCEnums;
|
||||||
|
using MewtocolNet.Subregisters;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Text;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MewtocolNet.Registers;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Globalization;
|
|
||||||
using MewtocolNet.Logging;
|
|
||||||
|
|
||||||
namespace MewtocolNet {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
public partial class MewtocolInterface {
|
public partial class MewtocolInterface {
|
||||||
|
|
||||||
#region PLC info getters
|
#region PLC info getters
|
||||||
@@ -20,14 +18,14 @@ namespace MewtocolNet {
|
|||||||
/// Gets generic information about the PLC
|
/// Gets generic information about the PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A PLCInfo class</returns>
|
/// <returns>A PLCInfo class</returns>
|
||||||
public async Task<PLCInfo> GetPLCInfoAsync () {
|
public async Task<PLCInfo> GetPLCInfoAsync() {
|
||||||
var resu = await SendCommandAsync("%01#RT");
|
var resu = await SendCommandAsync("%01#RT");
|
||||||
if(!resu.Success) return null;
|
if (!resu.Success) return null;
|
||||||
|
|
||||||
var reg = new Regex(@"\%([0-9]{2})\$RT([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{4})..", RegexOptions.IgnoreCase);
|
var reg = new Regex(@"\%([0-9]{2})\$RT([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{4})..", RegexOptions.IgnoreCase);
|
||||||
Match m = reg.Match(resu.Response);
|
Match m = reg.Match(resu.Response);
|
||||||
|
|
||||||
if(m.Success) {
|
if (m.Success) {
|
||||||
|
|
||||||
string station = m.Groups[1].Value;
|
string station = m.Groups[1].Value;
|
||||||
string cpu = m.Groups[2].Value;
|
string cpu = m.Groups[2].Value;
|
||||||
@@ -48,7 +46,7 @@ namespace MewtocolNet {
|
|||||||
PlcInfo = retInfo;
|
PlcInfo = retInfo;
|
||||||
return retInfo;
|
return retInfo;
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +59,7 @@ namespace MewtocolNet {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mode">The mode to change to</param>
|
/// <param name="mode">The mode to change to</param>
|
||||||
/// <returns>The success state of the write operation</returns>
|
/// <returns>The success state of the write operation</returns>
|
||||||
public async Task<bool> SetOperationMode (OPMode mode) {
|
public async Task<bool> SetOperationMode(OPMode mode) {
|
||||||
|
|
||||||
string modeChar = mode == OPMode.Prog ? "P" : "R";
|
string modeChar = mode == OPMode.Prog ? "P" : "R";
|
||||||
|
|
||||||
@@ -90,7 +88,7 @@ namespace MewtocolNet {
|
|||||||
/// /// <param name="start">start address of the array</param>
|
/// /// <param name="start">start address of the array</param>
|
||||||
/// <param name="byteArr"></param>
|
/// <param name="byteArr"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> WriteByteRange (int start, byte[] byteArr) {
|
public async Task<bool> WriteByteRange(int start, byte[] byteArr) {
|
||||||
|
|
||||||
string byteString = byteArr.BigToMixedEndian().ToHexString();
|
string byteString = byteArr.BigToMixedEndian().ToHexString();
|
||||||
var wordLength = byteArr.Length / 2;
|
var wordLength = byteArr.Length / 2;
|
||||||
@@ -114,17 +112,17 @@ namespace MewtocolNet {
|
|||||||
/// <param name="count">Number of bytes to get</param>
|
/// <param name="count">Number of bytes to get</param>
|
||||||
/// <param name="onProgress">Gets invoked when the progress changes, contains the progress as a double</param>
|
/// <param name="onProgress">Gets invoked when the progress changes, contains the progress as a double</param>
|
||||||
/// <returns>A byte array or null of there was an error</returns>
|
/// <returns>A byte array or null of there was an error</returns>
|
||||||
public async Task<byte[]> ReadByteRange (int start, int count, Action<double> onProgress = null) {
|
public async Task<byte[]> ReadByteRange(int start, int count, Action<double> onProgress = null) {
|
||||||
|
|
||||||
var byteList = new List<byte>();
|
var byteList = new List<byte>();
|
||||||
|
|
||||||
var wordLength = count / 2;
|
var wordLength = count / 2;
|
||||||
if (count % 2 != 0)
|
if (count % 2 != 0)
|
||||||
wordLength++;
|
wordLength++;
|
||||||
|
|
||||||
|
|
||||||
//read blocks of max 4 words per msg
|
//read blocks of max 4 words per msg
|
||||||
for (int i = 0; i < wordLength; i+=8) {
|
for (int i = 0; i < wordLength; i += 8) {
|
||||||
|
|
||||||
int curWordStart = start + i;
|
int curWordStart = start + i;
|
||||||
int curWordEnd = curWordStart + 7;
|
int curWordEnd = curWordStart + 7;
|
||||||
@@ -147,12 +145,12 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(onProgress != null)
|
if (onProgress != null)
|
||||||
onProgress((double)i / wordLength);
|
onProgress((double)i / wordLength);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return byteList.ToArray();
|
return byteList.ToArray();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,12 +162,12 @@ namespace MewtocolNet {
|
|||||||
/// 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>
|
||||||
public async Task<BRegisterResult> ReadBoolRegister (BRegister _toRead) {
|
public async Task<BRegisterResult> ReadBoolRegister(BRegister _toRead) {
|
||||||
|
|
||||||
string requeststring = $"%{GetStationNumber()}#RCS{_toRead.BuildMewtocolQuery()}";
|
string requeststring = $"%{GetStationNumber()}#RCS{_toRead.BuildMewtocolQuery()}";
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
if(!result.Success) {
|
if (!result.Success) {
|
||||||
return new BRegisterResult {
|
return new BRegisterResult {
|
||||||
Result = result,
|
Result = result,
|
||||||
Register = _toRead
|
Register = _toRead
|
||||||
@@ -177,9 +175,9 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resultBool = result.Response.ParseRCSingleBit();
|
var resultBool = result.Response.ParseRCSingleBit();
|
||||||
if(resultBool != null) {
|
if (resultBool != null) {
|
||||||
_toRead.SetValueFromPLC(resultBool.Value);
|
_toRead.SetValueFromPLC(resultBool.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var finalRes = new BRegisterResult {
|
var finalRes = new BRegisterResult {
|
||||||
Result = result,
|
Result = result,
|
||||||
@@ -196,13 +194,13 @@ namespace MewtocolNet {
|
|||||||
/// <param name="_toWrite">The register to write to</param>
|
/// <param name="_toWrite">The register to write to</param>
|
||||||
/// <param name="value">The value to write</param>
|
/// <param name="value">The value to write</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) {
|
public async Task<bool> WriteBoolRegister(BRegister _toWrite, bool value) {
|
||||||
|
|
||||||
string requeststring = $"%{GetStationNumber()}#WCS{_toWrite.BuildMewtocolQuery()}{(value ? "1" : "0")}";
|
string requeststring = $"%{GetStationNumber()}#WCS{_toWrite.BuildMewtocolQuery()}{(value ? "1" : "0")}";
|
||||||
|
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WC");
|
return result.Success && result.Response.StartsWith($"%{GetStationNumber()}$WC");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +214,7 @@ namespace MewtocolNet {
|
|||||||
/// <typeparam name="T">Type of number (short, ushort, int, uint, float)</typeparam>
|
/// <typeparam name="T">Type of number (short, ushort, int, uint, float)</typeparam>
|
||||||
/// <param name="_toRead">The register to read</param>
|
/// <param name="_toRead">The register to read</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) {
|
public async Task<NRegisterResult<T>> ReadNumRegister<T>(NRegister<T> _toRead) {
|
||||||
|
|
||||||
Type numType = typeof(T);
|
Type numType = typeof(T);
|
||||||
|
|
||||||
@@ -231,7 +229,7 @@ namespace MewtocolNet {
|
|||||||
if (!result.Success || string.IsNullOrEmpty(result.Response)) {
|
if (!result.Success || string.IsNullOrEmpty(result.Response)) {
|
||||||
return failedResult;
|
return failedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numType == typeof(short)) {
|
if (numType == typeof(short)) {
|
||||||
|
|
||||||
var resultBytes = result.Response.ParseDTByteString(4).ReverseByteOrder();
|
var resultBytes = result.Response.ParseDTByteString(4).ReverseByteOrder();
|
||||||
@@ -301,7 +299,7 @@ namespace MewtocolNet {
|
|||||||
/// <param name="_toWrite">The register to write</param>
|
/// <param name="_toWrite">The register to write</param>
|
||||||
/// <param name="_value">The value to write</param>
|
/// <param name="_value">The value to write</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) {
|
public async Task<bool> WriteNumRegister<T>(NRegister<T> _toWrite, T _value) {
|
||||||
|
|
||||||
byte[] toWriteVal;
|
byte[] toWriteVal;
|
||||||
Type numType = typeof(T);
|
Type numType = typeof(T);
|
||||||
@@ -339,7 +337,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WD");
|
return result.Success && result.Response.StartsWith($"%{GetStationNumber()}$WD");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +358,7 @@ namespace MewtocolNet {
|
|||||||
/// <param name="_toRead">The register to read</param>
|
/// <param name="_toRead">The register to read</param>
|
||||||
/// <param name="_stationNumber">The station number of the PLC</param>
|
/// <param name="_stationNumber">The station number of the PLC</param>
|
||||||
/// <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 = $"%{GetStationNumber()}#RD{_toRead.BuildMewtocolQuery()}";
|
string requeststring = $"%{GetStationNumber()}#RD{_toRead.BuildMewtocolQuery()}";
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
@@ -382,27 +380,27 @@ namespace MewtocolNet {
|
|||||||
public async Task<bool> WriteStringRegister(SRegister _toWrite, string _value, int _stationNumber = 1) {
|
public async Task<bool> WriteStringRegister(SRegister _toWrite, string _value, int _stationNumber = 1) {
|
||||||
|
|
||||||
if (_value == null) _value = "";
|
if (_value == null) _value = "";
|
||||||
if(_value.Length > _toWrite.ReservedSize) {
|
if (_value.Length > _toWrite.ReservedSize) {
|
||||||
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 = GetStationNumber();
|
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);
|
||||||
|
|
||||||
string requeststring = $"%{stationNum}#WD{dataArea}{dataString}";
|
string requeststring = $"%{stationNum}#WD{dataArea}{dataString}";
|
||||||
|
|
||||||
var result = await SendCommandAsync(requeststring);
|
var result = await SendCommandAsync(requeststring);
|
||||||
|
|
||||||
|
|
||||||
return result.Success && result.Response.StartsWith($"%{ GetStationNumber()}$WD");
|
return result.Success && result.Response.StartsWith($"%{GetStationNumber()}$WD");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
|
|
||||||
internal string GetStationNumber () {
|
internal string GetStationNumber() {
|
||||||
|
|
||||||
return StationNumber.ToString().PadLeft(2, '0');
|
return StationNumber.ToString().PadLeft(2, '0');
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace MewtocolNet {
|
namespace MewtocolNet.PLCEnums {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CPU type of the PLC
|
/// CPU type of the PLC
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
namespace MewtocolNet.PLCEnums {
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MewtocolNet {
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CPU type of the PLC
|
/// CPU type of the PLC
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains generic information about the plc
|
/// Contains generic information about the plc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -7,26 +7,26 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains information about the PLCs cpu
|
/// Contains information about the PLCs cpu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CpuInfo CpuInformation {get;set;}
|
public CpuInfo CpuInformation { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains information about the PLCs operation modes
|
/// Contains information about the PLCs operation modes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PLCMode OperationMode {get;set;}
|
public PLCMode OperationMode { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current error code of the PLC
|
/// Current error code of the PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ErrorCode {get;set;}
|
public string ErrorCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current station number of the PLC
|
/// Current station number of the PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int StationNumber { get;set;}
|
public int StationNumber { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates a string containing some of the most important informations
|
/// Generates a string containing some of the most important informations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override string ToString () {
|
public override string ToString() {
|
||||||
|
|
||||||
return $"Type: {CpuInformation.Cputype},\n" +
|
return $"Type: {CpuInformation.Cputype},\n" +
|
||||||
$"Capacity: {CpuInformation.ProgramCapacity}k\n" +
|
$"Capacity: {CpuInformation.ProgramCapacity}k\n" +
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All modes
|
/// All modes
|
||||||
@@ -43,7 +43,7 @@ namespace MewtocolNet.Registers {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets operation mode from 2 digit hex number
|
/// Gets operation mode from 2 digit hex number
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static PLCMode BuildFromHex (string _hexString) {
|
internal static PLCMode BuildFromHex(string _hexString) {
|
||||||
|
|
||||||
string lower = Convert.ToString(Convert.ToInt32(_hexString.Substring(0, 1)), 2).PadLeft(4, '0');
|
string lower = Convert.ToString(Convert.ToInt32(_hexString.Substring(0, 1)), 2).PadLeft(4, '0');
|
||||||
string higher = Convert.ToString(Convert.ToInt32(_hexString.Substring(1, 1)), 2).PadLeft(4, '0');
|
string higher = Convert.ToString(Convert.ToInt32(_hexString.Substring(1, 1)), 2).PadLeft(4, '0');
|
||||||
@@ -87,6 +87,7 @@ namespace MewtocolNet.Registers {
|
|||||||
return retMode;
|
return retMode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace MewtocolNet.Queue {
|
|||||||
readonly object _locker = new object();
|
readonly object _locker = new object();
|
||||||
readonly WeakReference<Task> _lastTask = new WeakReference<Task>(null);
|
readonly WeakReference<Task> _lastTask = new WeakReference<Task>(null);
|
||||||
|
|
||||||
internal Task<T> Enqueue<T> (Func<Task<T>> asyncFunction) {
|
internal Task<T> Enqueue<T>(Func<Task<T>> asyncFunction) {
|
||||||
lock (_locker) {
|
lock (_locker) {
|
||||||
Task lastTask;
|
Task lastTask;
|
||||||
Task<T> resultTask;
|
Task<T> resultTask;
|
||||||
|
|||||||
16
MewtocolNet/RegisterAttributes/BitCount.cs
Normal file
16
MewtocolNet/RegisterAttributes/BitCount.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace MewtocolNet.RegisterAttributes {
|
||||||
|
/// <summary>
|
||||||
|
/// The size of the bitwise register
|
||||||
|
/// </summary>
|
||||||
|
public enum BitCount {
|
||||||
|
/// <summary>
|
||||||
|
/// 16 bit
|
||||||
|
/// </summary>
|
||||||
|
B16,
|
||||||
|
/// <summary>
|
||||||
|
/// 32 bit
|
||||||
|
/// </summary>
|
||||||
|
B32
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,25 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MewtocolNet.RegisterAttributes {
|
namespace MewtocolNet.RegisterAttributes {
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The size of the bitwise register
|
|
||||||
/// </summary>
|
|
||||||
public enum BitCount {
|
|
||||||
/// <summary>
|
|
||||||
/// 16 bit
|
|
||||||
/// </summary>
|
|
||||||
B16,
|
|
||||||
/// <summary>
|
|
||||||
/// 32 bit
|
|
||||||
/// </summary>
|
|
||||||
B32
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the behavior of a register property
|
/// Defines the behavior of a register property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -38,10 +20,10 @@ namespace MewtocolNet.RegisterAttributes {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="memoryArea">The area in the plcs memory</param>
|
/// <param name="memoryArea">The area in the plcs memory</param>
|
||||||
/// <param name="stringLength">The max string length in the plc</param>
|
/// <param name="stringLength">The max string length in the plc</param>
|
||||||
public RegisterAttribute (int memoryArea, int stringLength = 1) {
|
public RegisterAttribute(int memoryArea, int stringLength = 1) {
|
||||||
|
|
||||||
MemoryArea = memoryArea;
|
MemoryArea = memoryArea;
|
||||||
StringLength = stringLength;
|
StringLength = stringLength;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,11 +41,11 @@ namespace MewtocolNet.RegisterAttributes {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for boolean registers
|
/// Attribute for boolean registers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RegisterAttribute (IOType type, int memoryArea, byte spAdress = 0x0) {
|
public RegisterAttribute(IOType type, int memoryArea, byte spAdress = 0x0) {
|
||||||
|
|
||||||
MemoryArea = memoryArea;
|
MemoryArea = memoryArea;
|
||||||
RegisterType = (RegisterType)(int)type;
|
RegisterType = (RegisterType)(int)type;
|
||||||
SpecialAddress = spAdress;
|
SpecialAddress = spAdress;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +54,7 @@ namespace MewtocolNet.RegisterAttributes {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="memoryArea">The area in the plcs memory</param>
|
/// <param name="memoryArea">The area in the plcs memory</param>
|
||||||
/// <param name="bitcount">The number of bits to parse</param>
|
/// <param name="bitcount">The number of bits to parse</param>
|
||||||
public RegisterAttribute (int memoryArea, BitCount bitcount) {
|
public RegisterAttribute(int memoryArea, BitCount bitcount) {
|
||||||
|
|
||||||
MemoryArea = memoryArea;
|
MemoryArea = memoryArea;
|
||||||
StringLength = 0;
|
StringLength = 0;
|
||||||
@@ -86,9 +68,9 @@ namespace MewtocolNet.RegisterAttributes {
|
|||||||
/// <param name="memoryArea">The area in the plcs memory</param>
|
/// <param name="memoryArea">The area in the plcs memory</param>
|
||||||
/// <param name="bitcount">The number of bits to parse</param>
|
/// <param name="bitcount">The number of bits to parse</param>
|
||||||
/// <param name="assignBit">The index of the bit that gets linked to the bool</param>
|
/// <param name="assignBit">The index of the bit that gets linked to the bool</param>
|
||||||
public RegisterAttribute (int memoryArea, uint assignBit, BitCount bitcount) {
|
public RegisterAttribute(int memoryArea, uint assignBit, BitCount bitcount) {
|
||||||
|
|
||||||
if(assignBit > 15 && bitcount == BitCount.B16) {
|
if (assignBit > 15 && bitcount == BitCount.B16) {
|
||||||
throw new NotSupportedException("The assignBit parameter cannot be greater than 15 in a 16 bit var");
|
throw new NotSupportedException("The assignBit parameter cannot be greater than 15 in a 16 bit var");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,15 +1,7 @@
|
|||||||
using System;
|
using System.ComponentModel;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MewtocolNet.RegisterAttributes
|
namespace MewtocolNet.RegisterAttributes {
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A register collection base with full auto read and notification support built in
|
/// A register collection base with full auto read and notification support built in
|
||||||
@@ -19,7 +11,7 @@ namespace MewtocolNet.RegisterAttributes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to its bound interface
|
/// Reference to its bound interface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MewtocolInterface PLCInterface { get; set; }
|
public MewtocolInterface PLCInterface { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whenever one of its props changes
|
/// Whenever one of its props changes
|
||||||
@@ -30,7 +22,7 @@ namespace MewtocolNet.RegisterAttributes
|
|||||||
/// Triggers a property changed event
|
/// Triggers a property changed event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="propertyName">Name of the property to trigger for</param>
|
/// <param name="propertyName">Name of the property to trigger for</param>
|
||||||
public void TriggerPropertyChanged (string propertyName = null) {
|
public void TriggerPropertyChanged(string propertyName = null) {
|
||||||
var handler = PropertyChanged;
|
var handler = PropertyChanged;
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
@@ -38,11 +30,11 @@ namespace MewtocolNet.RegisterAttributes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use this on the setter method of a property to enable automatic property register writing
|
/// Use this on the setter method of a property to enable automatic property register writing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AutoSetter<T> (object value, ref T privateField, [CallerMemberName] string propName = null) {
|
public void AutoSetter<T>(object value, ref T privateField, [CallerMemberName] string propName = null) {
|
||||||
|
|
||||||
PLCInterface.PropertyRegisterWasSet(propName, value);
|
PLCInterface.PropertyRegisterWasSet(propName, value);
|
||||||
|
|
||||||
if(value is IRegister reg) {
|
if (value is IRegister reg) {
|
||||||
|
|
||||||
privateField = (T)reg.Value;
|
privateField = (T)reg.Value;
|
||||||
return;
|
return;
|
||||||
@@ -57,14 +49,14 @@ namespace MewtocolNet.RegisterAttributes
|
|||||||
/// Gets called when the register collection base was linked to its parent mewtocol interface
|
/// Gets called when the register collection base was linked to its parent mewtocol interface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plc">The parent interface</param>
|
/// <param name="plc">The parent interface</param>
|
||||||
public virtual void OnInterfaceLinked (MewtocolInterface plc) { }
|
public virtual void OnInterfaceLinked(MewtocolInterface plc) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets called when the register collection base was linked to its parent mewtocol interface
|
/// Gets called when the register collection base was linked to its parent mewtocol interface
|
||||||
/// and the plc connection is established
|
/// and the plc connection is established
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plc">The parent interface</param>
|
/// <param name="plc">The parent interface</param>
|
||||||
public virtual void OnInterfaceLinkedAndOnline (MewtocolInterface plc) { }
|
public virtual void OnInterfaceLinkedAndOnline(MewtocolInterface plc) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
using System;
|
namespace MewtocolNet.RegisterBuilding {
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MewtocolNet.Mewtocol {
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains useful tools for register creation
|
/// Contains useful tools for register creation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -15,12 +11,14 @@ namespace MewtocolNet.Mewtocol {
|
|||||||
/// <param name="name">The name, fe. DT100</param>
|
/// <param name="name">The name, fe. DT100</param>
|
||||||
/// <param name="reg">An <see cref="IRegister"/> or null if </param>
|
/// <param name="reg">An <see cref="IRegister"/> or null if </param>
|
||||||
/// <returns>True if successfully parsed</returns>
|
/// <returns>True if successfully parsed</returns>
|
||||||
//public static bool TryBuildFromName (string name, out IRegister reg) {
|
public static bool TryBuildFromName(string name, out IRegister reg) {
|
||||||
|
|
||||||
|
reg = null;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace MewtocolNet {
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MewtocolNet {
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The register prefixed type
|
/// The register prefixed type
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
namespace MewtocolNet {
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The formatted result of a ascii command
|
/// The formatted result of a ascii command
|
||||||
@@ -14,19 +8,19 @@ namespace MewtocolNet.Registers {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Success state of the message
|
/// Success state of the message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Success {get;set;}
|
public bool Success { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Response text of the message
|
/// Response text of the message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Response {get;set;}
|
public string Response { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Error code of the message
|
/// Error code of the message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Error {get;set;}
|
public string Error { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Error text of the message
|
/// Error text of the message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ErrorDescription {get;set;}
|
public string ErrorDescription { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using MewtocolNet;
|
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet.Subregisters {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a register containing a boolean
|
/// Defines a register containing a boolean
|
||||||
@@ -21,7 +19,7 @@ namespace MewtocolNet.Registers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
internal RegisterType RegType { get; private set; }
|
internal RegisterType RegType { get; private set; }
|
||||||
|
|
||||||
internal Type collectionType;
|
internal Type collectionType;
|
||||||
|
|
||||||
@@ -64,12 +62,12 @@ namespace MewtocolNet.Registers {
|
|||||||
/// <param name="_name">The custom name</param>
|
/// <param name="_name">The custom name</param>
|
||||||
/// <exception cref="NotSupportedException"></exception>
|
/// <exception cref="NotSupportedException"></exception>
|
||||||
/// <exception cref="Exception"></exception>
|
/// <exception cref="Exception"></exception>
|
||||||
public BRegister (IOType _io, byte _spAddress = 0x0, int _areaAdress = 0, string _name = null) {
|
public BRegister(IOType _io, byte _spAddress = 0x0, int _areaAdress = 0, string _name = null) {
|
||||||
|
|
||||||
if (_areaAdress < 0)
|
if (_areaAdress < 0)
|
||||||
throw new NotSupportedException("The area address cant be negative");
|
throw new NotSupportedException("The area address cant be negative");
|
||||||
|
|
||||||
if(_io == IOType.R && _areaAdress >= 512)
|
if (_io == IOType.R && _areaAdress >= 512)
|
||||||
throw new NotSupportedException("R area addresses cant be greater than 511");
|
throw new NotSupportedException("R area addresses cant be greater than 511");
|
||||||
|
|
||||||
if ((_io == IOType.X || _io == IOType.Y) && _areaAdress >= 110)
|
if ((_io == IOType.X || _io == IOType.Y) && _areaAdress >= 110)
|
||||||
@@ -78,7 +76,7 @@ namespace MewtocolNet.Registers {
|
|||||||
if (_spAddress > 0xF)
|
if (_spAddress > 0xF)
|
||||||
throw new NotSupportedException("Special address cant be greater 15 or 0xF");
|
throw new NotSupportedException("Special address cant be greater 15 or 0xF");
|
||||||
|
|
||||||
memoryAddress = (int)_areaAdress;
|
memoryAddress = _areaAdress;
|
||||||
specialAddress = _spAddress;
|
specialAddress = _spAddress;
|
||||||
name = _name;
|
name = _name;
|
||||||
|
|
||||||
@@ -96,7 +94,7 @@ namespace MewtocolNet.Registers {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builds the register area name
|
/// Builds the register area name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BuildMewtocolQuery () {
|
public string BuildMewtocolQuery() {
|
||||||
|
|
||||||
//build area code from register type
|
//build area code from register type
|
||||||
StringBuilder asciistring = new StringBuilder(RegType.ToString());
|
StringBuilder asciistring = new StringBuilder(RegType.ToString());
|
||||||
@@ -111,12 +109,12 @@ namespace MewtocolNet.Registers {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetValueFromPLC (bool val) {
|
internal void SetValueFromPLC(bool val) {
|
||||||
|
|
||||||
lastValue = val;
|
lastValue = val;
|
||||||
TriggerChangedEvnt(this);
|
TriggerChangedEvnt(this);
|
||||||
TriggerNotifyChange();
|
TriggerNotifyChange();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetStartingMemoryArea() {
|
public string GetStartingMemoryArea() {
|
||||||
@@ -149,7 +147,7 @@ namespace MewtocolNet.Registers {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(MemoryAddress > 0 && SpecialAddress != 0) {
|
if (MemoryAddress > 0 && SpecialAddress != 0) {
|
||||||
|
|
||||||
return $"{GetRegisterString()}{MemoryAddress}{spAdressEnd}";
|
return $"{GetRegisterString()}{MemoryAddress}{spAdressEnd}";
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet.Subregisters {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Result for a boolean register
|
/// Result for a boolean register
|
||||||
@@ -2,16 +2,15 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet.Subregisters {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a register containing a number
|
/// Defines a register containing a number
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of the numeric value</typeparam>
|
/// <typeparam name="T">The type of the numeric value</typeparam>
|
||||||
public class NRegister<T> : IRegister {
|
public class NRegister<T> : IRegister {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets called whenever the value was changed
|
/// Gets called whenever the value was changed
|
||||||
@@ -64,7 +63,7 @@ namespace MewtocolNet.Registers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="_adress">Memory start adress max 99999</param>
|
/// <param name="_adress">Memory start adress max 99999</param>
|
||||||
/// <param name="_name">Name of the register</param>
|
/// <param name="_name">Name of the register</param>
|
||||||
public NRegister (int _adress, string _name = null) {
|
public NRegister(int _adress, string _name = null) {
|
||||||
|
|
||||||
if (_adress > 99999)
|
if (_adress > 99999)
|
||||||
throw new NotSupportedException("Memory adresses cant be greater than 99999");
|
throw new NotSupportedException("Memory adresses cant be greater than 99999");
|
||||||
@@ -113,18 +112,18 @@ namespace MewtocolNet.Registers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isUsedBitwise = isBitwise;
|
isUsedBitwise = isBitwise;
|
||||||
enumType = _enumType;
|
enumType = _enumType;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal NRegister<T> WithCollectionType (Type colType) {
|
internal NRegister<T> WithCollectionType(Type colType) {
|
||||||
|
|
||||||
collectionType = colType;
|
collectionType = colType;
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetValueFromPLC (object val) {
|
internal void SetValueFromPLC(object val) {
|
||||||
|
|
||||||
lastValue = (T)val;
|
lastValue = (T)val;
|
||||||
TriggerChangedEvnt(this);
|
TriggerChangedEvnt(this);
|
||||||
@@ -132,7 +131,7 @@ namespace MewtocolNet.Registers {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetStartingMemoryArea () => this.MemoryAddress.ToString();
|
public string GetStartingMemoryArea() => MemoryAddress.ToString();
|
||||||
|
|
||||||
public Type GetCollectionType() => CollectionType;
|
public Type GetCollectionType() => CollectionType;
|
||||||
|
|
||||||
@@ -141,10 +140,10 @@ namespace MewtocolNet.Registers {
|
|||||||
public string GetValueString() {
|
public string GetValueString() {
|
||||||
|
|
||||||
//is number or bitwise
|
//is number or bitwise
|
||||||
if(enumType == null) {
|
if (enumType == null) {
|
||||||
|
|
||||||
return $"{Value}{(isUsedBitwise ? $" [{GetBitwise().ToBitString()}]" : "")}";
|
return $"{Value}{(isUsedBitwise ? $" [{GetBitwise().ToBitString()}]" : "")}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//is enum
|
//is enum
|
||||||
@@ -164,11 +163,11 @@ namespace MewtocolNet.Registers {
|
|||||||
if (dict.ContainsKey(shortVal)) {
|
if (dict.ContainsKey(shortVal)) {
|
||||||
|
|
||||||
return $"{Value} ({dict[shortVal]})";
|
return $"{Value} ({dict[shortVal]})";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return $"{Value} (Missing Enum)";
|
return $"{Value} (Missing Enum)";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -228,7 +227,7 @@ namespace MewtocolNet.Registers {
|
|||||||
|
|
||||||
public string GetRegisterString() {
|
public string GetRegisterString() {
|
||||||
|
|
||||||
if(Value is short) {
|
if (Value is short) {
|
||||||
return "DT";
|
return "DT";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
namespace MewtocolNet.Subregisters {
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Result for a read/write operation
|
/// Result for a read/write operation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -20,15 +18,15 @@ namespace MewtocolNet.Registers {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Trys to get the value of there is one
|
/// Trys to get the value of there is one
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool TryGetValue (out T value) {
|
public bool TryGetValue(out T value) {
|
||||||
|
|
||||||
if(Result.Success) {
|
if (Result.Success) {
|
||||||
value = (T)Register.Value;
|
value = (T)Register.Value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
value = default(T);
|
value = default;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet.Subregisters {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a register containing a string
|
/// Defines a register containing a string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -91,7 +91,7 @@ namespace MewtocolNet.Registers {
|
|||||||
return asciistring.ToString();
|
return asciistring.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string BuildCustomIdent (int overwriteWordLength) {
|
internal string BuildCustomIdent(int overwriteWordLength) {
|
||||||
|
|
||||||
if (overwriteWordLength <= 0)
|
if (overwriteWordLength <= 0)
|
||||||
throw new Exception("overwriteWordLength cant be 0 or less");
|
throw new Exception("overwriteWordLength cant be 0 or less");
|
||||||
@@ -108,16 +108,16 @@ namespace MewtocolNet.Registers {
|
|||||||
|
|
||||||
public bool IsUsedBitwise() => false;
|
public bool IsUsedBitwise() => false;
|
||||||
|
|
||||||
internal void SetValueFromPLC (string val) {
|
internal void SetValueFromPLC(string val) {
|
||||||
|
|
||||||
lastValue = val;
|
lastValue = val;
|
||||||
|
|
||||||
TriggerChangedEvnt(this);
|
TriggerChangedEvnt(this);
|
||||||
TriggerNotifyChange();
|
TriggerNotifyChange();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetStartingMemoryArea() => this.MemoryAddress.ToString();
|
public string GetStartingMemoryArea() => MemoryAddress.ToString();
|
||||||
|
|
||||||
public string GetValueString() => Value?.ToString() ?? "";
|
public string GetValueString() => Value?.ToString() ?? "";
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ namespace MewtocolNet.Registers {
|
|||||||
|
|
||||||
public void TriggerNotifyChange() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
|
public void TriggerNotifyChange() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
|
||||||
|
|
||||||
public override string ToString () => $"{GetRegisterPLCName()} - Value: {GetValueString()}";
|
public override string ToString() => $"{GetRegisterPLCName()} - Value: {GetValueString()}";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace MewtocolNet.Registers {
|
namespace MewtocolNet.Subregisters {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The results of a string register operation
|
/// The results of a string register operation
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
using MewtocolNet;
|
using MewtocolNet;
|
||||||
using MewtocolNet.Registers;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using MewtocolNet.RegisterAttributes;
|
using MewtocolNet.RegisterAttributes;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using MewtocolNet.Subregisters;
|
||||||
|
|
||||||
namespace MewtocolTests {
|
namespace MewtocolTests
|
||||||
|
{
|
||||||
|
|
||||||
public class AutomatedPropertyRegisters {
|
public class AutomatedPropertyRegisters {
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ using Xunit;
|
|||||||
using MewtocolNet;
|
using MewtocolNet;
|
||||||
using MewtocolNet.Registers;
|
using MewtocolNet.Registers;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using MewtocolNet.Links;
|
|
||||||
|
|
||||||
namespace MewtocolTests {
|
namespace MewtocolTests
|
||||||
|
{
|
||||||
|
|
||||||
public class TestLinkedLists {
|
public class TestLinkedLists {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using MewtocolNet;
|
using MewtocolNet;
|
||||||
using MewtocolNet.Logging;
|
using MewtocolNet.Logging;
|
||||||
|
using MewtocolNet.PLCEnums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -8,7 +9,8 @@ using System.Threading.Tasks;
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace MewtocolTests {
|
namespace MewtocolTests
|
||||||
|
{
|
||||||
|
|
||||||
public class TestLivePLC {
|
public class TestLivePLC {
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ namespace MewtocolTests {
|
|||||||
|
|
||||||
//boolean
|
//boolean
|
||||||
new BRegister(IOType.R, 0, 100),
|
new BRegister(IOType.R, 0, 100),
|
||||||
|
new BRegister(IOType.R, 0, 0),
|
||||||
new BRegister(IOType.X, 5),
|
new BRegister(IOType.X, 5),
|
||||||
new BRegister(IOType.X, 0xA),
|
new BRegister(IOType.X, 0xA),
|
||||||
new BRegister(IOType.X, 0xF, 109),
|
new BRegister(IOType.X, 0xF, 109),
|
||||||
@@ -82,6 +83,7 @@ namespace MewtocolTests {
|
|||||||
|
|
||||||
//boolean
|
//boolean
|
||||||
"R100",
|
"R100",
|
||||||
|
"R0",
|
||||||
"X5",
|
"X5",
|
||||||
"XA",
|
"XA",
|
||||||
"X109F",
|
"X109F",
|
||||||
|
|||||||
229
formatting_settings
Normal file
229
formatting_settings
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
# Entfernen Sie die folgende Zeile, wenn Sie EDITORCONFIG-Einstellungen von höheren Verzeichnissen vererben möchten.
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# C#-Dateien
|
||||||
|
[*.cs]
|
||||||
|
|
||||||
|
#### Wichtige EditorConfig-Optionen ####
|
||||||
|
|
||||||
|
# Einzüge und Abstände
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
tab_width = 4
|
||||||
|
|
||||||
|
# Einstellungen für neue Zeilen
|
||||||
|
end_of_line = crlf
|
||||||
|
insert_final_newline = false
|
||||||
|
|
||||||
|
#### .NET-Codierungskonventionen ####
|
||||||
|
|
||||||
|
# Using-Direktiven organisieren
|
||||||
|
dotnet_separate_import_directive_groups = false
|
||||||
|
dotnet_sort_system_directives_first = false
|
||||||
|
file_header_template = unset
|
||||||
|
|
||||||
|
# this.- und Me.-Einstellungen
|
||||||
|
dotnet_style_qualification_for_event = false
|
||||||
|
dotnet_style_qualification_for_field = false
|
||||||
|
dotnet_style_qualification_for_method = false
|
||||||
|
dotnet_style_qualification_for_property = false
|
||||||
|
|
||||||
|
# Einstellungen für Sprachschlüsselwörter und BCL-Typen
|
||||||
|
dotnet_style_predefined_type_for_locals_parameters_members = true
|
||||||
|
dotnet_style_predefined_type_for_member_access = true
|
||||||
|
|
||||||
|
# Einstellungen für Klammern
|
||||||
|
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
|
||||||
|
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
|
||||||
|
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
|
||||||
|
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
|
||||||
|
|
||||||
|
# Einstellungen für Modifizierer
|
||||||
|
dotnet_style_require_accessibility_modifiers = for_non_interface_members
|
||||||
|
|
||||||
|
# Einstellungen für Ausdrucksebene
|
||||||
|
dotnet_style_coalesce_expression = true
|
||||||
|
dotnet_style_collection_initializer = true
|
||||||
|
dotnet_style_explicit_tuple_names = true
|
||||||
|
dotnet_style_namespace_match_folder = true
|
||||||
|
dotnet_style_null_propagation = true
|
||||||
|
dotnet_style_object_initializer = true
|
||||||
|
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||||
|
dotnet_style_prefer_auto_properties = true
|
||||||
|
dotnet_style_prefer_compound_assignment = true
|
||||||
|
dotnet_style_prefer_conditional_expression_over_assignment = true
|
||||||
|
dotnet_style_prefer_conditional_expression_over_return = true
|
||||||
|
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
|
||||||
|
dotnet_style_prefer_inferred_anonymous_type_member_names = true
|
||||||
|
dotnet_style_prefer_inferred_tuple_names = true
|
||||||
|
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
|
||||||
|
dotnet_style_prefer_simplified_boolean_expressions = true
|
||||||
|
dotnet_style_prefer_simplified_interpolation = true
|
||||||
|
|
||||||
|
# Einstellungen für Felder
|
||||||
|
dotnet_style_readonly_field = true
|
||||||
|
|
||||||
|
# Einstellungen für Parameter
|
||||||
|
dotnet_code_quality_unused_parameters = all
|
||||||
|
|
||||||
|
# Unterdrückungseinstellungen
|
||||||
|
dotnet_remove_unnecessary_suppression_exclusions = none
|
||||||
|
|
||||||
|
# Einstellungen für neue Zeilen
|
||||||
|
dotnet_style_allow_multiple_blank_lines_experimental = true
|
||||||
|
dotnet_style_allow_statement_immediately_after_block_experimental = true
|
||||||
|
|
||||||
|
#### C#-Codierungskonventionen ####
|
||||||
|
|
||||||
|
# Var-Einstellungen
|
||||||
|
csharp_style_var_elsewhere = false
|
||||||
|
csharp_style_var_for_built_in_types = false
|
||||||
|
csharp_style_var_when_type_is_apparent = false
|
||||||
|
|
||||||
|
# Ausdruckskörpermember
|
||||||
|
csharp_style_expression_bodied_accessors = true
|
||||||
|
csharp_style_expression_bodied_constructors = false
|
||||||
|
csharp_style_expression_bodied_indexers = true
|
||||||
|
csharp_style_expression_bodied_lambdas = true
|
||||||
|
csharp_style_expression_bodied_local_functions = false
|
||||||
|
csharp_style_expression_bodied_methods = false
|
||||||
|
csharp_style_expression_bodied_operators = false
|
||||||
|
csharp_style_expression_bodied_properties = true
|
||||||
|
|
||||||
|
# Einstellungen für den Musterabgleich
|
||||||
|
csharp_style_pattern_matching_over_as_with_null_check = true
|
||||||
|
csharp_style_pattern_matching_over_is_with_cast_check = true
|
||||||
|
csharp_style_prefer_extended_property_pattern = true
|
||||||
|
csharp_style_prefer_not_pattern = true
|
||||||
|
csharp_style_prefer_pattern_matching = true
|
||||||
|
csharp_style_prefer_switch_expression = true
|
||||||
|
|
||||||
|
# Einstellungen für NULL-Überprüfung
|
||||||
|
csharp_style_conditional_delegate_call = true
|
||||||
|
|
||||||
|
# Einstellungen für Modifizierer
|
||||||
|
csharp_prefer_static_local_function = true
|
||||||
|
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
|
||||||
|
csharp_style_prefer_readonly_struct = true
|
||||||
|
csharp_style_prefer_readonly_struct_member = true
|
||||||
|
|
||||||
|
# Einstellungen für Codeblöcke
|
||||||
|
csharp_prefer_braces = true
|
||||||
|
csharp_prefer_simple_using_statement = true
|
||||||
|
csharp_style_namespace_declarations = file_scoped
|
||||||
|
csharp_style_prefer_method_group_conversion = true
|
||||||
|
csharp_style_prefer_top_level_statements = true
|
||||||
|
|
||||||
|
# Einstellungen für Ausdrucksebene
|
||||||
|
csharp_prefer_simple_default_expression = true
|
||||||
|
csharp_style_deconstructed_variable_declaration = true
|
||||||
|
csharp_style_implicit_object_creation_when_type_is_apparent = true
|
||||||
|
csharp_style_inlined_variable_declaration = true
|
||||||
|
csharp_style_prefer_index_operator = true
|
||||||
|
csharp_style_prefer_local_over_anonymous_function = true
|
||||||
|
csharp_style_prefer_null_check_over_type_check = true
|
||||||
|
csharp_style_prefer_range_operator = true
|
||||||
|
csharp_style_prefer_tuple_swap = true
|
||||||
|
csharp_style_prefer_utf8_string_literals = true
|
||||||
|
csharp_style_throw_expression = true
|
||||||
|
csharp_style_unused_value_assignment_preference = discard_variable
|
||||||
|
csharp_style_unused_value_expression_statement_preference = discard_variable
|
||||||
|
|
||||||
|
# Einstellungen für using-Anweisungen
|
||||||
|
csharp_using_directive_placement = outside_namespace
|
||||||
|
|
||||||
|
# Einstellungen für neue Zeilen
|
||||||
|
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
|
||||||
|
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
|
||||||
|
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
|
||||||
|
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
|
||||||
|
csharp_style_allow_embedded_statements_on_same_line_experimental = true
|
||||||
|
|
||||||
|
#### C#-Formatierungsregeln ####
|
||||||
|
|
||||||
|
# Einstellungen für neue Zeilen
|
||||||
|
csharp_new_line_before_catch = false
|
||||||
|
csharp_new_line_before_else = false
|
||||||
|
csharp_new_line_before_finally = false
|
||||||
|
csharp_new_line_before_members_in_anonymous_types = true
|
||||||
|
csharp_new_line_before_members_in_object_initializers = true
|
||||||
|
csharp_new_line_before_open_brace = none
|
||||||
|
csharp_new_line_between_query_expression_clauses = true
|
||||||
|
|
||||||
|
# Einstellungen für Einrückung
|
||||||
|
csharp_indent_block_contents = true
|
||||||
|
csharp_indent_braces = false
|
||||||
|
csharp_indent_case_contents = false
|
||||||
|
csharp_indent_case_contents_when_block = false
|
||||||
|
csharp_indent_labels = one_less_than_current
|
||||||
|
csharp_indent_switch_labels = true
|
||||||
|
|
||||||
|
# Einstellungen für Abstände
|
||||||
|
csharp_space_after_cast = false
|
||||||
|
csharp_space_after_colon_in_inheritance_clause = true
|
||||||
|
csharp_space_after_comma = true
|
||||||
|
csharp_space_after_dot = false
|
||||||
|
csharp_space_after_keywords_in_control_flow_statements = true
|
||||||
|
csharp_space_after_semicolon_in_for_statement = true
|
||||||
|
csharp_space_around_binary_operators = before_and_after
|
||||||
|
csharp_space_around_declaration_statements = false
|
||||||
|
csharp_space_before_colon_in_inheritance_clause = true
|
||||||
|
csharp_space_before_comma = false
|
||||||
|
csharp_space_before_dot = false
|
||||||
|
csharp_space_before_open_square_brackets = false
|
||||||
|
csharp_space_before_semicolon_in_for_statement = false
|
||||||
|
csharp_space_between_empty_square_brackets = false
|
||||||
|
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||||
|
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||||
|
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||||
|
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||||
|
csharp_space_between_method_declaration_name_and_open_parenthesis = false
|
||||||
|
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||||
|
csharp_space_between_parentheses = false
|
||||||
|
csharp_space_between_square_brackets = false
|
||||||
|
|
||||||
|
# Umbrucheinstellungen
|
||||||
|
csharp_preserve_single_line_blocks = true
|
||||||
|
csharp_preserve_single_line_statements = true
|
||||||
|
|
||||||
|
#### Benennungsstile ####
|
||||||
|
|
||||||
|
# Benennungsregeln
|
||||||
|
|
||||||
|
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
|
||||||
|
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||||
|
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||||
|
|
||||||
|
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
|
||||||
|
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||||
|
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||||
|
|
||||||
|
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
|
||||||
|
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
||||||
|
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
||||||
|
|
||||||
|
# Symbolspezifikationen
|
||||||
|
|
||||||
|
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||||
|
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||||
|
dotnet_naming_symbols.interface.required_modifiers =
|
||||||
|
|
||||||
|
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||||
|
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||||
|
dotnet_naming_symbols.types.required_modifiers =
|
||||||
|
|
||||||
|
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||||
|
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||||
|
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||||
|
|
||||||
|
# Benennungsstile
|
||||||
|
|
||||||
|
dotnet_naming_style.pascal_case.required_prefix =
|
||||||
|
dotnet_naming_style.pascal_case.required_suffix =
|
||||||
|
dotnet_naming_style.pascal_case.word_separator =
|
||||||
|
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||||
|
|
||||||
|
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||||
|
dotnet_naming_style.begins_with_i.required_suffix =
|
||||||
|
dotnet_naming_style.begins_with_i.word_separator =
|
||||||
|
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||||
Reference in New Issue
Block a user