diff --git a/Examples/TestRegisters.cs b/Examples/TestRegisters.cs index dfa77cc..afe76f7 100644 --- a/Examples/TestRegisters.cs +++ b/Examples/TestRegisters.cs @@ -7,7 +7,7 @@ namespace Examples { public class TestRegisters : RegisterCollectionBase { //corresponds to a R100 boolean register in the PLC - [Register(1000, RegisterType.R)] + [Register(IOType.R, 1000)] public bool TestBool1 { get; private set; } private int testDuplicate; @@ -19,7 +19,7 @@ namespace Examples { } //corresponds to a XD input of the PLC - [Register(RegisterType.X, SpecialAddress.D)] + [Register(IOType.X, (byte)0xD)] public bool TestBoolInputXD { get; private set; } //corresponds to a DT1101 - DT1104 string register in the PLC with (STRING[4]) diff --git a/Examples/TestRegistersEnumBitwise.cs b/Examples/TestRegistersEnumBitwise.cs index 2a24825..ea4954c 100644 --- a/Examples/TestRegistersEnumBitwise.cs +++ b/Examples/TestRegistersEnumBitwise.cs @@ -9,7 +9,7 @@ namespace Examples { private bool startCyclePLC; - [Register(50, RegisterType.R)] + [Register(IOType.R, 50)] public bool StartCyclePLC { get => startCyclePLC; set => AutoSetter(value, ref startCyclePLC); diff --git a/MewtocolNet/Mewtocol/LinkedLists.cs b/MewtocolNet/Mewtocol/CodeDescriptions.cs similarity index 90% rename from MewtocolNet/Mewtocol/LinkedLists.cs rename to MewtocolNet/Mewtocol/CodeDescriptions.cs index 468a28a..cbe90ef 100644 --- a/MewtocolNet/Mewtocol/LinkedLists.cs +++ b/MewtocolNet/Mewtocol/CodeDescriptions.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; namespace MewtocolNet.Links { - internal class LinkedData { + internal class CodeDescriptions { - internal static Dictionary ErrorCodes = new Dictionary { + internal static Dictionary Error = new Dictionary { {21, "NACK error"}, {22, "WACK error"}, diff --git a/MewtocolNet/Mewtocol/DynamicInterface.cs b/MewtocolNet/Mewtocol/DynamicInterface.cs index 1fe5054..8bee8e6 100644 --- a/MewtocolNet/Mewtocol/DynamicInterface.cs +++ b/MewtocolNet/Mewtocol/DynamicInterface.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Reflection; using System.Text; @@ -205,167 +206,6 @@ namespace MewtocolNet { #region Register Adding - - /// - /// Adds a PLC memory register to the watchlist - /// The registers can be read back by attaching - /// - /// The address of the register in the PLCs memory - /// - /// The memory area type - /// X = Physical input area (bool) - /// Y = Physical input area (bool) - /// R = Internal relay area (bool) - /// DT = Internal data area (short/ushort) - /// DDT = Internal relay area (int/uint) - /// - /// A naming definition for QOL, doesn't effect PLC and is optional - public void AddRegister (int _address, RegisterType _type, string _name = null) { - - IRegister toAdd = null; - - //as number registers - if (_type == RegisterType.DT_short) { - toAdd = new NRegister(_address, _name); - } - if (_type == RegisterType.DT_ushort) { - toAdd = new NRegister(_address, _name); - } - if (_type == RegisterType.DDT_int) { - toAdd = new NRegister(_address, _name); - } - if (_type == RegisterType.DDT_uint) { - toAdd = new NRegister(_address, _name); - } - if (_type == RegisterType.DDT_float) { - toAdd = new NRegister(_address, _name); - } - - if(toAdd == null) { - toAdd = new BRegister(_address, _type, _name); - } - - Registers.Add(toAdd); - - } - - internal void AddRegister (Type _colType, int _address, RegisterType _type, string _name = null) { - - IRegister toAdd = null; - - //as number registers - if (_type == RegisterType.DT_short) { - toAdd = new NRegister(_address, _name).WithCollectionType(_colType); - } - if (_type == RegisterType.DT_ushort) { - toAdd = new NRegister(_address, _name).WithCollectionType(_colType); - } - if (_type == RegisterType.DDT_int) { - toAdd = new NRegister(_address, _name).WithCollectionType(_colType); - } - if (_type == RegisterType.DDT_uint) { - toAdd = new NRegister(_address, _name).WithCollectionType(_colType); - } - if (_type == RegisterType.DDT_float) { - toAdd = new NRegister(_address, _name).WithCollectionType(_colType); - } - - if (toAdd == null) { - toAdd = new BRegister(_address, _type, _name).WithCollectionType(_colType); - } - - Registers.Add(toAdd); - - } - - /// - /// Adds a PLC memory register to the watchlist - /// The registers can be read back by attaching - /// - /// The special address of the register in the PLCs memory - /// - /// The memory area type - /// X = Physical input area (bool) - /// Y = Physical input area (bool) - /// R = Internal relay area (bool) - /// DT = Internal data area (short/ushort) - /// DDT = Internal relay area (int/uint) - /// - /// A naming definition for QOL, doesn't effect PLC and is optional - public void AddRegister (SpecialAddress _spAddress, RegisterType _type, string _name = null) { - - //as bool registers - Registers.Add(new BRegister(_spAddress, _type, _name)); - - } - - internal void AddRegister (Type _colType, SpecialAddress _spAddress, RegisterType _type, string _name = null) { - - var reg = new BRegister(_spAddress, _type, _name); - - reg.collectionType = _colType; - - //as bool registers - Registers.Add(reg); - - } - - /// - /// Adds a PLC memory register to the watchlist - /// The registers can be read back by attaching - /// - /// - /// The type of the register translated from C# to IEC 61131-3 types - /// C# ------ IEC - /// short => INT/WORD - /// ushort => UINT - /// int => DOUBLE - /// uint => UDOUBLE - /// float => REAL - /// string => STRING - /// - /// A naming definition for QOL, doesn't effect PLC and is optional - /// The address of the register in the PLCs memory - /// The length of the string (Can be ignored for other types) - public void AddRegister(int _address, int _length = 1, string _name = null) { - - Type regType = typeof(T); - - if (regType != typeof(string) && _length != 1) { - throw new NotSupportedException($"_lenght parameter only allowed for register of type string"); - } - - IRegister toAdd; - - if (regType == typeof(short)) { - toAdd = new NRegister(_address, _name); - } else if (regType == typeof(ushort)) { - toAdd = new NRegister(_address, _name); - } else if (regType == typeof(int)) { - toAdd = new NRegister(_address, _name); - } else if (regType == typeof(uint)) { - toAdd = new NRegister(_address, _name); - } else if (regType == typeof(float)) { - toAdd = new NRegister(_address, _name); - } else if (regType == typeof(string)) { - toAdd = new SRegister(_address, _length, _name); - } else if (regType == typeof(TimeSpan)) { - toAdd = new NRegister(_address, _name); - } else if (regType == typeof(bool)) { - toAdd = new BRegister(_address, RegisterType.R, _name); - } else { - throw new NotSupportedException($"The type {regType} is not allowed for Registers \n" + - $"Allowed are: short, ushort, int, uint, float and string"); - } - - - if (Registers.Any(x => x.GetRegisterPLCName() == toAdd.GetRegisterPLCName())) { - throw new NotSupportedException($"Cannot add a register multiple times, " + - $"make sure that all register attributes or AddRegister assignments have different adresses."); - } - - } - //Internal register adding for auto register collection building internal void AddRegister (Type _colType, int _address, PropertyInfo boundProp, int _length = 1, bool _isBitwise = false, Type _enumType = null) { @@ -405,7 +245,7 @@ namespace MewtocolNet { } else if (regType == typeof(TimeSpan)) { reg = new NRegister(_address, propName).WithCollectionType(_colType); } else if (regType == typeof(bool)) { - reg = new BRegister(_address, RegisterType.R, propName).WithCollectionType(_colType); + reg = new BRegister(IOType.R, 0x0, _address,propName).WithCollectionType(_colType); } if (reg == null) { diff --git a/MewtocolNet/Mewtocol/MewtocolHelpers.cs b/MewtocolNet/Mewtocol/MewtocolHelpers.cs index 1b82ccc..715a869 100644 --- a/MewtocolNet/Mewtocol/MewtocolHelpers.cs +++ b/MewtocolNet/Mewtocol/MewtocolHelpers.cs @@ -239,6 +239,24 @@ namespace MewtocolNet { } + /// + /// Checks if the register type is non numeric + /// + internal static bool IsBoolean (this RegisterType type) { + + return type == RegisterType.X || type == RegisterType.Y || type == RegisterType.R; + + } + + /// + /// Checks if the register type is an physical in or output of the plc + /// + internal static bool IsPhysicalInOutType (this RegisterType type) { + + return type == RegisterType.X || type == RegisterType.Y; + + } + } } \ No newline at end of file diff --git a/MewtocolNet/Mewtocol/MewtocolInterface.cs b/MewtocolNet/Mewtocol/MewtocolInterface.cs index 9062077..009f7fe 100644 --- a/MewtocolNet/Mewtocol/MewtocolInterface.cs +++ b/MewtocolNet/Mewtocol/MewtocolInterface.cs @@ -17,6 +17,8 @@ using System.Threading; using MewtocolNet.Queue; using System.Reflection; using System.Timers; +using System.Data; +using System.Xml.Linq; namespace MewtocolNet { @@ -437,11 +439,10 @@ namespace MewtocolNet if (attr is RegisterAttribute cAttribute) { if (prop.PropertyType == typeof(bool) && cAttribute.AssignedBitIndex == -1) { - if (cAttribute.SpecialAddress == SpecialAddress.None) { - AddRegister(collection.GetType(), cAttribute.MemoryArea, cAttribute.RegisterType, _name: propName); - } else { - AddRegister(collection.GetType(), cAttribute.SpecialAddress, cAttribute.RegisterType, _name: propName); - } + + //add bool register non bit assgined + Registers.Add(new BRegister((IOType)(int)cAttribute.RegisterType, cAttribute.SpecialAddress, cAttribute.MemoryArea, _name: propName).WithCollectionType(collection.GetType())); + } if (prop.PropertyType == typeof(short)) { @@ -738,7 +739,7 @@ namespace MewtocolNet Match m = errorcheck.Match(response.ToString()); if (m.Success) { string eCode = m.Groups[1].Value; - string eDes = Links.LinkedData.ErrorCodes[Convert.ToInt32(eCode)]; + string eDes = Links.CodeDescriptions.Error[Convert.ToInt32(eCode)]; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Response is: {response}"); Logger.Log($"Error on command {_msg.Replace("\r", "")} the PLC returned error code: {eCode}, {eDes}", LogLevel.Error); diff --git a/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs b/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs index 382c574..8e81f21 100644 --- a/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs +++ b/MewtocolNet/Mewtocol/RegisterAttributes/RegisterAttribute.cs @@ -23,17 +23,16 @@ namespace MewtocolNet.RegisterAttributes { /// /// Defines the behavior of a register property /// - [AttributeUsage(AttributeTargets.Property)] + [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class RegisterAttribute : Attribute { internal int MemoryArea; internal int StringLength; internal RegisterType RegisterType; - internal SpecialAddress SpecialAddress = SpecialAddress.None; + internal byte SpecialAddress = 0x0; internal BitCount BitCount; internal int AssignedBitIndex = -1; - /// /// Attribute for string type or numeric registers /// @@ -49,31 +48,22 @@ namespace MewtocolNet.RegisterAttributes { /// /// Attribute for boolean registers /// - /// The area in the plcs memory - /// The type of boolean register - public RegisterAttribute (int memoryArea, RegisterType type) { + public RegisterAttribute(IOType type, byte spAdress = 0x0) { - if (type.ToString().StartsWith("DT")) - throw new NotSupportedException("DT types are not supported for attribute register setups because the number type is casted automatically"); - - MemoryArea = memoryArea; - RegisterType = type; - SpecialAddress = SpecialAddress.None; + MemoryArea = 0; + RegisterType = (RegisterType)(int)type; + SpecialAddress = spAdress; } /// /// Attribute for boolean registers /// - /// The special area in the plcs memory - /// The type of boolean register - public RegisterAttribute (RegisterType type, SpecialAddress spAdress) { + public RegisterAttribute (IOType type, int memoryArea, byte spAdress = 0x0) { - if (type.ToString().StartsWith("DT")) - throw new NotSupportedException("DT types are not supported for attribute register setups because the number type is casted automatically"); - - RegisterType = type; - SpecialAddress = spAdress; + MemoryArea = memoryArea; + RegisterType = (RegisterType)(int)type; + SpecialAddress = spAdress; } diff --git a/MewtocolNet/Mewtocol/RegisterBuilder.cs b/MewtocolNet/Mewtocol/RegisterBuilder.cs new file mode 100644 index 0000000..7278ac4 --- /dev/null +++ b/MewtocolNet/Mewtocol/RegisterBuilder.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MewtocolNet.Mewtocol { + + /// + /// Contains useful tools for register creation + /// + public static class RegisterBuilder { + + /// + /// Parses a register from its PLC name + /// + /// The name, fe. DT100 + /// An or null if + /// True if successfully parsed + //public static bool TryBuildFromName (string name, out IRegister reg) { + + + + //} + + } + +} diff --git a/MewtocolNet/Mewtocol/RegisterEnums.cs b/MewtocolNet/Mewtocol/RegisterEnums.cs index 66f7582..d6559c4 100644 --- a/MewtocolNet/Mewtocol/RegisterEnums.cs +++ b/MewtocolNet/Mewtocol/RegisterEnums.cs @@ -7,64 +7,62 @@ using System.Threading.Tasks; namespace MewtocolNet { /// - /// The special register type + /// The register prefixed type /// public enum RegisterType { /// /// Physical input as a bool (Relay) /// - X, + X = 0, /// /// Physical output as a bool (Relay) /// - Y, + Y = 1, /// /// Internal as a bool (Relay) /// - R, + R = 2, /// /// Data area as a short (Register) /// - DT_short, + DT_short = 3, /// /// Data area as an unsigned short (Register) /// - DT_ushort, + DT_ushort = 4, /// /// Double data area as an integer (Register) /// - DDT_int, + DDT_int = 5, /// /// Double data area as an unsigned integer (Register) /// - DDT_uint, + DDT_uint = 6, /// /// Double data area as an floating point number (Register) /// - DDT_float, + DDT_float = 7, } /// - /// The special input / output channel address + /// The type of an input/output register /// - public enum SpecialAddress { - - #pragma warning disable CS1591 + public enum IOType { /// - /// No defined + /// Physical input as a bool (Relay) /// - None, - A = -10, - B = -11, - C = -12, - D = -13, - E = -14, - F = -15, - - #pragma warning restore + X = 0, + /// + /// Physical output as a bool (Relay) + /// + Y = 1, + /// + /// Internal relay + /// + R = 2, } diff --git a/MewtocolNet/Mewtocol/Subregisters/BRegister.cs b/MewtocolNet/Mewtocol/Subregisters/BRegister.cs index 92cb068..c49d13e 100644 --- a/MewtocolNet/Mewtocol/Subregisters/BRegister.cs +++ b/MewtocolNet/Mewtocol/Subregisters/BRegister.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Data; using System.Text; using MewtocolNet; @@ -22,8 +23,6 @@ namespace MewtocolNet.Registers { internal RegisterType RegType { get; private set; } - internal SpecialAddress SpecialAddress { get; private set; } - internal Type collectionType; /// @@ -44,50 +43,46 @@ namespace MewtocolNet.Registers { /// public string Name => name; - internal int memoryAdress; + internal int memoryAddress; /// /// The registers memory adress if not a special register /// - public int MemoryAddress => memoryAdress; + public int MemoryAddress => memoryAddress; + + internal byte specialAddress; + /// + /// The registers memory adress if not a special register + /// + public byte SpecialAddress => specialAddress; /// - /// Defines a register containing a number + /// Creates a new boolean register /// - /// Memory start adress max 99999 - /// Type of boolean register - /// Name of the register - public BRegister (int _address, RegisterType _type = RegisterType.R, string _name = null) { + /// The io type prefix + /// The special address + /// The area special address + /// The custom name + /// + /// + public BRegister (IOType _io, byte _spAddress = 0x0, int _areaAdress = 0, string _name = null) { - if (_address > 99999) throw new NotSupportedException("Memory addresses cant be greater than 99999"); + if (_areaAdress < 0) + throw new NotSupportedException("The area address cant be negative"); - if (_type != RegisterType.X && _type != RegisterType.Y && _type != RegisterType.R) - throw new NotSupportedException("The register type cant be numeric, use X, Y or R"); + if(_io == IOType.R && _areaAdress >= 512) + throw new NotSupportedException("R area addresses cant be greater than 511"); - memoryAdress = _address; + if ((_io == IOType.X || _io == IOType.Y) && _areaAdress >= 110) + throw new NotSupportedException("XY area addresses cant be greater than 110"); + + if (_spAddress > 0xF) + throw new NotSupportedException("Special address cant be greater 15 or 0xF"); + + memoryAddress = (int)_areaAdress; + specialAddress = _spAddress; name = _name; - RegType = _type; - - } - - /// - /// Defines a register containing a number - /// - /// Memory start adress max 99999 - /// Type of boolean register - /// Name of the register - public BRegister (SpecialAddress _address, RegisterType _type = RegisterType.R, string _name = null) { - - if (_address == SpecialAddress.None) - throw new NotSupportedException("Special address cant be none"); - - if (_type != RegisterType.X && _type != RegisterType.Y && _type != RegisterType.R) - throw new NotSupportedException("The register type cant be numeric, use X, Y or R"); - - SpecialAddress = _address; - name = _name; - - RegType = _type; + RegType = (RegisterType)(int)_io; } @@ -105,12 +100,13 @@ namespace MewtocolNet.Registers { //build area code from register type StringBuilder asciistring = new StringBuilder(RegType.ToString()); - if(SpecialAddress == SpecialAddress.None) { - asciistring.Append(MemoryAddress.ToString().PadLeft(4, '0')); - } else { - asciistring.Append(SpecialAddress.ToString().PadLeft(4, '0')); - } - + + string memPadded = MemoryAddress.ToString().PadLeft(4, '0'); + string sp = SpecialAddress.ToString("X1"); + + asciistring.Append(memPadded); + asciistring.Append(sp); + return asciistring.ToString(); } @@ -125,9 +121,6 @@ namespace MewtocolNet.Registers { public string GetStartingMemoryArea() { - if (SpecialAddress != SpecialAddress.None) - return SpecialAddress.ToString(); - return MemoryAddress.ToString(); } @@ -148,8 +141,18 @@ namespace MewtocolNet.Registers { public string GetRegisterPLCName() { - if (SpecialAddress != SpecialAddress.None) { - return $"{GetRegisterString()}{SpecialAddress}"; + var spAdressEnd = SpecialAddress.ToString("X1"); + + if (MemoryAddress == 0) { + + return $"{GetRegisterString()}{spAdressEnd}"; + + } + + if(MemoryAddress > 0 && SpecialAddress != 0) { + + return $"{GetRegisterString()}{MemoryAddress}{spAdressEnd}"; + } return $"{GetRegisterString()}{MemoryAddress}"; diff --git a/MewtocolNet/MewtocolNet.csproj b/MewtocolNet/MewtocolNet.csproj index 5f420a3..c296329 100644 --- a/MewtocolNet/MewtocolNet.csproj +++ b/MewtocolNet/MewtocolNet.csproj @@ -2,7 +2,7 @@ netstandard2.0 Mewtocol.NET - 0.7.0 + 0.7.1 Felix Weiss Womed true diff --git a/MewtocolTests/AutomatedPropertyRegisters.cs b/MewtocolTests/AutomatedPropertyRegisters.cs index 30e902d..834a39c 100644 --- a/MewtocolTests/AutomatedPropertyRegisters.cs +++ b/MewtocolTests/AutomatedPropertyRegisters.cs @@ -21,11 +21,12 @@ namespace MewtocolTests { public class TestRegisterCollection : RegisterCollectionBase { //corresponds to a R100 boolean register in the PLC - [Register(1000, RegisterType.R)] + //can also be written as R1000 because the last one is a special address + [Register(IOType.R, 100, spAdress: 0)] public bool TestBool1 { get; private set; } //corresponds to a XD input of the PLC - [Register(RegisterType.X, SpecialAddress.D)] + [Register(IOType.X, (byte)0xD)] public bool TestBoolInputXD { get; private set; } //corresponds to a DT1101 - DT1104 string register in the PLC with (STRING[4]) @@ -117,7 +118,7 @@ namespace MewtocolTests { var register = interf.GetRegister(nameof(TestRegisterCollection.TestBool1)); //test generic properties - TestBasicGeneration(register, nameof(TestRegisterCollection.TestBool1), false, 1000, "R1000"); + TestBasicGeneration(register, nameof(TestRegisterCollection.TestBool1), false, 100, "R100"); } diff --git a/MewtocolTests/TestLinkedLists.cs b/MewtocolTests/TestLinkedLists.cs index cef48f8..4f47f03 100644 --- a/MewtocolTests/TestLinkedLists.cs +++ b/MewtocolTests/TestLinkedLists.cs @@ -53,7 +53,7 @@ namespace MewtocolTests { }; - Assert.Equal(expectedData, LinkedData.ErrorCodes); + Assert.Equal(expectedData, CodeDescriptions.Error); } diff --git a/MewtocolTests/TestRegisterInterface.cs b/MewtocolTests/TestRegisterInterface.cs index f3acba8..d66daba 100644 --- a/MewtocolTests/TestRegisterInterface.cs +++ b/MewtocolTests/TestRegisterInterface.cs @@ -26,7 +26,7 @@ namespace MewtocolTests { new NRegister(50, _name : null), }; - List expcectedIdents = new List { + List expectedIdents = new List { "D0005000050", //single word register "D0005000050", //single word register "D0005000051", //double word register @@ -39,7 +39,7 @@ namespace MewtocolTests { for (int i = 0; i < registers.Count; i++) { IRegister? reg = registers[i]; - string expect = expcectedIdents[i]; + string expect = expectedIdents[i]; Assert.Equal(expect, reg.BuildMewtocolQuery()); @@ -58,25 +58,38 @@ namespace MewtocolTests { new NRegister(80, _name : null), new NRegister(90, _name : null), new NRegister(100, _name : null), + //boolean - new BRegister(100), - new BRegister(5, RegisterType.X), - new BRegister(SpecialAddress.A, RegisterType.X), + new BRegister(IOType.R, 0, 100), + new BRegister(IOType.X, 5), + new BRegister(IOType.X, 0xA), + new BRegister(IOType.X, 0xF, 109), + new BRegister(IOType.Y, 0xC, 75), + //string new SRegister(999, 5), }; List expcectedIdents = new List { + + //numeric ones "DT50", "DT60", "DDT70", "DDT80", "DDT90", "DDT100", + + //boolean "R100", "X5", "XA", + "X109F", + "Y75C", + + //string "DT999" + }; //test mewtocol idents @@ -104,7 +117,7 @@ namespace MewtocolTests { var ex1 = Assert.Throws(() => { - new BRegister(100000); + new BRegister(IOType.R, _areaAdress: 512); }); @@ -112,12 +125,20 @@ namespace MewtocolTests { var ex2 = Assert.Throws(() => { - new SRegister(100000, 5); + new BRegister(IOType.X, _areaAdress: 110); }); output.WriteLine(ex2.Message.ToString()); + var ex3 = Assert.Throws(() => { + + new SRegister(100000, 5); + + }); + + output.WriteLine(ex3.Message.ToString()); + } [Fact(DisplayName = "Non allowed (Wrong data type)")] @@ -133,32 +154,6 @@ namespace MewtocolTests { } - [Fact(DisplayName = "Non allowed (Wrong bool type address)")] - public void WrongDataTypeRegisterBool1 () { - - var ex = Assert.Throws(() => { - - new BRegister(100, RegisterType.DDT_int); - - }); - - output.WriteLine(ex.Message.ToString()); - - } - - [Fact(DisplayName = "Non allowed (Wrong bool special address)")] - public void WrongDataTypeRegisterBool2 () { - - var ex = Assert.Throws(() => { - - new BRegister(SpecialAddress.None, RegisterType.X); - - }); - - output.WriteLine(ex.Message.ToString()); - - } - } } \ No newline at end of file diff --git a/MewtocolTests/TestRegisterParsing.cs b/MewtocolTests/TestRegisterParsing.cs new file mode 100644 index 0000000..94953fd --- /dev/null +++ b/MewtocolTests/TestRegisterParsing.cs @@ -0,0 +1,84 @@ +using MewtocolNet; +using MewtocolNet.Mewtocol; +using MewtocolNet.Registers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +namespace MewtocolTests; + +public class TestRegisterParsing { + + private readonly ITestOutputHelper output; + + public TestRegisterParsing (ITestOutputHelper output) { + this.output = output; + } + + [Fact(DisplayName = "Parsing as BRegister (Phyiscal Outputs)")] + public void TestParsingBRegisterY () { + + var tests = new Dictionary() { + + {"Y0", new BRegister(IOType.Y)}, + {"Y1", new BRegister(IOType.Y, 0x1)}, + {"Y2", new BRegister(IOType.Y, 0x2)}, + {"Y3", new BRegister(IOType.Y, 0x3)}, + {"Y4", new BRegister(IOType.Y, 0x4)}, + {"Y5", new BRegister(IOType.Y, 0x5)}, + {"Y6", new BRegister(IOType.Y, 0x6)}, + {"Y7", new BRegister(IOType.Y, 0x7)}, + {"Y8", new BRegister(IOType.Y, 0x8)}, + {"Y9", new BRegister(IOType.Y, 0x9)}, + + {"YA", new BRegister(IOType.Y, 0xA)}, + {"YB", new BRegister(IOType.Y, 0xB)}, + {"YC", new BRegister(IOType.Y, 0xC)}, + {"YD", new BRegister(IOType.Y, 0xD)}, + {"YE", new BRegister(IOType.Y, 0xE)}, + {"YF", new BRegister(IOType.Y, 0xF)}, + + {"Y1A", new BRegister(IOType.Y, 0xA, 1)}, + {"Y10B", new BRegister(IOType.Y, 0xB, 10)}, + {"Y109C", new BRegister(IOType.Y, 0xC, 109)}, + + }; + + } + + [Fact(DisplayName = "Parsing as BRegister (Phyiscal Inputs)")] + public void TestParsingBRegisterX () { + + var tests = new Dictionary() { + + {"X0", new BRegister(IOType.X)}, + {"X1", new BRegister(IOType.X, 0x1)}, + {"X2", new BRegister(IOType.X, 0x2)}, + {"X3", new BRegister(IOType.X, 0x3)}, + {"X4", new BRegister(IOType.X, 0x4)}, + {"X5", new BRegister(IOType.X, 0x5)}, + {"X6", new BRegister(IOType.X, 0x6)}, + {"X7", new BRegister(IOType.X, 0x7)}, + {"X8", new BRegister(IOType.X, 0x8)}, + {"X9", new BRegister(IOType.X, 0x9)}, + + {"XA", new BRegister(IOType.X, 0xA)}, + {"XB", new BRegister(IOType.X, 0xB)}, + {"XC", new BRegister(IOType.X, 0xC)}, + {"XD", new BRegister(IOType.X, 0xD)}, + {"XE", new BRegister(IOType.X, 0xE)}, + {"XF", new BRegister(IOType.X, 0xF)}, + + {"X1A", new BRegister(IOType.X, 0xA, 1)}, + {"X10B", new BRegister(IOType.X, 0xB, 10)}, + {"X109C", new BRegister(IOType.X, 0xC, 109)}, + + }; + + } + +}