The items supported by the server need to be defined in the generic server cache and can be declared in different ways:
- within the code of the Customization module
- loaded from an XML configuration file
- dynamically added on demand
Dynamic Item Configuration
Some applications have so many possible items, that a static definition of all items is not feasible.
The DANSrv Professional Edition supports the dynamic adding of items to the server's address space. The plug-in is called when a client accesses an item that is not yet defined in the server cache. The plug-in can add the item if it is valid.
A dynamic address space typically requires the item browsing to be implemented so that all items are returned that could be added. This allows the client to search for possible items. The DANSrv does forward browse calls to the plug-in if browse mode VIRTUAL is configured.
Static Item Configuration
All server supported items are defined at startup. Depending on the application the items can be queried from the device or be declared in the server.
If the items are declared in the server then this can be done in the code or in a file. Definition in the code gives the security that the item definition cannot be changed without a recompilation. Definition in a file gives the flexibility to change the item configuration without changing the code.
Item definitions in a file can still be protected against changes by embedding the file into the server customization DLL.
XML File based Item Configuration
XML file based item configuration is supported only by the DANSrv Professional Edition.
The XML configuration file can be created with the ConfigBuilder tool and the ConfigBuilder helper class loads the XML file and creates the items according the definitions.
The ConfigLoader class is provide in C#/VB.NET source code in the sample servers CSsampleCB respectively VBsampleCB.
The XML configuration file can be:
- a file in the same directory as the EXE file, allowing item configuration changes without re-compilation
The configuration is loaded using the LoadFromExeDir method
- embedded into the customization assembly to hide it and prevent alterations
To embed the XML item configuration file in the customization plug-in, the XML file has to be included in the Visual Studio project and the 'Build Action' has to be set to 'Embedded Resource'
The configuration has to be loaded using the LoadEmbedded method and the file name has to be qualified with the NSPlugin namespace, e.g. "NSPlugin.CfgSample.xml"
The configuration XML file contains information required to:
- create the item in the generic OPC server
- access the device associated with the item
The data from the XML configuration file is loaded into an array of ItemData objects. The ItemData class inherits from the ItemElement class used in the ConfigBuilder tool and the XML file. The ItemData class can be extended to contain applications specific run-time data, allowing the item definitions array to be used as a data cache.