mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-15 11:22:52 +00:00
Add linqpad samples
This commit is contained in:
@@ -27,4 +27,10 @@
|
||||
<PackageReference Include="System.Reactive" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="linqpad-samples/**/*.*">
|
||||
<Pack>true</Pack>
|
||||
<PackagePath>linqpad-samples\;content</PackagePath>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
37
Sharp7.Rx/linqpad-samples/Create Notification.linq
Normal file
37
Sharp7.Rx/linqpad-samples/Create Notification.linq
Normal file
@@ -0,0 +1,37 @@
|
||||
<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>
|
||||
|
||||
var ip = "10.30.3.221"; // Set IP address of S7
|
||||
var db = 3; // Set to an existing DB
|
||||
|
||||
// For rack number and cpu mpi address see
|
||||
// https://github.com/fbarresi/Sharp7/wiki/Connection#rack-and-slot
|
||||
var rackNumber = 0;
|
||||
var cpuMpiAddress = 0;
|
||||
|
||||
using var plc = new Sharp7Plc(ip, rackNumber, cpuMpiAddress);
|
||||
|
||||
await plc.InitializeAsync();
|
||||
await plc.ConnectionState
|
||||
.FirstAsync(c => c == Sharp7.Rx.Enums.ConnectionState.Connected)
|
||||
.ToTask();
|
||||
|
||||
"Connection established".Dump();
|
||||
|
||||
// create an IObservable
|
||||
var observable = plc.CreateNotification<short>($"DB{db}.Int6", Sharp7.Rx.Enums.TransmissionMode.OnChange);
|
||||
|
||||
observable.Dump();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
await plc.SetValue($"DB{db}.Int6", (short)i);
|
||||
await Task.Delay(300);
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
4
Sharp7.Rx/linqpad-samples/FileOrder.txt
Normal file
4
Sharp7.Rx/linqpad-samples/FileOrder.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Establish connection.linq
|
||||
Write and read value.linq
|
||||
Create Notification.linq
|
||||
Multiple notifications.linq
|
||||
47
Sharp7.Rx/linqpad-samples/Multiple notifications.linq
Normal file
47
Sharp7.Rx/linqpad-samples/Multiple notifications.linq
Normal file
@@ -0,0 +1,47 @@
|
||||
<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>
|
||||
|
||||
var ip = "10.30.3.221"; // Set IP address of S7
|
||||
var db = 3; // Set to an existing DB
|
||||
|
||||
// For rack number and cpu mpi address see
|
||||
// https://github.com/fbarresi/Sharp7/wiki/Connection#rack-and-slot
|
||||
var rackNumber = 0;
|
||||
var cpuMpiAddress = 0;
|
||||
|
||||
using var plc = new Sharp7Plc(ip, rackNumber, cpuMpiAddress);
|
||||
|
||||
plc.ConnectionState.Dump();
|
||||
|
||||
await plc.InitializeAsync();
|
||||
await plc.ConnectionState
|
||||
.FirstAsync(c => c == Sharp7.Rx.Enums.ConnectionState.Connected)
|
||||
.ToTask();
|
||||
|
||||
// create an IObservable
|
||||
plc.CreateNotification<short>($"DB{db}.Int6", Sharp7.Rx.Enums.TransmissionMode.OnChange).Dump("Int 6");
|
||||
plc.CreateNotification<float>($"DB{db}.Real10", Sharp7.Rx.Enums.TransmissionMode.OnChange).Dump("Real 10");
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
switch (i%3)
|
||||
{
|
||||
case 0:
|
||||
await plc.SetValue($"DB{db}.Int6", (short)i);
|
||||
break;
|
||||
case 1:
|
||||
await plc.SetValue($"DB{db}.Real10", i * 0.123f);
|
||||
break;
|
||||
}
|
||||
|
||||
await Task.Delay(300);
|
||||
}
|
||||
|
||||
|
||||
35
Sharp7.Rx/linqpad-samples/Write and read value.linq
Normal file
35
Sharp7.Rx/linqpad-samples/Write and read value.linq
Normal file
@@ -0,0 +1,35 @@
|
||||
<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>
|
||||
|
||||
var ip = "10.30.3.221"; // Set IP address of S7
|
||||
var db = 3; // Set to an existing DB
|
||||
|
||||
// For rack number and cpu mpi address see
|
||||
// https://github.com/fbarresi/Sharp7/wiki/Connection#rack-and-slot
|
||||
var rackNumber = 0;
|
||||
var cpuMpiAddress = 0;
|
||||
|
||||
using var plc = new Sharp7Plc(ip, rackNumber, cpuMpiAddress);
|
||||
|
||||
await plc.InitializeAsync();
|
||||
await plc.ConnectionState
|
||||
.FirstAsync(c => c == Sharp7.Rx.Enums.ConnectionState.Connected)
|
||||
.ToTask();
|
||||
|
||||
"Connection established".Dump();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
await plc.SetValue($"DB{db}.Int6", (short)i);
|
||||
var value = await plc.GetValue<short>($"DB{db}.Int6");
|
||||
value.Dump();
|
||||
|
||||
await Task.Delay(200);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user