-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature to use opc-plc as nuget package (#325)
* Update nuget * Use langversion preview * Add pck icon * Add nuget config * Use async wait * Handle possible null * Add static dependencies and unpack to output folder * Cosmetic * Fix amb. namespace * Cosmetic * Incr version * Cosmetic * Fix typos and consistency * Fix typos and consistency * Sync readme CLI options * Fix typos * Simplify namespaces * Cosmetic * Add sample files * Update readme * Update ver
- Loading branch information
1 parent
0cd1420
commit dd2532c
Showing
13 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace UnitTests; | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public class OpcPlcBase | ||
{ | ||
public OpcPlcBase(string[] args, int port = 51234) | ||
{ | ||
// Passed args override the following defaults. | ||
var serverTask = Task.Run(() => OpcPlc.Program.MainAsync( | ||
args.Concat( | ||
new[] | ||
{ | ||
"--autoaccept", | ||
$"--portnum={port}", | ||
"--fn=25", | ||
"--fr=1", | ||
"--ft=uint", | ||
}).ToArray(), | ||
CancellationToken.None) | ||
.GetAwaiter().GetResult()); | ||
|
||
OpcPlcEndpointUrl = WaitForServerUpAsync(serverTask).GetAwaiter().GetResult(); | ||
} | ||
|
||
public string OpcPlcEndpointUrl { get; } | ||
|
||
private static async Task<string> WaitForServerUpAsync(Task serverTask) | ||
{ | ||
while (true) | ||
{ | ||
if (serverTask.IsFaulted) | ||
{ | ||
throw serverTask.Exception!; | ||
} | ||
|
||
if (serverTask.IsCompleted) | ||
{ | ||
throw new Exception("Server failed to start."); | ||
} | ||
|
||
if (!OpcPlc.Program.Ready) | ||
{ | ||
await Task.Delay(1000).ConfigureAwait(false); | ||
continue; | ||
} | ||
|
||
return OpcPlc.Program.PlcServer.GetEndpoints()[0].EndpointUrl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace UnitTests; | ||
|
||
using System.Threading.Tasks; | ||
|
||
public class OpcUaUnitTests : OpcPlcBase | ||
{ | ||
public OpcUaUnitTests() | ||
: base(new[] { "--gn=2" }) // Additional arguments. | ||
{ | ||
} | ||
|
||
[Test] | ||
public async Task TestConnectedClientSession() | ||
{ | ||
var opcUaClient = await OpcUaClientFactory | ||
.GetConnectedClient(OpcPlcEndpointUrl) | ||
.ConfigureAwait(false); | ||
|
||
opcUaClient.Session.Connected.Should().BeTrue(); | ||
opcUaClient.Session.Close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.IoTEdge.OpcPlc" Version="2.10.0-gdd6f023a37" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> | ||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
<add key="LocalPackages" value="./packages" /> | ||
</packageSources> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project> | ||
<ItemGroup> | ||
<Files Include="$(MSBuildThisFileDirectory)/../contentFiles/**/*.*" /> | ||
</ItemGroup> | ||
<Target Name="CopyFiles" AfterTargets="Build"> | ||
<Copy SourceFiles="@(Files)" DestinationFolder="$(TargetDir)/%(RecursiveDir)" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters