From d95652553850fa63966c684b444074e6020f8b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Wei=C3=9F?= <72068105+Sandoun@users.noreply.github.com> Date: Thu, 6 Jul 2023 22:20:01 +0200 Subject: [PATCH] Removed old examples - added instant register update if write was successful --- DocBuilder/DocBuilder.csproj | 4 + Examples/ExampleScenarios.cs | 347 ------------------ Examples/Examples.csproj | 12 - Examples/Program.cs | 134 ------- Examples/ScenarioAttribute.cs | 15 - Examples/TestRegisters.cs | 80 ---- Examples/TestRegistersEnumBitwise.cs | 106 ------ MewExplorer/MewExplorer.csproj | 7 +- MewTerminal/Commands/ScanCommand.cs | 2 +- MewTerminal/MewTerminal.csproj | 17 +- MewtocolNet.sln | 16 +- MewtocolNet/MewtocolInterfaceRequests.cs | 6 +- MewtocolNet/MewtocolNet.csproj | 26 +- MewtocolNet/PLCInfo.cs | 14 +- MewtocolNet/PublicEnums/HWInformation.cs | 47 +-- MewtocolNet/PublicEnums/OPMode.cs | 49 ++- MewtocolNet/Registers/BoolRegister.cs | 4 +- MewtocolNet/Registers/BytesRegister.cs | 4 +- MewtocolNet/Registers/NumberRegister.cs | 4 +- MewtocolNet/Registers/StringRegister.cs | 8 +- .../ExpectedPlcInformationData.cs | 2 +- MewtocolTests/MewtocolTests.csproj | 11 +- MewtocolTests/TestLivePLC.cs | 10 +- build_order.md | 7 + 24 files changed, 135 insertions(+), 797 deletions(-) delete mode 100644 Examples/ExampleScenarios.cs delete mode 100644 Examples/Examples.csproj delete mode 100644 Examples/Program.cs delete mode 100644 Examples/ScenarioAttribute.cs delete mode 100644 Examples/TestRegisters.cs delete mode 100644 Examples/TestRegistersEnumBitwise.cs create mode 100644 build_order.md diff --git a/DocBuilder/DocBuilder.csproj b/DocBuilder/DocBuilder.csproj index 70b2327..c2b9011 100644 --- a/DocBuilder/DocBuilder.csproj +++ b/DocBuilder/DocBuilder.csproj @@ -1,10 +1,14 @@ + + false + false Exe net6.0 enable enable + diff --git a/Examples/ExampleScenarios.cs b/Examples/ExampleScenarios.cs deleted file mode 100644 index 59d4bb5..0000000 --- a/Examples/ExampleScenarios.cs +++ /dev/null @@ -1,347 +0,0 @@ -using MewtocolNet.Logging; -using MewtocolNet; -using System; -using System.Reflection; -using System.Threading.Tasks; -using System.Collections; -using MewtocolNet.RegisterBuilding; -using System.Collections.Generic; -using MewtocolNet.Registers; -using System.Diagnostics; -using System.Text; -using Microsoft.Win32; -using MewtocolNet.ComCassette; -using System.Linq; -using System.Net; -using System.IO.Ports; - -namespace Examples; - -public class ExampleScenarios { - - public void SetupLogger () { - - //attaching the logger - Logger.LogLevel = LogLevel.Info; - Logger.OnNewLogMessage((date, level, msg) => { - - if (level == LogLevel.Error) Console.ForegroundColor = ConsoleColor.Red; - - Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}"); - - Console.ResetColor(); - - }); - - } - - [Scenario("Dispose and disconnect connection")] - public async Task RunDisposalAndDisconnectAsync () { - - //automatic disposal - using (var interf = Mewtocol.Ethernet("192.168.115.210")) { - - await interf.ConnectAsync(); - - if (interf.IsConnected) { - - Console.WriteLine("Opened connection"); - - await Task.Delay(5000); - - } - - } - - Console.WriteLine("Disposed, closed connection"); - - //manual close - var interf2 = Mewtocol.Ethernet("192.168.115.210"); - - await interf2.ConnectAsync(); - - if (interf2.IsConnected) { - - Console.WriteLine("Opened connection"); - - await Task.Delay(5000); - - } - - interf2.Disconnect(); - - Console.WriteLine("Disconnected, closed connection"); - - } - - [Scenario("Read all kinds of example registers over ethernet")] - public async Task RunReadTestEth () { - - //setting up a new PLC interface and register collection - var interf = Mewtocol.Ethernet("192.168.115.210").WithPoller(); - - await RunCyclicReadTest(interf); - - } - - [Scenario("Read all kinds of example registers over serial")] - public async Task RunReadTestSer () { - - //setting up a new PLC interface and register collection - var interf = Mewtocol.SerialAuto("COM4").WithPoller(); - - await RunCyclicReadTest(interf); - - } - - private async Task RunCyclicReadTest (IPlc interf) { - - //auto add all built registers to the interface - var builder = RegBuilder.ForInterface(interf); - var r0reg = builder.FromPlcRegName("R0").Build(); - builder.FromPlcRegName("R1", "Testname").Build(); - builder.FromPlcRegName("R1F").Build(); - builder.FromPlcRegName("R101A").Build(); - - var shortReg = builder.FromPlcRegName("DT35").AsPlcType(PlcVarType.INT).Build(); - builder.FromPlcRegName("DDT36").AsPlcType(PlcVarType.DINT).Build(); - builder.FromPlcRegName("DT200").AsBytes(30).Build(); - - var timeReg = builder.FromPlcRegName("DDT38").AsPlcType(PlcVarType.TIME).Build(); - var stringReg = builder.FromPlcRegName("DT40").AsPlcType(PlcVarType.STRING).Build(); - - //connect - if(interf is IPlcSerial serialPlc) { - - await serialPlc.ConnectAsync(() => { - - Console.WriteLine($"Trying config: {serialPlc.ConnectionInfo}"); - - }); - - } else { - - await interf.ConnectAsync(); - - } - - //await first register data - await interf.AwaitFirstDataCycleAsync(); - - _ = Task.Factory.StartNew(async () => { - - void setTitle() { - - Console.Title = - $"Speed UP: {interf.BytesPerSecondUpstream} B/s, " + - $"Speed DOWN: {interf.BytesPerSecondDownstream} B/s, " + - $"Poll cycle: {interf.PollerCycleDurationMs} ms, " + - $"Queued MSGs: {interf.QueuedMessages}"; - - } - - while (interf.IsConnected) { - setTitle(); - await Task.Delay(1000); - } - - setTitle(); - - }); - - while (interf.IsConnected) { - - var sw = Stopwatch.StartNew(); - - //set bool - await r0reg.WriteAsync(!(bool)r0reg.Value); - - //set random num - await shortReg.WriteAsync((short)new Random().Next(0, 100)); - await stringReg.WriteAsync($"_{DateTime.Now.Second}s_"); - - sw.Stop(); - - foreach (var reg in interf.Registers) - Console.WriteLine(reg.ToString()); - - Console.WriteLine($"Total write time for registers: {sw.Elapsed.TotalMilliseconds:N0}ms"); - - Console.WriteLine(); - - //await Task.Delay(new Random().Next(0, 10000)); - await Task.Delay(1000); - - } - - } - - [Scenario("Test read speed TCP (n) R registers")] - public async Task ReadRSpeedTest (string registerCount) { - - var preLogLevel = Logger.LogLevel; - Logger.LogLevel = LogLevel.Critical; - - //setting up a new PLC interface and register collection - using var interf = Mewtocol.Ethernet("192.168.115.210"); - - //auto add all built registers to the interface - var builder = RegBuilder.ForInterface(interf); - for (int i = 0; i < int.Parse(registerCount); i++) { - - builder.FromPlcRegName($"R{i}A").Build(); - - } - - //connect - await interf.ConnectAsync(); - - if(!interf.IsConnected) { - Console.WriteLine("Aborted, connection failed"); - return; - } - - Console.WriteLine("Poller cycle started"); - var sw = Stopwatch.StartNew(); - - int cmdCount = await interf.RunPollerCylceManual(); - - sw.Stop(); - - Console.WriteLine("Poller cycle finished"); - - Console.WriteLine($"Single frame excec time: {sw.ElapsedMilliseconds:N0}ms for {cmdCount} commands and {interf.Registers.Count()} R registers"); - - await Task.Delay(1000); - - } - - [Scenario("Test read speed Serial (n) R registers")] - public async Task ReadRSpeedTestSerial (string registerCount) { - - var preLogLevel = Logger.LogLevel; - Logger.LogLevel = LogLevel.Critical; - - //setting up a new PLC interface and register collection - //MewtocolInterfaceShared interf = Mewtocol.SerialAuto("COM4"); - using var interf = Mewtocol.Serial("COM4", BaudRate._115200, DataBits.Eight, Parity.Odd, StopBits.One); - - //auto add all built registers to the interface - var builder = RegBuilder.ForInterface(interf); - for (int i = 0; i < int.Parse(registerCount); i++) { - - builder.FromPlcRegName($"R{i}A").Build(); - - } - - //connect - await interf.ConnectAsync(); - - if (!interf.IsConnected) { - Console.WriteLine("Aborted, connection failed"); - return; - } - - Console.WriteLine("Poller cycle started"); - var sw = Stopwatch.StartNew(); - - int cmdCount = await interf.RunPollerCylceManual(); - - sw.Stop(); - - Console.WriteLine("Poller cycle finished"); - - Console.WriteLine($"Single frame excec time: {sw.ElapsedMilliseconds:N0}ms for {cmdCount} commands and {interf.Registers.Count()} R registers"); - - } - - [Scenario("Test automatic serial port setup")] - public async Task TestAutoSerialSetup () { - - var preLogLevel = Logger.LogLevel; - Logger.LogLevel = LogLevel.Critical; - - //setting up a new PLC interface and register collection - var interf = Mewtocol.SerialAuto("COM4"); - - //connect - await interf.ConnectAsync(); - - if (!interf.IsConnected) { - - Console.WriteLine("Aborted, connection failed"); - return; - - } else { - - Console.WriteLine("Serial port settings found"); - - } - - - } - - [Scenario("Find all COM5 cassettes in the network")] - public async Task FindCassettes () { - - Console.Clear(); - - var casettes = await CassetteFinder.FindClientsAsync(); - - foreach (var cassette in casettes) { - - Console.WriteLine($"{cassette.Name}"); - Console.WriteLine($"IP: {cassette.IPAddress}"); - Console.WriteLine($"Port: {cassette.Port}"); - Console.WriteLine($"DHCP: {cassette.UsesDHCP}"); - Console.WriteLine($"Subnet Mask: {cassette.SubnetMask}"); - Console.WriteLine($"Gateway: {cassette.GatewayAddress}"); - Console.WriteLine($"Mac: {cassette.MacAddress.ToHexString(":")}"); - Console.WriteLine($"Firmware: {cassette.FirmwareVersion}"); - Console.WriteLine($"Status: {cassette.Status}"); - Console.WriteLine($"Endpoint: {cassette.EndpointName} - {cassette.Endpoint.Address}"); - Console.WriteLine(); - - } - - var found = casettes.FirstOrDefault(x => x.Endpoint.Address.ToString() == "10.237.191.75"); - - if (found == null) return; - - found.IPAddress = IPAddress.Parse($"192.168.1.{new Random().Next(20, 120)}"); - found.Name = $"Rand{new Random().Next(5, 15)}"; - - await found.SendNewConfigAsync(); - - } - - [Scenario("Test")] - public async Task Test () { - - Logger.LogLevel = LogLevel.Critical; - - //fpx c14 r - var plxFpx = Mewtocol.Ethernet("192.168.178.55"); - await plxFpx.ConnectAsync(); - await ((MewtocolInterface)plxFpx).GetSystemRegister(); - - //fpx-h c30 t - var plcFpxH = Mewtocol.Ethernet("192.168.115.210"); - await plcFpxH.ConnectAsync(); - await ((MewtocolInterface)plcFpxH).GetSystemRegister(); - - //fpx-h c14 r - var plcFpxHc14 = Mewtocol.Ethernet("192.168.115.212"); - await plcFpxHc14.ConnectAsync(); - await ((MewtocolInterface)plcFpxHc14).GetSystemRegister(); - - //fpx c30 t - var plcFpxc30T = Mewtocol.Ethernet("192.168.115.213"); - await plcFpxc30T.ConnectAsync(); - await ((MewtocolInterface)plcFpxc30T).GetSystemRegister(); - - await Task.Delay(-1); - - } - -} diff --git a/Examples/Examples.csproj b/Examples/Examples.csproj deleted file mode 100644 index b9f9fac..0000000 --- a/Examples/Examples.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - Exe - net6.0 - - - diff --git a/Examples/Program.cs b/Examples/Program.cs deleted file mode 100644 index d925120..0000000 --- a/Examples/Program.cs +++ /dev/null @@ -1,134 +0,0 @@ -using MewtocolNet.RegisterBuilding; -using MewtocolNet; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using MewtocolNet.Logging; -using System.Text.RegularExpressions; -using System.Globalization; -using System.Threading; - -namespace Examples; - -class Program { - - static ExampleScenarios ExampleSzenarios = new ExampleScenarios(); - - static void Main(string[] args) { - - Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); - - Console.Clear(); - - AppDomain.CurrentDomain.UnhandledException += (s,e) => { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Uncatched exception: {e.ExceptionObject.ToString()}"); - Console.ResetColor(); - }; - - //TaskScheduler.UnobservedTaskException += (s,e) => { - // Console.ForegroundColor = ConsoleColor.Magenta; - // Console.WriteLine($"Unobserved Task Uncatched exception: {e.Exception.ToString()}"); - // Console.ResetColor(); - //}; - - ExampleSzenarios.SetupLogger(); - - LoopInput(); - - } - - private static void LoopInput () { - - Console.WriteLine("All available scenarios\n"); - - var methods = ExampleSzenarios.GetType().GetMethods(); - var invokeableMethods = new List(); - - for (int i = 0, j = 0; i < methods.Length; i++) { - - MethodInfo method = methods[i]; - var foundAtt = method.GetCustomAttribute(typeof(ScenarioAttribute)); - - if(foundAtt != null && foundAtt is ScenarioAttribute att) { - - string paramsStr = string.Join(" ", method.GetParameters().Select(x => x.Name)); - Console.WriteLine($"[{j + 1}] {method.Name}({paramsStr}) - {att.Description}"); - invokeableMethods.Add(method); - - j++; - - } - - } - - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("\nEnter a number to excecute a example"); - Console.ResetColor(); - - Console.WriteLine("\nOther possible commands: \n"); - Console.WriteLine($"'logger ' - set loglevel to one of: {string.Join(", ", Enum.GetNames(typeof(LogLevel)).ToList())}"); - Console.WriteLine("'exit' - to close this program"); - Console.WriteLine("'clear' - to clear the output"); - - - Console.Write("> "); - - var line = Console.ReadLine(); - - var loggerMatch = Regex.Match(line, @"logger (?[a-zA-Z]{0,})"); - var splitInput = Regex.Split(line, " "); - - - if (loggerMatch.Success && Enum.TryParse(loggerMatch.Groups["level"].Value, out var loglevel)) { - - Logger.LogLevel = loglevel; - - Console.WriteLine($"Loglevel changed to: {loglevel}"); - - } else if (line == "exit") { - - Environment.Exit(0); - - } else if (line == "clear") { - - Console.Clear(); - - } else if (int.TryParse(splitInput[0], out var lineNum)) { - - var index = Math.Clamp(lineNum - 1, 0, invokeableMethods.Count - 1); - - object[] invParams = null; - - if(splitInput.Length > 1) { - invParams = splitInput.Skip(1).Cast().ToArray(); - } - - try { - - var task = (Task)invokeableMethods.ElementAt(index).Invoke(ExampleSzenarios, invParams); - task.Wait(); - - } catch (TargetParameterCountException) { - - Console.WriteLine("Missing parameters"); - - } - - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("The program ran to completition"); - Console.ResetColor(); - - } else { - - Console.WriteLine("Wrong input"); - - } - - LoopInput(); - - } - -} diff --git a/Examples/ScenarioAttribute.cs b/Examples/ScenarioAttribute.cs deleted file mode 100644 index 5a869c2..0000000 --- a/Examples/ScenarioAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace Examples; - -public class ScenarioAttribute : Attribute { - - public string Description { get; private set; } - - public ScenarioAttribute(string description) { - - Description = description; - - } - -} \ No newline at end of file diff --git a/Examples/TestRegisters.cs b/Examples/TestRegisters.cs deleted file mode 100644 index c2bbe9a..0000000 --- a/Examples/TestRegisters.cs +++ /dev/null @@ -1,80 +0,0 @@ -using MewtocolNet; -using MewtocolNet.RegisterAttributes; -using System; -using System.Collections; - -namespace Examples { - public class TestRegisters : RegisterCollection { - - //corresponds to a R100 boolean register in the PLC - [Register(IOType.R, 1000)] - public bool TestBool1 { get; private set; } - - private int testDuplicate; - - [Register(1000)] - public int TestDuplicate { - get => testDuplicate; - set => AutoSetter(value, ref testDuplicate); - } - - //corresponds to a XD input of the PLC - [Register(IOType.X, (byte)0xD)] - public bool TestBoolInputXD { get; private set; } - - //corresponds to a DT1101 - DT1104 string register in the PLC with (STRING[4]) - //[Register(1101, 4)] - //public string TestString1 { get; private set; } - - //corresponds to a DT7000 16 bit int register in the PLC - [Register(899)] - public short TestInt16 { get; private set; } - - //corresponds to a DTD7001 - DTD7002 32 bit int register in the PLC - [Register(7001)] - public int TestInt32 { get; private set; } - - //corresponds to a DTD7001 - DTD7002 32 bit float register in the PLC (REAL) - [Register(7003)] - public float TestFloat32 { get; private set; } - - //corresponds to a DT7005 - DT7009 string register in the PLC with (STRING[5]) - [Register(7005, 5)] - public string TestString2 { get; private set; } - - //corresponds to a DT7010 as a 16bit word/int and parses the word as single bits - [Register(7010)] - public BitArray TestBitRegister { get; private set; } - - //corresponds to a DT1204 as a 16bit word/int takes the bit at index 9 and writes it back as a boolean - [Register(1204, BitCount.B16, 9)] - public bool BitValue { get; private set; } - - [Register(1204, BitCount.B16, 5)] - public bool FillTest { get; private set; } - - //corresponds to a DT7012 - DT7013 as a 32bit time value that gets parsed as a timespan (TIME) - //the smallest value to communicate to the PLC is 10ms - [Register(7012)] - public TimeSpan TestTime { get; private set; } - - public enum CurrentState { - Undefined = 0, - State1 = 1, - State2 = 2, - //State3 = 3, - State4 = 4, - State5 = 5, - StateBetween = 100, - State6 = 6, - State7 = 7, - } - - [Register(50)] - public CurrentState TestEnum { get; private set; } - - [Register(100)] - public TimeSpan TsTest2 { get; private set; } - - } -} diff --git a/Examples/TestRegistersEnumBitwise.cs b/Examples/TestRegistersEnumBitwise.cs deleted file mode 100644 index a3990b8..0000000 --- a/Examples/TestRegistersEnumBitwise.cs +++ /dev/null @@ -1,106 +0,0 @@ -using MewtocolNet; -using MewtocolNet.RegisterAttributes; -using System; -using System.Collections; - -namespace Examples { - - public class TestRegistersEnumBitwise : RegisterCollection { - - private bool startCyclePLC; - - [Register(IOType.R, 50)] - public bool StartCyclePLC { - get => startCyclePLC; - set => AutoSetter(value, ref startCyclePLC); - } - - //the enum you want to read out - public enum CurrentState { - - Undefined = 0, - State1 = 1, - State2 = 2, - //If you leave an enum empty it still works - //State3 = 3, - State4 = 4, - State5 = 5, - State6 = 6, - State7 = 7, - State8 = 8, - State9 = 9, - State10 = 10, - State11 = 11, - State12 = 12, - State13 = 13, - State14 = 14, - State15 = 15, - - } - - //automatically convert the short (PLC int) register to an enum - [Register(500)] - public CurrentState TestEnum16 { get; private set; } - - //also works for 32bit registers - [Register(501, BitCount.B32)] - public CurrentState TestEnum32 { get; private set; } - - //get the whole bit array from DT503 - - [Register(503)] - public BitArray TestBitRegister16 { get; private set; } - - //you can also extract single bits from DT503 - - [Register(503, BitCount.B16, 0)] - public bool BitValue0 { get; private set; } - - [Register(503, BitCount.B16, 1)] - public bool BitValue1 { get; private set; } - - [Register(503, BitCount.B16, 2)] - public bool BitValue2 { get; private set; } - - [Register(503, BitCount.B16, 3)] - public bool BitValue3 { get; private set; } - - [Register(503, BitCount.B16, 4)] - public bool BitValue4 { get; private set; } - - [Register(503, BitCount.B16, 5)] - public bool BitValue5 { get; private set; } - - [Register(503, BitCount.B16, 6)] - public bool BitValue6 { get; private set; } - - [Register(503, BitCount.B16, 7)] - public bool BitValue7 { get; private set; } - - [Register(503, BitCount.B16, 8)] - public bool BitValue8 { get; private set; } - - [Register(503, BitCount.B16, 9)] - public bool BitValue9 { get; private set; } - - [Register(503, BitCount.B16, 10)] - public bool BitValue10 { get; private set; } - - [Register(503, BitCount.B16, 11)] - public bool BitValue11 { get; private set; } - - [Register(503, BitCount.B16, 12)] - public bool BitValue12 { get; private set; } - - [Register(503, BitCount.B16, 13)] - public bool BitValue13 { get; private set; } - - [Register(503, BitCount.B16, 14)] - public bool BitValue14 { get; private set; } - - [Register(503, BitCount.B16, 15)] - public bool BitValue15 { get; private set; } - - } - -} diff --git a/MewExplorer/MewExplorer.csproj b/MewExplorer/MewExplorer.csproj index 9a8e14e..a21d09b 100644 --- a/MewExplorer/MewExplorer.csproj +++ b/MewExplorer/MewExplorer.csproj @@ -1,10 +1,11 @@  - net7.0-android; + + false + + net7.0-android; $(TargetFrameworks);net7.0-windows10.0.19041.0 - - Exe MewExplorer true diff --git a/MewTerminal/Commands/ScanCommand.cs b/MewTerminal/Commands/ScanCommand.cs index 697766b..d197c68 100644 --- a/MewTerminal/Commands/ScanCommand.cs +++ b/MewTerminal/Commands/ScanCommand.cs @@ -72,7 +72,7 @@ internal class ScanCommand : CommandLineExcecuteable { AnsiConsole.Write(found.Select(x => new { x.Cassette.Name, PLC = x.PLCInf.TypeCode.ToName(), - IsRun = x.PLCInf.OperationMode.HasFlag(OPMode.Run), + IsRun = x.PLCInf.OperationMode.HasFlag(OPMode.RunMode), IP = x.Cassette.IPAddress, x.Cassette.Port, DHCP = x.Cassette.UsesDHCP, diff --git a/MewTerminal/MewTerminal.csproj b/MewTerminal/MewTerminal.csproj index e75817e..417a0cf 100644 --- a/MewTerminal/MewTerminal.csproj +++ b/MewTerminal/MewTerminal.csproj @@ -1,10 +1,11 @@ - + Exe net7.0 enable enable + true @@ -16,4 +17,18 @@ + + + x64 + win-x64 + True + None + False + false + none + en + ..\Builds\MewTerminal + + + diff --git a/MewtocolNet.sln b/MewtocolNet.sln index 5c0ee6e..8a20ae2 100644 --- a/MewtocolNet.sln +++ b/MewtocolNet.sln @@ -5,15 +5,13 @@ VisualStudioVersion = 17.5.33103.201 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MewtocolNet", "MewtocolNet\MewtocolNet.csproj", "{8B7863E7-5E82-4990-9138-2C0C24629982}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples", "Examples\Examples.csproj", "{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MewtocolTests", "MewtocolTests\MewtocolTests.csproj", "{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MewExplorer", "MewExplorer\MewExplorer.csproj", "{F243F38A-76D3-4C38-BAE6-C61729479661}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocBuilder", "DocBuilder\DocBuilder.csproj", "{50F2D23F-C875-4006-A0B6-7F5A181BC944}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MewTerminal", "MewTerminal\MewTerminal.csproj", "{D1E751C6-296F-4CF1-AE28-C6D4388C7CF1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MewTerminal", "MewTerminal\MewTerminal.csproj", "{D1E751C6-296F-4CF1-AE28-C6D4388C7CF1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,18 +35,6 @@ Global {8B7863E7-5E82-4990-9138-2C0C24629982}.Release|x64.Build.0 = Release|Any CPU {8B7863E7-5E82-4990-9138-2C0C24629982}.Release|x86.ActiveCfg = Release|Any CPU {8B7863E7-5E82-4990-9138-2C0C24629982}.Release|x86.Build.0 = Release|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Debug|x64.ActiveCfg = Debug|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Debug|x64.Build.0 = Debug|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Debug|x86.ActiveCfg = Debug|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Debug|x86.Build.0 = Debug|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|Any CPU.Build.0 = Release|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x64.ActiveCfg = Release|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x64.Build.0 = Release|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x86.ActiveCfg = Release|Any CPU - {D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x86.Build.0 = Release|Any CPU {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|Any CPU.Build.0 = Debug|Any CPU {C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x64.ActiveCfg = Debug|Any CPU diff --git a/MewtocolNet/MewtocolInterfaceRequests.cs b/MewtocolNet/MewtocolInterfaceRequests.cs index 409071a..94015f3 100644 --- a/MewtocolNet/MewtocolInterfaceRequests.cs +++ b/MewtocolNet/MewtocolInterfaceRequests.cs @@ -69,15 +69,15 @@ namespace MewtocolNet { /// /// The mode to change to /// The success state of the write operation - public async Task SetOperationMode(OPMode mode) { + public async Task SetOperationMode (bool setRun) { - string modeChar = mode == OPMode.Prog ? "P" : "R"; + string modeChar = setRun ? "R" : "P"; string requeststring = $"%{GetStationNumber()}#RM{modeChar}"; var result = await SendCommandAsync(requeststring); if (result.Success) { - Logger.Log($"operation mode was changed to {mode}", LogLevel.Info, this); + Logger.Log($"operation mode was changed to {(setRun ? "Run" : "Prog")}", LogLevel.Info, this); } else { Logger.Log("Operation mode change failed", LogLevel.Error, this); } diff --git a/MewtocolNet/MewtocolNet.csproj b/MewtocolNet/MewtocolNet.csproj index c9ade86..89d2219 100644 --- a/MewtocolNet/MewtocolNet.csproj +++ b/MewtocolNet/MewtocolNet.csproj @@ -1,8 +1,12 @@  + - netstandard2.0; + + false + + netstandard2.0 Mewtocol.NET - 0.7.1 + 0.0.0 Felix Weiss Womed true @@ -13,22 +17,28 @@ plc;panasonic;mewtocol;automation; MIT 2ccdcc9b-94a3-4e76-8827-453ab889ea33 + - - ..\Builds\MewtocolNet.xml - ..\Builds + + + ..\Builds\MewtocolNet\MewtocolNet.xml + ..\Builds\MewtocolNet - + + <_Parameter1>MewtocolTests - + + <_Parameter1>DocBuilder - + + + diff --git a/MewtocolNet/PLCInfo.cs b/MewtocolNet/PLCInfo.cs index 5334306..ce3ae79 100644 --- a/MewtocolNet/PLCInfo.cs +++ b/MewtocolNet/PLCInfo.cs @@ -1,5 +1,4 @@ -using MewtocolNet.PublicEnums; -using System.Globalization; +using System.Globalization; using System.Text.RegularExpressions; namespace MewtocolNet { @@ -39,6 +38,11 @@ namespace MewtocolNet { /// public string SelfDiagnosticError { get; internal set; } + /// + /// Quickcheck for the runmode flag + /// + public bool IsRunMode => OperationMode.HasFlag(OPMode.RunMode); + internal bool TryExtendFromEXRT (string msg) { var regexEXRT = new Regex(@"\%EE\$EX00RT00(?..)(?..)..(?..)(?..)..(?..)(?....)(?..)(?..)(?.)(?....)(?....)(?....).*", RegexOptions.IgnoreCase); @@ -108,6 +112,12 @@ namespace MewtocolNet { return !c1.Equals(c2); } + public override string ToString() { + + return $"{TypeCode.ToName()}, OP: {OperationMode}"; + + } + } } \ No newline at end of file diff --git a/MewtocolNet/PublicEnums/HWInformation.cs b/MewtocolNet/PublicEnums/HWInformation.cs index 6089eab..2f9b06d 100644 --- a/MewtocolNet/PublicEnums/HWInformation.cs +++ b/MewtocolNet/PublicEnums/HWInformation.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace MewtocolNet.PublicEnums { +namespace MewtocolNet { /// /// Contains hardware information about the device as flags @@ -29,49 +29,4 @@ namespace MewtocolNet.PublicEnums { } - /// - /// Descibes the operation mode of the device as flags - /// - [Flags] - public enum OPMode : byte { - - /// - /// No operation mode flag active - /// - None = 0, - /// - /// Is in RUN mode, otherwise its PROG Mode - /// - RunMode = 1, - /// - /// Is in test mode, otherwise ok - /// - TestMode = 2, - /// - /// Is BRK/1 step executed - /// - BreakPointPerOneStep = 4, - /// - /// Is BRK command enabled - /// - BreakEnabled = 16, - /// - /// Is outputting to external device - /// - ExternalOutput = 32, - /// - /// Is 1 step exec enabled - /// - OneStepExecEnabled = 64, - /// - /// Is a message displayed? - /// - MessageInstructionDisplayed = 128, - /// - /// Is in remote mode - /// - RemoteMode = 255, - - } - } diff --git a/MewtocolNet/PublicEnums/OPMode.cs b/MewtocolNet/PublicEnums/OPMode.cs index e760230..73a8467 100644 --- a/MewtocolNet/PublicEnums/OPMode.cs +++ b/MewtocolNet/PublicEnums/OPMode.cs @@ -1,17 +1,50 @@ -namespace MewtocolNet { +using System; + +namespace MewtocolNet { /// - /// CPU type of the PLC + /// Descibes the operation mode of the device as flags /// - public enum OPMode { + [Flags] + public enum OPMode : byte { + /// - /// PLC run mode + /// No operation mode flag active /// - Run, + None = 0, /// - /// PLC programming mode + /// Is in RUN mode, otherwise its PROG Mode /// - Prog, + RunMode = 1, + /// + /// Is in test mode, otherwise ok + /// + TestMode = 2, + /// + /// Is BRK/1 step executed + /// + BreakPointPerOneStep = 4, + /// + /// Is BRK command enabled + /// + BreakEnabled = 16, + /// + /// Is outputting to external device + /// + ExternalOutput = 32, + /// + /// Is 1 step exec enabled + /// + OneStepExecEnabled = 64, + /// + /// Is a message displayed? + /// + MessageInstructionDisplayed = 128, + /// + /// Is in remote mode + /// + RemoteMode = 255, + } -} \ No newline at end of file +} diff --git a/MewtocolNet/Registers/BoolRegister.cs b/MewtocolNet/Registers/BoolRegister.cs index a8f14aa..cf1af8c 100644 --- a/MewtocolNet/Registers/BoolRegister.cs +++ b/MewtocolNet/Registers/BoolRegister.cs @@ -78,7 +78,9 @@ namespace MewtocolNet.Registers { if (!attachedInterface.IsConnected) return false; - return await attachedInterface.WriteRawRegisterAsync(this, PlcValueParser.Encode(this, (bool)data)); + var res = await attachedInterface.WriteRawRegisterAsync(this, PlcValueParser.Encode(this, (bool)data)); + if (res) SetValueFromPLC(data); + return res; } diff --git a/MewtocolNet/Registers/BytesRegister.cs b/MewtocolNet/Registers/BytesRegister.cs index c6c102e..bd2483f 100644 --- a/MewtocolNet/Registers/BytesRegister.cs +++ b/MewtocolNet/Registers/BytesRegister.cs @@ -89,7 +89,9 @@ namespace MewtocolNet.Registers { if (!attachedInterface.IsConnected) return false; - return await attachedInterface.WriteRawRegisterAsync(this, (byte[])data); + var res = await attachedInterface.WriteRawRegisterAsync(this, (byte[])data); + if (res) SetValueFromPLC(data); + return res; } diff --git a/MewtocolNet/Registers/NumberRegister.cs b/MewtocolNet/Registers/NumberRegister.cs index 207d7de..2f8a4ab 100644 --- a/MewtocolNet/Registers/NumberRegister.cs +++ b/MewtocolNet/Registers/NumberRegister.cs @@ -178,7 +178,9 @@ namespace MewtocolNet.Registers { if (!attachedInterface.IsConnected) return false; - return await attachedInterface.WriteRawRegisterAsync(this, PlcValueParser.Encode(this, (T)data)); + var res = await attachedInterface.WriteRawRegisterAsync(this, PlcValueParser.Encode(this, (T)data)); + if (res) SetValueFromPLC(data); + return res; } diff --git a/MewtocolNet/Registers/StringRegister.cs b/MewtocolNet/Registers/StringRegister.cs index 44fb5ed..9147049 100644 --- a/MewtocolNet/Registers/StringRegister.cs +++ b/MewtocolNet/Registers/StringRegister.cs @@ -97,9 +97,11 @@ namespace MewtocolNet.Registers { if (!attachedInterface.IsConnected) return false; var res = await attachedInterface.WriteRawRegisterAsync(this, PlcValueParser.Encode(this, (string)data)); - - if (res) UsedSize = (short)((string)Value).Length; - + if (res) { + UsedSize = (short)((string)Value).Length; + SetValueFromPLC(data); + } + return res; } diff --git a/MewtocolTests/EncapsulatedTests/ExpectedPlcInformationData.cs b/MewtocolTests/EncapsulatedTests/ExpectedPlcInformationData.cs index 2a97059..0f35705 100644 --- a/MewtocolTests/EncapsulatedTests/ExpectedPlcInformationData.cs +++ b/MewtocolTests/EncapsulatedTests/ExpectedPlcInformationData.cs @@ -10,7 +10,7 @@ public class ExpectedPlcInformationData { public int PLCPort { get; set; } - public CpuType Type { get; set; } + public PlcType Type { get; set; } public int ProgCapacity { get; set; } diff --git a/MewtocolTests/MewtocolTests.csproj b/MewtocolTests/MewtocolTests.csproj index 9d3002f..7c619ff 100644 --- a/MewtocolTests/MewtocolTests.csproj +++ b/MewtocolTests/MewtocolTests.csproj @@ -1,13 +1,16 @@ - net6.0 + + false + false + + net6.0 enable enable - - false + - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MewtocolTests/TestLivePLC.cs b/MewtocolTests/TestLivePLC.cs index a8bdaef..1a94956 100644 --- a/MewtocolTests/TestLivePLC.cs +++ b/MewtocolTests/TestLivePLC.cs @@ -20,7 +20,7 @@ namespace MewtocolTests PLCName = "FPX-H C30T", PLCIP = "192.168.115.210", PLCPort = 9094, - Type = CpuType.FP_Sigma_X_H_30K_60K_120K, + Type = PlcType.FPdXH_32k__C30TsP_C40T_C60TsP, ProgCapacity = 32, }, @@ -29,7 +29,7 @@ namespace MewtocolTests PLCName = "FPX-H C14R", PLCIP = "192.168.115.212", PLCPort = 9094, - Type = CpuType.FP_Sigma_X_H_30K_60K_120K, + Type = PlcType.FPdXH_16k__C14R, ProgCapacity = 16, }, @@ -57,7 +57,7 @@ namespace MewtocolTests this.output = output; - Logger.LogLevel = LogLevel.Verbose; + Logger.LogLevel = LogLevel.Critical; Logger.OnNewLogMessage((d, l, m) => { output.WriteLine($"Mewtocol Logger: {d} {m}"); @@ -102,8 +102,8 @@ namespace MewtocolTests Assert.True(client.IsConnected); - Assert.Equal(client.PlcInfo.CpuInformation.Cputype, plc.Type); - Assert.Equal(client.PlcInfo.CpuInformation.ProgramCapacity, plc.ProgCapacity); + Assert.Equal(client.PlcInfo.TypeCode, plc.Type); + Assert.Equal(client.PlcInfo.ProgramCapacity, plc.ProgCapacity); client.Disconnect(); diff --git a/build_order.md b/build_order.md new file mode 100644 index 0000000..656465c --- /dev/null +++ b/build_order.md @@ -0,0 +1,7 @@ +## 1. Run the tests + +`dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=./TestResults/coverage.opencover.xml` + +## 2. Publish + +`dotnet publish -c:Release --property WarningLevel=0` \ No newline at end of file