mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Added test structure
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||||||
using MewtocolNet;
|
using MewtocolNet;
|
||||||
using MewtocolNet.Logging;
|
using MewtocolNet.Logging;
|
||||||
using MewtocolNet.Registers;
|
using MewtocolNet.Registers;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
namespace Examples;
|
namespace Examples;
|
||||||
|
|
||||||
@@ -10,6 +11,14 @@ class Program {
|
|||||||
|
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.UnhandledException += (s,e) => {
|
||||||
|
Console.WriteLine(e.ExceptionObject.ToString());
|
||||||
|
};
|
||||||
|
|
||||||
|
TaskScheduler.UnobservedTaskException += (s,e) => {
|
||||||
|
Console.WriteLine(e.Exception.ToString());
|
||||||
|
};
|
||||||
|
|
||||||
Console.WriteLine("Enter your scenario number:\n" +
|
Console.WriteLine("Enter your scenario number:\n" +
|
||||||
"1 = Permanent connection\n" +
|
"1 = Permanent connection\n" +
|
||||||
"2 = Dispose connection");
|
"2 = Dispose connection");
|
||||||
@@ -59,21 +68,21 @@ class Program {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//await interf.ConnectAsync((plcinf) => AfterConnect(interf, registers));
|
|
||||||
|
|
||||||
bool flip = false;
|
|
||||||
while(true) {
|
|
||||||
|
|
||||||
if(!flip) {
|
|
||||||
await interf.ConnectAsync();
|
await interf.ConnectAsync();
|
||||||
} else {
|
|
||||||
interf.Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
flip = !flip;
|
//bool flip = false;
|
||||||
await Task.Delay(5000);
|
//while(true) {
|
||||||
|
|
||||||
}
|
// if(!flip) {
|
||||||
|
// await interf.ConnectAsync();
|
||||||
|
// } else {
|
||||||
|
// interf.Disconnect();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// flip = !flip;
|
||||||
|
// await Task.Delay(5000);
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.30114.105
|
VisualStudioVersion = 17.5.33103.201
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MewtocolNet", "MewtocolNet\MewtocolNet.csproj", "{8B7863E7-5E82-4990-9138-2C0C24629982}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MewtocolNet", "MewtocolNet\MewtocolNet.csproj", "{8B7863E7-5E82-4990-9138-2C0C24629982}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples", "Examples\Examples.csproj", "{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MewtocolTests", "MewtocolTests\MewtocolTests.csproj", "{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -16,9 +18,6 @@ Global
|
|||||||
Release|x64 = Release|x64
|
Release|x64 = Release|x64
|
||||||
Release|x86 = Release|x86
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{8B7863E7-5E82-4990-9138-2C0C24629982}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{8B7863E7-5E82-4990-9138-2C0C24629982}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{8B7863E7-5E82-4990-9138-2C0C24629982}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{8B7863E7-5E82-4990-9138-2C0C24629982}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
@@ -44,5 +43,20 @@ Global
|
|||||||
{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x64.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{D1F2FA26-3752-44BA-9DCB-4BC2436C5957}.Release|x86.Build.0 = 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
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{C1BF3AB0-CDFE-4070-A759-C3B25A20ABE1}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
28
MewtocolTests/MewtocolTests.csproj
Normal file
28
MewtocolTests/MewtocolTests.csproj
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\MewtocolNet\MewtocolNet.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
55
MewtocolTests/TestComProtocol.cs
Normal file
55
MewtocolTests/TestComProtocol.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using MewtocolNet;
|
||||||
|
using MewtocolNet.Registers;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace MewtocolTests {
|
||||||
|
|
||||||
|
public class TestComProtocol {
|
||||||
|
|
||||||
|
private readonly ITestOutputHelper output;
|
||||||
|
|
||||||
|
public TestComProtocol (ITestOutputHelper output) {
|
||||||
|
this.output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact(DisplayName = "Numeric register protocol identifiers")]
|
||||||
|
public void NumericRegisterMewtocolIdentifiers () {
|
||||||
|
|
||||||
|
List<Register> registers = new List<Register> {
|
||||||
|
new NRegister<short>(50),
|
||||||
|
new NRegister<ushort>(50),
|
||||||
|
new NRegister<int>(50),
|
||||||
|
new NRegister<uint>(50),
|
||||||
|
new NRegister<float>(50),
|
||||||
|
new NRegister<BitArray>(50),
|
||||||
|
};
|
||||||
|
|
||||||
|
List<string> expcectedIdents = new List<string> {
|
||||||
|
"D0005000050", //single word register
|
||||||
|
"D0005000050", //single word register
|
||||||
|
"D0005000051", //double word register
|
||||||
|
"D0005000051", //double word register
|
||||||
|
"D0005000051", //double word register
|
||||||
|
"D0005000051", //double word register
|
||||||
|
"D0005000051", //double word register
|
||||||
|
};
|
||||||
|
|
||||||
|
//test mewtocol idents
|
||||||
|
for (int i = 0; i < registers.Count; i++) {
|
||||||
|
|
||||||
|
Register? reg = registers[i];
|
||||||
|
string expect = expcectedIdents[i];
|
||||||
|
|
||||||
|
Assert.Equal(expect, reg.BuildMewtocolIdent());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user