The server configuration consists of two main parts:
-
Server operating mode selections
- Item Configuration
The customization module file IGeneric.cs/vb contains wrappers for the callback methods and default implementations of all methods called by the generic server. It is recommended not to modify this file but to implement a method overload in the file ServerAdapt.cs/vb for all methods that need to be customized.
The configuration methods are:
This methods contain the code to select the mode settings selected in the DANSrv project generation wizard.
Additionally these methods try to read definitions from the file DANSrv.exe.config and use these definitions if found.
The DANSrv project generation wizard creates a configuration file with the settings according the selection in the wizard GUI. The configuration file is only required if the settings need to be changed without a recompilation.
Sample DANSrv.exe.config file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <!-- Server registry definitions --> <add key="ClsidServer" value="{FD588D18-E4AD-4F5D-8B5B-D54541913F0D}"/> <add key="ClsidServer" value="{38E22F8D-F91D-49F1-86FD-E47740A4F1D3}"/> <add key="ServerProgID" value="TS.CSMinimalDA"/> <add key="CurrServerProgID" value="TS.CSMinimalDA.1"/> <add key="ServerName" value="TS.CSMinimalDA DA Server"/> <add key="CurrServerName" value="TS.CSMinimalDA DA Server"/> <add key="CompanyName" value="Advosol Inc."/> <!-- Server operation definitions --> </appSettings> </configuration> |
If an application requires the configuration settings to be handled differently then the configuration methods should be implemented in the ServerAdapt.cs/vb file and overload the default implementation in IGeneric.cs/vb.
Item Configuration
If the ConfigBuilder Class option is checked in the DANSrv project creation wizard then the GetServerParameters() default implementation in IGeneric.cs/vb tries to load the DANSrv.Items.xml file, first the external file and if it's not found tries to load the items from the embedded file.
The sample code in ServerAdapt.cs/vb uses the loaded configuration and creates the items defined in the XML file. After the items are created the server is functional and typically a thread is started that handles the device access and the refresh of the server cache.
new public int CreateServerItems( string commandLineParams ) { // Create all items supported by this server. // The DANSrv.Items.XML configuration file was loaded in GetServerparameters int rtc = Config.CreateServerItems( cbAddItem ); if( HRESULTS.Succeeded(rtc) ) { // Create a thread to simulate signal changes and update the server cache. // In real applications this thread reads data from the device. myThread = new Thread( new ThreadStart( UpdateThread ) ) ; myThread.Name = "Item Update/Simulation" ; myThread.Start(); } return rtc; } |
If no XML item definition file is accessible then the items have to be defined in some other way, either statically or dynamically.