UaModeler
1.4.2.342
|
This tutorial describes how to support structures and events on the server side.
Create a new project as described in steps 1–5 of HowTo: Create a New UaModeler Project With a Method first.
Add a new structured DataType called “Vector” as described in Step 5: Add a Structured Data Type of HowTo Create a New Project With a Structured Data Type.
Add a new ObjectType called MyObjectType to your project (see screenshot).
Add the following children (see screenshot):
Add input and output arguments to the method Move (see screenshot):
Add a new EventType called MyEventType (see screenshot).
Add the following variables to the new EventType (see screenshot):
Select MyObjectType in the Information Model Window and add a new GeneratesEvent reference: Choose NonHierarchicalReferences → GeneratesEvent as Reference Type and MyEventType as Target (see screenshot). This reference has only semantic use.
Generate code for your project as shown in steps 9 and 10 of HowTo: Create a New UaModeler Project With a Method.
Open the project file created in Step 6: Generate Code.
First we’re creating an instance of MyObjectType in the Startup method of the generated NodeManager (in our case in the file ExampleModelNsNodeManager.cs).
Add the following code to the Startup method:
Set initial values for Count and Position in the Startup method:
In addition, it is necessary to implement the method Move. The generated code for methods can be found in the file MyObjectTypeMethods.cs.
Replace the generated code with the following snippet. The initial Position is moved in Direction, Count is increased, and an event is fired.
Compile and run the server, then connect to the server with UaExpert.
To receive Events, choose Document → Add... → Event View from the menu and drag the Server object to the Event View (see screenshot).
Expand the tree and select the event fields of MyEventType (see screenshot).
Right-click on the method Move in the Address Space Window and select Call. Enter a Direction at Input Arguments and call the method. As the initial values for Position were (0|0|0), the NewPosition is identical to the method’s input argument (see screenshot).
The method call triggers an event, which shows up in the respective window in the Event View. Select the event to view the values for each event field (see screenshot).