diff --git a/S7.Net.UnitTest/Helpers/S7TestServer.cs b/S7.Net.UnitTest/Helpers/S7TestServer.cs index 8db9328..401587f 100644 --- a/S7.Net.UnitTest/Helpers/S7TestServer.cs +++ b/S7.Net.UnitTest/Helpers/S7TestServer.cs @@ -29,7 +29,7 @@ namespace S7.Net.UnitTest.Helpers Console.WriteLine(Server.EventText(ref Event)); } - public static void Start() + public static void Start(short port) { Server = new S7Server(); // Share some resources with our virtual PLC @@ -59,7 +59,14 @@ namespace S7.Net.UnitTest.Helpers // Start the server onto the default adapter. // To select an adapter we have to use Server->StartTo("192.168.x.y"). // Start() is the same of StartTo("0.0.0.0"); + + Server.SetParam(S7Consts.p_u16_LocalPort, ref port); + int Error = Server.Start(); + if (Error != 0) + { + throw new Exception($"Error starting Snap7 server: {Server.ErrorText(Error)}"); + } //if (Error == 0) //{ // // Now the server is running ... wait a key to terminate diff --git a/S7.Net.UnitTest/S7.Net.UnitTest.csproj b/S7.Net.UnitTest/S7.Net.UnitTest.csproj index 70f0e07..abbf6c5 100644 --- a/S7.Net.UnitTest/S7.Net.UnitTest.csproj +++ b/S7.Net.UnitTest/S7.Net.UnitTest.csproj @@ -1,15 +1,17 @@  - net452 + net452;netcoreapp3.1 true Properties\S7.Net.snk false Copyright © 2014 + x64 - + + @@ -23,14 +25,13 @@ - + - + PreserveNewest - diff --git a/S7.Net.UnitTest/S7NetTestsAsync.cs b/S7.Net.UnitTest/S7NetTestsAsync.cs index 604e2bb..d317533 100644 --- a/S7.Net.UnitTest/S7NetTestsAsync.cs +++ b/S7.Net.UnitTest/S7NetTestsAsync.cs @@ -6,10 +6,12 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using S7.Net; using S7.Net.UnitTest.Helpers; using S7.Net.UnitTest; -using System.ServiceProcess; using S7.Net.Types; using S7.UnitTest.Helpers; using System.Threading.Tasks; +#if NETFRAMEWORK +using System.ServiceProcess; +#endif using System.Threading; #endregion diff --git a/S7.Net.UnitTest/S7NetTestsSync.cs b/S7.Net.UnitTest/S7NetTestsSync.cs index fd63448..8d713a5 100644 --- a/S7.Net.UnitTest/S7NetTestsSync.cs +++ b/S7.Net.UnitTest/S7NetTestsSync.cs @@ -6,9 +6,11 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using S7.Net; using S7.Net.UnitTest.Helpers; using S7.Net.UnitTest; -using System.ServiceProcess; using S7.Net.Types; using S7.UnitTest.Helpers; +#if NETFRAMEWORK +using System.ServiceProcess; +#endif #endregion @@ -41,6 +43,7 @@ namespace S7.Net.UnitTest #region Constants const int DB2 = 2; const int DB4 = 4; + const short TestServerPort = 31122; #endregion #region Private fields @@ -53,16 +56,21 @@ namespace S7.Net.UnitTest /// public S7NetTests() { - plc = new Plc(CpuType.S7300, "127.0.0.1", 0, 2); + plc = CreatePlc(); //ConsoleManager.Show(); ShutDownServiceS7oiehsx64(); } + private static Plc CreatePlc() + { + return new Plc(CpuType.S7300, "localhost", TestServerPort, 0, 2); + } + [TestInitialize] public void Setup() { - S7TestServer.Start(); + S7TestServer.Start(TestServerPort); plc.Open(); } @@ -931,9 +939,9 @@ namespace S7.Net.UnitTest { plc.Close(); S7TestServer.Stop(); - S7TestServer.Start(); + S7TestServer.Start(TestServerPort); - var reachablePlc = new Plc(CpuType.S7300, "127.0.0.1", 0, 2); + var reachablePlc = CreatePlc(); Assert.IsTrue(reachablePlc.IsAvailable); } @@ -1028,6 +1036,7 @@ namespace S7.Net.UnitTest #region Private methods private static void ShutDownServiceS7oiehsx64() { +#if NETFRAMEWORK ServiceController[] services = ServiceController.GetServices(); var service = services.FirstOrDefault(s => s.ServiceName == "s7oiehsx64"); if (service != null) @@ -1037,6 +1046,7 @@ namespace S7.Net.UnitTest service.Stop(); } } +#endif } #region IDisposable Support diff --git a/S7.Net.UnitTest/Snap7/snap7.net.cs b/S7.Net.UnitTest/Snap7/snap7.net.cs index 98efa75..b6ae831 100644 --- a/S7.Net.UnitTest/Snap7/snap7.net.cs +++ b/S7.Net.UnitTest/Snap7/snap7.net.cs @@ -36,11 +36,8 @@ namespace Snap7 public class S7Consts { - #if __MonoCS__ // Assuming that we are using Unix release of Mono (otherwise modify it) - public const string Snap7LibName = "libsnap7.so"; - #else - public const string Snap7LibName = "snap7.dll"; - #endif + public const string Snap7LibName = "snap7"; + //------------------------------------------------------------------------------ // PARAMS LIST //------------------------------------------------------------------------------ diff --git a/S7.Net.UnitTest/runtimes/win-x64/native/snap7.dll b/S7.Net.UnitTest/runtimes/win-x64/native/snap7.dll new file mode 100644 index 0000000..e1baafc Binary files /dev/null and b/S7.Net.UnitTest/runtimes/win-x64/native/snap7.dll differ diff --git a/S7.Net.UnitTest/snap7.dll b/S7.Net.UnitTest/snap7.dll deleted file mode 100644 index d52c361..0000000 Binary files a/S7.Net.UnitTest/snap7.dll and /dev/null differ