.NET Based OPC UA Client/Server SDK
Lesson 6: Adding Support for Alarms & Conditions

In this example we extend the ControllerType defined in Lesson 2 by adding an instance of an alarm: We add a new Object called StateCondition having the TypeDefinition OffNodemalAlarmType (see Figure 6.1).

Figure 6.1: New StateCondition Object

Open the UaModeler project created in Lesson 2. Add a new Object called “StateCondition” as a child of ControllerType and choose “OffNormalAlarmType” as TypeDefinition (see Figure 6.2).

Figure 6.2: Add Alarm Object

Then regenerate the source files, export the model as xml file and replace the files BAIdentifiers.cs and buildingautomation.xml in your project.

After adding the controller object, we create an instance of the OffNormalAlarmModel. This class is used to store all data related to the OffNormalAlarmType. With LinkModelToNode the SDK maps the data defined in the instance to the nodes in the address space.

// Set alarm condition nodeId

We change the state of the alarm in the BlockStateChanged EventHandler.

NodeId alarmId = new NodeId(blockName + "." + yourorganisation.BA.BrowseNames.StateCondition, InstanceNamespaceIndex);
OffNormalAlarmModel alarm = (OffNormalAlarmModel)GetNodeUserData(alarmId);
// Change state of StateCondition
lock (alarm)
alarm.LastSeverity.Value = alarm.Severity;
alarm.LastSeverity.SourceTimestamp = alarm.Time;
if (state == 0)
// Change state to active
alarm.Severity = (ushort)EventSeverity.High;
// Change state to inactive
alarm.Severity = (ushort)EventSeverity.Low;

Finally, we have to add handling for Acknowledge calls by clients. Therefore, we need to override the Acknowledge method defined at the BaseNodeManager.

public override StatusCode Acknowledge(
RequestContext context,
AcknowledgeableConditionModel model,
byte[] eventId,
LocalizedText comment)
lock (model)
return model.Acknowledge(eventId, comment, context.UserIdentity.UserName);

To test the alarm, open a new Event View in UaExpert and change to the “Alarms” tab (see Figure 6.3). The alarm can be triggered by calling the methods “Start” and “Stop”. Right click on an Alarm to acknowledge, confirm, or add a comment.

Figure 6.3: Alarms in UaExpert