UA Bundle SDK .NET  2.2.1.258
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
Lesson 5: Adding support for Events

Adding Event support to Server

Added Event Type ControllerEventType with UaModeler Implement Event generation

Figure 5.1:

Get state change events from system

public override void Startup()
{
try
{
// initialize the underlying system.
m_system.Initialize();
// New Code Begin
// subscribe to state changed events.
m_system.BlockStateChanged += new BlockStateChangedEventHandler(UnderlyingSystem_BlockStateChanged);
// New Code End

Register event handler with underlying system

Create Notifier Hierarchy

Server → Controller Folder

// Create a Folder for Controllers
CreateObjectSettings settings = new CreateObjectSettings()
{
ParentNodeId = ObjectIds.ObjectsFolder,
ReferenceTypeId = ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("Controllers", InstanceNamespaceIndex),
BrowseName = new QualifiedName("Controllers", InstanceNamespaceIndex),
TypeDefinitionId = ObjectTypeIds.FolderType,
// New Code Begin
// need to create a notifier hierarchy for events to propagate.
NotifierParent = ObjectIds.Server
// New Code End
};
CreateObject(Server.DefaultRequestContext, settings);

Controller Folder → Controller (event source)

// create object.
settings = new CreateObjectSettings()
{
ParentNodeId = new NodeId("Controllers", InstanceNamespaceIndex),
ReferenceTypeId = ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId(block.Name, InstanceNamespaceIndex),
BrowseName = new QualifiedName(block.Name, TypeNamespaceIndex),
TypeDefinitionId = typeDefinitionId,
// New Code Begin
// need to create a notifier hierarchy for events to propagate.
NotifierParent = new NodeId("Controllers", InstanceNamespaceIndex)
// New Code End
};
CreateObject(Server.DefaultRequestContext, settings);

Report the event

private void UnderlyingSystem_BlockStateChanged(int blockAddress, string blockName, int state)
{
// create the event.
GenericEvent e = new GenericEvent(Server.FilterManager);
// initializ base event type fields
e.Initialize(
null, // EventId created by SDK if null
new NodeId(yourorganisation.BA.ObjectTypes.ControllerEventType, TypeNamespaceIndex), // EventType
new NodeId(blockName, InstanceNamespaceIndex), // SourceNode
blockName, // SourceName
EventSeverity.Medium, // Severity
"A controller state changed."); // Message
// set additional event field State
e.Set(e.ToPath(new QualifiedName(yourorganisation.BA.BrowseNames.State, TypeNamespaceIndex)), state);
// report the event.
ReportEvent(e.SourceNode, e);
}

Figure 5.2:

  • Document → Add…
  • Select Document “Event View”
  • Drag & Drop Server object to Event View
  • Call Methods Stop and Start on controller objects