I am connecting to a kepware server using UAMonitoredItemChangedObservable. I find I don't get notified if the server gets switched off. Is this expected.
For reference I have ended up pinging the server every 60 seconds as below I wonder if there is a better solution you could suggest ? (I realise could use one common tag for the server and channel rather than pinging each tag)
public class ItemValue
{
public object Value { get ; set;}
public bool Good { get;set;}
static public IObservable<ItemValue> UaObservable(object status, string endpoint, string node, int updateInterval, string type)
{
var args = new EasyUAMonitoredItemArguments(
status,
endpoint,
node,
updateInterval
);
var uaClient = new EasyUAClient();
var check = (Observable.Return<long>(0).Concat(Observable.Interval(
TimeSpan.FromSeconds(60))).Select(t =>
{
try
{
return uaClient.Read(
endpoint,
node
).HasGoodStatus;
}
catch (Exception)
{
return false;
}
}
).Distinct());
return check.SelectMany(c =>
{
if (!c)
{
return Observable.Return(new ItemValue{Good=false});
}
else
{
IObservable<EasyUAMonitoredItemChangedEventArgs> ret = null;
switch (type)
{
case "int":
ret = UAMonitoredItemChangedObservable.Create<int>(args);
break;
case "bool":
ret = UAMonitoredItemChangedObservable.Create<bool>(args);
break;
case "double":
ret = UAMonitoredItemChangedObservable.Create<double>(args);
break;
case "float":
ret = UAMonitoredItemChangedObservable.Create<Single>(args);
break;
default:
ret = UAMonitoredItemChangedObservable.Create<string>(args);
break;
}
return ret.Select(
r => new ItemValue
{
Value = r.AttributeData != null ? r.AttributeData.Value : null,
Good = r.AttributeData != null && r.AttributeData.StatusCode.ToString().StartsWith("Good")
}
);
}
});
}
}