mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-16 19:52:53 +00:00
Add linqpad samples
This commit is contained in:
39
Sharp7.Rx/linqpad-samples/Establish connection.linq
Normal file
39
Sharp7.Rx/linqpad-samples/Establish connection.linq
Normal file
@@ -0,0 +1,39 @@
|
||||
<Query Kind="Statements">
|
||||
<NuGetReference Prerelease="true">Sharp7.Rx</NuGetReference>
|
||||
<Namespace>Sharp7.Rx</Namespace>
|
||||
<Namespace>System.Reactive.Linq</Namespace>
|
||||
<Namespace>System.Reactive.Threading.Tasks</Namespace>
|
||||
<Namespace>System.Threading.Tasks</Namespace>
|
||||
</Query>
|
||||
|
||||
// Set IP address of S7
|
||||
var ip = "10.30.3.221";
|
||||
|
||||
// For rack number and cpu mpi address see
|
||||
// https://github.com/fbarresi/Sharp7/wiki/Connection#rack-and-slot
|
||||
var rackNumber = 0;
|
||||
var cpuMpiAddress = 0;
|
||||
|
||||
// Create Sharp7Plc
|
||||
using var plc = new Sharp7Plc(ip, rackNumber, cpuMpiAddress);
|
||||
|
||||
// Initialize connection
|
||||
await plc.InitializeAsync();
|
||||
|
||||
// wait for connection to be established
|
||||
await plc.ConnectionState
|
||||
.FirstAsync(c => c == Sharp7.Rx.Enums.ConnectionState.Connected)
|
||||
.ToTask();
|
||||
|
||||
"Connection established".Dump();
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(Timeout.Infinite, this.QueryCancelToken);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
"Script stopped by user. Disconnecting by disposing plc.".Dump();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user