How to check peripheral is alive using heartbeat

Hello object developers,

I created object+interface+peripheral for a device which provides heartbeat (alive) Bit. I read this bit in OnEcUpdateIntputs of my peripheral object and now I would like to display an error event if the alive Bit is not changing.

I have some idea how to deal with that, but I am not sure what is the right way. So here is my proposal:

  1. Evaluate bit is changing on peripheral side and transfer the state (IsAlive) to top level object using interface.
  2. Check the status of IsAlive in OnUnitOperational of Unit and trigger event if it is not present.

Is it right or should I do that differently?

Best reply by Düscha

You can set the error directly in your peripheral with method SetDeviceError.

If you using SetDeviceError method you must clear the error in the base to.

SUPER^.ClearError();

In your unit you check for example in the method OnUnitOperational is the error set in peripheral and than you set wit the method SetExtEvent the error on HMI and bring your unit to state ERROR.

VAR

_deviceError : OpconDeviceError;

END_VAR

 

_deviceError := YourInterfaceToPeripheral.LastError;

SetExtEvent(OpconEventClass.Error,_deviceError.Number,_deviceError.AddText,_deviceError.ObjectId,TRUE/FALSE);

View original
3 replies
Resolved