private static bool EvaluateStatus(IPlcStatusProvider provider) { // By default any PlcStatusCode unequal to NoError will lead to a PlcException. // In this scenario we ignore the case that a PLC device can be temporary offline // and therefore unavailable. Additionally we do also ignore Timeouts in cases of // a bad network connection and access to missing data areas (NoData). PlcStatus status = provider.Status; Console.WriteLine(); Console.WriteLine("--> {0}.Status.Evaluate: {1}", provider.GetType().Name, status.Code); Console.WriteLine("----> TimeStamp: {0}", status.TimeStamp.ToString("hh:mm:ss.fff")); Console.WriteLine("----> Text: {0}", status.Text); if (status.Type != null) { Console.WriteLine("----> Type: {0}", status.Type); } PlcStatusCode statusCode = status.Code; return(statusCode == PlcStatusCode.NoError || statusCode == PlcStatusCode.CpuNotFound || statusCode == PlcStatusCode.Timeout || statusCode == PlcStatusCode.NoData); // Instead of the whole code above is also possible to clear out all types of error and // information codes by just always returning the value true. The value true does // indicate that each status of any provider has been evaluated by custom code and no // further framework evaluation is required. //// return true; }
private void evaluateStateBit(bool stateBit, bool unknownValue = false) { var now = DateTime.Now; if (stateBit != _prevBitState) { log.Info($"cambio stato: da {_prevBitState} a {stateBit}"); _prevBitState = stateBit; _prevTime = now; _plcBit.OnNext(stateBit); if (_prevStatus != PLC.PlcStatus.Ok) { log.Warn($"rientro dallo stato di allerta: da {_prevStatus} a {PLC.PlcStatus.Ok}"); _prevStatus = PLC.PlcStatus.Ok; _plcStatus.OnNext(_prevStatus); } } else { log.Debug($"check threshold"); TimeSpan ts = (now - _prevTime); if (ts > _timeThreshold) { log.Warn($"soglia superata da {ts.TotalMilliseconds} millis"); if (_prevStatus == PLC.PlcStatus.Ok) { _prevStatus = (unknownValue ? PLC.PlcStatus.NotResponding : PLC.PlcStatus.ThresholdReached); _plcStatus.OnNext(_prevStatus); } } } }
private static void HandleValueStatusChanged(object sender, EventArgs e) { // The Status.Changed event does provide low level operational status information and // does therefore reflect the result of the most recent operation performed on the low // level driver used by the framework. PlcStatus status = (PlcStatus)sender; Console.WriteLine(); Console.WriteLine("--> Value.Status.Change: {0}", status.Code); Console.WriteLine("----> TimeStamp: {0}", status.TimeStamp.ToString("hh:mm:ss.fff")); Console.WriteLine("----> Text: {0}", status.Text); if (status.Type != null) { Console.WriteLine("----> Type: {0}", status.Type); } }
public PlcStatusArgs(PlcStatus status) { this.plcStatus = status; }