Expose Custom Data in Automation System
Introduction
The purpose of this example is to show how to create your own structures/configurations in CDP Studio, the independent automation software for open PC-based real-time distributed control systems.
This provides a way to define advanced configuration structures insides function blocks using no-code programming with our tool similar the PLC IEC 61131-3 programming.
The example extends CDPComponent by using a CDPNode, which is a common base class that enables exposing application structure through StudioAPI. A standard CDPComponent contains Signals, Parameters, Alarms, Properties and so on, which you may configure in Studio's Configure mode. At some point you may need to put your own additional data/configuration in a CDPComponent. Examples:
- you are making your own component for custom made HW, and need to define sections where you can configure Digital Inputs/Outputs and Analogue Inputs/Outputs
- you need to read data from specified db-files and tables
- you need to set up different sensors and configuration of them and so on.
Configure mode has both Offline view and Online view. In Offline view you can configure values locally, which will be downloaded to target application when choosing Run & Connect on system later. When the application is running and connected to CDP Studio (Online view), live structures and data-values from the running system are shown in Configure mode.
The 3 examples below will show you what you need to do to get a new configurable section, and how to get/show data-values in Configure mode for both Offline view and Online view. In Configure mode, Offline view, it is basically the model-files that decide what will be shown and what is allowed to configure. To make the additional data-values appear in Studio in Online view, you need to add some extra C++-code to your library.
Important definitions:
Component model | A Component model consist of both a C++-class and a model xml-file. Both the C++-class and the model xml-file may inherit other classes/models. In the model xml-file, you may also list which other objects/resources you are allowed to add to the component in Studio's Configure mode when you have clicked on the component. In the Code mode Project tree (under your library) you will find the C++-class files under Headers and Sources, while the model xml-files are found under 'Other files' Templates\Models. |
Component | A CDPComponent is an instance of a CDP component model, instantiated using the specification in the component configuration xml file. You may have several CDPComponents in your application of the same model, having slightly different configurations like different routing and values for properties and Parameters. In the Code mode Project tree (under your system's application) you will find the component xml-files under 'Other files' Application and Components. |
CDPNode | A CDPNode is a common base class that enables exposing application structure through StudioAPI. For instance, CDPComponents inherit CDPNode. When adding your own structures/configurations in a CDPComponent, these structures should inherit/be based on CDPNode. |
CDPNode Exposes Structure
One way to add your own structures/configurations in a CDPComponent is to build structures based on CDPNode. These examples show you how to do this. Some coding is required, as CDPNode has a few functions which must be overridden, like CDPNode::GetNodeName(), CDPNode::GetNodeTypeName() and CDPNode::FillNodeChildren().
Note: Without overriding these functions, your new structures and values will not show up in CDP Studio in Online view.
When adding a CDPNode to your library from the CDPNode wizard, the CDPNode has one property to contain a user-value (in addition to the standard attributes/properties called "Model" and "Description"). In the model-file, this property is called "UserAttribute" of type "string" with default-value "Simple attribute". Other properties/value-types may be added, see Example B-2.
How to Run the Example
To run the example from CDP Studio, open Welcome mode and find it under Examples. Next, in Configure mode right-click on the system project and select Run & Connect. See the Running the Example Project tutorial for more information. The example-code contains the full code (except Example B-2) so you can try it in CDP Studio, or use the code as a look-up if you need to see how it is done. The description in the examples explains how to get to this state, starting from scratch.
Overview of the Examples
All the examples are based on a CDPComponent that aggregates sub-nodes of base class CDPNode. Each example (Except Example A-2) is configured such that it is possible to add (drag) nodes to the component in CDP Studio when configuring a System. The examples show how to modify the models to accept specific models.
Below is an overview of the examples.
Example A - Basic Node Config and Pre-Configuration
In Example A, the model UserComponentA is modified so you are allowed to add nodes of model UserNodeA. In addition, the component model is pre-configured with 2 nodes. This can be useful if you want that all components of this type shall minimum contain 2 such nodes. Pre-configured nodes are greyed out and can not be deleted in Configure mode. Click here to see how component UserComponentA.xml looks like for added nodes. In CDP Studio, nodes of model UserNodeA will be added to specified section 'UserNodeA':
Example A-2 describes what you need to do to, if you e.g. want to have the 2 first UserNodeA in your component, but also inhibit the possibility to add any more nodes of type UserNodeA.
Example B - Nodes Within a Group
In Example B, the model UserComponentB is modified so you are allowed to add nodes of model UserNodeB. The component model is not pre-configured with any nodes. In component UserComponentB.xml, all UserNodeB-nodes will be stored inside group 'UserNodesB' (differently than in component UserComponentA.xml), see here. In CDP Studio, nodes of model UserNodeB will be added to specified section 'UserNodesB':
Example B-2 describes what you need to do to add 2 new properties (one of type double and one of type int) to UserNodeB. The section in CDP Studio will be the same as in Example B, but UserNodeB has got two new properties (MyDouble and MyInt) of type double and int:
Example C - Nodes with Sub-Nodes
In Example C, the model UserComponentC is modified so you are allowed to add nodes of model UserNodeC. In addition, UserNodeC is modified so you are allowed to add nodes of model UserNodeC2. The component model is not pre-configured with any nodes. In component UserComponentC.xml, all UserNodeC-nodes will be stored inside group 'UserNodesC', and all UserNodeC2-nodes will be stored inside group 'UserNodesC2', see here. Underscore have been used in the node-names in this example, just to avoid having a node-name ('UserNodeC2') similar to the model-name, but we could have done it since it is not equal to the full model-name ('UserDefinedStructureLib.UserNodeC2'). In CDP Studio, nodes of model UserNodeC will be added to specified section 'UserNodesC':
After clicking into one of the nodes, you will have another section with more nodes (Section/group-name specified to 'UserNodesC2', and possibility to add as many nodes (of model UserNodeC2) as wanted):
Additional Information
The demo requires you to be familiar with library creation and provided wizards (right-click in the library and choose Add New... from the context menu). When this is new to you please see the following getting started guide: How to Create a Library. The library in this demo has been called UserDefinedStructureLib.
The base code of this library demo has been created by using the CDP Component Model and CDP Node Model wizards, and the classes are called UserComponentA-C and UserNodeA-C (and UserNodeC2). The 3 examples describe all steps you need to do when you start with the base library.
Modifications and differences:
UserComponentA | Modified so nodes of type UserNodeA can be added. In CDP Studio, nodes will be added to specified section 'UserNodeA'. Nodes will not be added to any specified group in component xml. Pre-configured with 2 nodes of UserNodeA. |
UserComponentB | Modified so nodes of type UserNodeB can be added. In CDP Studio, nodes will be added to specified section 'UserNodesB'. In component xml, nodes will also be added to specified group 'UserNodesB'. |
UserComponentC | Modified so nodes of type UserNodeC can be added. In CDP Studio, nodes will be added to specified section 'UserNodesC'. In component xml, nodes will also be added to specified group 'UserNodesC'. |
UserNodeA | Standard model created by CDP Node Model wizard, no changes done. Have one "UserAttribute" of type "string" with configurable value. |
UserNodeB | Standard model created by CDP Node Model wizard, no changes done. Have one "UserAttribute" of type "string" with configurable value. In Example B-2, UserNodeB.h and UserNodeB.cpp are modified, see Example B-2 for changes. |
UserNodeC | Standard model created by CDP Node Model wizard modified so you can add nodes of type UserNodeC2. Added nodes will be put into specified section called "UserNodesC2". |
UserNodeC2 | Standard model created by CDP Node Model wizard, only one minor change done in UserNodeC2.h and UserNodeC2.cpp, see Changes to UserNodeC2. Have one "UserAttribute" of type "string" with configurable value. |
The UserDefinedStructureLib is a library with 3 CDPComponents and 4 CDPNodes created by CDP Component Model and CDP Node Model wizards:
You will find the 3 examples here:
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.