mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Changed boolean register usage and attributes
This commit is contained in:
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace MewtocolTests {
|
||||
|
||||
};
|
||||
|
||||
Assert.Equal(expectedData, LinkedData.ErrorCodes);
|
||||
Assert.Equal(expectedData, CodeDescriptions.Error);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace MewtocolTests {
|
||||
new NRegister<TimeSpan>(50, _name : null),
|
||||
};
|
||||
|
||||
List<string> expcectedIdents = new List<string> {
|
||||
List<string> expectedIdents = new List<string> {
|
||||
"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<uint>(80, _name : null),
|
||||
new NRegister<float>(90, _name : null),
|
||||
new NRegister<TimeSpan>(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<string> expcectedIdents = new List<string> {
|
||||
|
||||
//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<NotSupportedException>(() => {
|
||||
|
||||
new BRegister(100000);
|
||||
new BRegister(IOType.R, _areaAdress: 512);
|
||||
|
||||
});
|
||||
|
||||
@@ -112,12 +125,20 @@ namespace MewtocolTests {
|
||||
|
||||
var ex2 = Assert.Throws<NotSupportedException>(() => {
|
||||
|
||||
new SRegister(100000, 5);
|
||||
new BRegister(IOType.X, _areaAdress: 110);
|
||||
|
||||
});
|
||||
|
||||
output.WriteLine(ex2.Message.ToString());
|
||||
|
||||
var ex3 = Assert.Throws<NotSupportedException>(() => {
|
||||
|
||||
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<NotSupportedException>(() => {
|
||||
|
||||
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<NotSupportedException>(() => {
|
||||
|
||||
new BRegister(SpecialAddress.None, RegisterType.X);
|
||||
|
||||
});
|
||||
|
||||
output.WriteLine(ex.Message.ToString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
84
MewtocolTests/TestRegisterParsing.cs
Normal file
84
MewtocolTests/TestRegisterParsing.cs
Normal file
@@ -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<string, IRegister>() {
|
||||
|
||||
{"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<string, IRegister>() {
|
||||
|
||||
{"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)},
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user