Wait for connection before setting up notification

This commit is contained in:
Peter Butzhammer
2024-07-30 12:13:50 +02:00
parent 79031d6f1c
commit a2b6d84862

View File

@@ -105,9 +105,13 @@ public class Sharp7Plc : IPlc
disposableContainer.AddDisposableTo(disp);
var observable =
// Read variable with GetValue first.
// This will propagate any errors due to reading from invalid addresses.
Observable.FromAsync(() => GetValue<TValue>(variableName))
ConnectionState
// Wait for connection to be established
.FirstAsync(c => c == Enums.ConnectionState.Connected)
// Read variable with GetValue first.
// This will propagate any errors due to reading from invalid addresses.
.SelectMany(_ => GetValue<TValue>(variableName))
// Output results from read loop
.Concat(
disposableContainer.Observable
.Select(bytes => ValueConverter.ReadFromBuffer<TValue>(bytes, address))