diff --git a/Sharp7.Rx/Sharp7Plc.cs b/Sharp7.Rx/Sharp7Plc.cs index 3bb5ac6..03bda1f 100644 --- a/Sharp7.Rx/Sharp7Plc.cs +++ b/Sharp7.Rx/Sharp7Plc.cs @@ -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(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(variableName)) + // Output results from read loop .Concat( disposableContainer.Observable .Select(bytes => ValueConverter.ReadFromBuffer(bytes, address))