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); disposableContainer.AddDisposableTo(disp);
var observable = var observable =
// Read variable with GetValue first. ConnectionState
// This will propagate any errors due to reading from invalid addresses. // Wait for connection to be established
Observable.FromAsync(() => GetValue<TValue>(variableName)) .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( .Concat(
disposableContainer.Observable disposableContainer.Observable
.Select(bytes => ValueConverter.ReadFromBuffer<TValue>(bytes, address)) .Select(bytes => ValueConverter.ReadFromBuffer<TValue>(bytes, address))