How Do I Programmatically Select My NI OPC Server Configuration?
Primary Software: LabVIEW Modules>>DSC Module
Primary Software Version: 8.6
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Modules>>DSC Module
Problem: I have multiple OPC server configurations that I would like to be able to select programmatically. How can I do this in LabVIEW using the LabVIEW DSC Module?
Solution: The best way to programmatically change the OPC Server Configuration is to stop the OPC Service and have it restart with a different .OPF file (the OPC Server Configuration file). To do this, follow these steps:
- Open up the NI OPC Server from Start»Programs»National Instruments»NI OPC Servers»NI OPC Servers.
- In the OPC Server, navigate to Tools»Options and select the Service tab. Make sure that "Automatically start as a Windows NT service" is checked. This will register the NI OPC Service so that it can be started and stopped programmatically.
-
If your OPC Service is currently running, stop the service by sending a 'net stop "NI OPC Service" ' command to the
System Exec.vi. This will be equivalent to typing the command in the command line. The
System Exec.vi is located on the block diagram in
Communication»Libraries and Executables»System Exec.vi. It is important to stop the service before selecting a new OPF file because if not, the file you select will be overwritten when the service is stopped.

- Once the service is stopped, you can select a new OPF file for the service to load next time it executes. To do this, you must change the file path of the Default Project in the ServerMain.ini. The default location of this file is C:\Program Files\National Instruments\Shared\NI OPC Servers\ServerMain.ini. One way to do this programmatically is to use the Configuration File VIs located in Programming»File I/O»Configuration VIs. First open the configuration file using the above file path. Then write to the Default Project key located in the Service section of the file using the Write Key.vi. Then specify the file path of the OPF file you would like to write to that location. Also make sure that you connect a true constant to the write raw string? input of the Write Key.vi. This will ensure that the string you input is not reformatted incorrectly. Finally, close the configuration file. An example of how to do this is shown below.
- Now that the new configuration has been selected, you can restart the service by sending a 'net start "NI OPC Service" ' command to the System Exec.vi. Once the service is restarted, the OPC Server will reflect the new OPF file it loaded.
Related Links:
Attachments:
System Exec.PNG
Config File.PNG
Report Date: 12/15/2008
Last Updated: 12/31/2008
Document ID: 4SEE28MK