Overview
Learn how to connect to a networked PLC using the LabVIEW Project and network shared variables to bring data into LabVIEW.
This exercise was designed for the LabVIEW Online Evaluation Environment. This exercise could be completed on any Windows PC that has LabVIEW with the Datalogging and Supervisory Control Module and NI OPC Servers installed.

The LabVIEW 8.5 DSC Module makes LabVIEW an OPC Client, enabling LabVIEW to communicate with any OPC DA 3.0 and 2.x compliant OPC servers. With this added feature, we can make LabVIEW DSC a great HMI/SCADA package for industrial control applications.
Viewing the Existing PLCs’ OPC Tags in NI OPC Servers
- Launch NI OPC Servers by selecting Start » Programs » National Instruments » NI OPC Servers » NI OPC Servers. With NI-OPC Servers, we can create, configure and view tags that are linked to our PLCs.
- NI OPC Servers should launch with a PLC simulation project already loaded. This project simulates PLCs that have already been created and configured in NI OPC Servers.
Note: If this simulation project is not already loaded, in NI OPC Servers, select File » Open… and browse to C:\Program Files\National Instruments\Shared\NI OPC Servers\Projects\simdemo.opf. The project should look as displayed in figure 2 below.

Figure 2 NI OPC Servers displaying simulated PLCs
- View the Sine tags by expanding Channel_0_User_Defined and selecting Sine. The tags should populate the right-most window. Tags are what we use to connect LabVIEW to the PLCs as these preconfigured tags are pointing at the simulated PLCs’ registers.
- View the data from the PLCs’ OPC tags
- In NI OPC Servers, go to Tools » Launch OPC Quick Client. This will launch the OPC Quick Client that allows the viewing of the data from our PLCs’ OPC tags.
- Expand the National Instruments.NIOPCServers folder and select Channel_0_User_Defined.Sine. This selects the device to monitor.
- Notice that all the Sine tags populate the right most window and are updating with simulated sine data as shown in figure 3 below.

Figure 3 NI OPC Quick Client displaying PLCs’ OPC tags linked to simulated PLC
Note: For a list of supported devices/drivers for NI OPC, visit ni.com/opc.
Creating an I/O Server to Connect LabVIEW to the PLCs’ OPC Tags
- In the Getting Started window of LabVIEW, click File » New Project. This will open a new project explorer window.
- If the Context Help window is not visible, press the <Ctrl-H> keys to display the window.
- Create and configure a new I/O server.
- Right click on My Computer and select New » I/O Server. We will use this I/O server to link LabVIEW to NI OPC Servers.
![CropperCapture[1] CropperCapture[1]](/cms/images/devzone/tut/Project New Server.jpg)
Figure 4 Creating a new I/O Server through the LabVIEW Project
- Select OPC Client in the Create New I/O Server Window and hit Continue. OPC Client, Alarm Printer, Data Set Marking, EPICS Client, Modbus, Modbus Slave and Custom I/O Server install with the LabVIEW 8.5 DSC module.
- Choose National Instruments.NIOPCServers from the registered OPC server list and set the update rate to be 100ms. This will create a connection between NI OPC Servers to LabVIEW.
![CropperCapture[3] CropperCapture[3]](/cms/images/devzone/tut/Config OPC Server.jpg)
Figure 5 Configuring the OPC Client I/O Server
- Select OK. A library will automatically be created in your project explorer window to manage the I/O Server.
- Right click on My Computer and select New » I/O Server. We will use this I/O server to link LabVIEW to NI OPC Servers.
- Save the project as OPCDemoProject and the library as OPCDemoLibrary by selecting File » Save All from the project explorer window.
Creating Shared Variables that Connect to the PLCs’ OPC Tags through I/O Server
- Create new shared variables that are bound to the PLCs’ OPC tags.
- Right click on My Computer and select New » Library. This creates a new library for the shared variables, which are used to connect to the PLCs’ OPC tags.
- Right click on the newly created library and select Create Bound Variables…
- In the Create Bound Variables window, select the PLCs’ OPC tags to bind the shared variables to by browsing down to the simulated sine data from the OPC server as shown in figure 6 below.

Figure 6 Selecting the PLCs’ OPC tags to bind to shared variables
- Select all the sine items and click Add and OK. This will create shared variables that are bound to our PLCs’ OPC tags and load them into the Multiple Variable Editor.
- In the Multiple Variable Editor, select Done. This will add the new shared variables to the library that was created earlier.
Note: The LabVIEW 8.5 DSC Module enhances shared variables by adding the ability to log data, alarms and events directly to a database without ever writing a LabVIEW application.
- Save the new library as OPCItems in the project explorer window by right clicking on the library and selecting Save As.
- Deploy the shared variables by right clicking on the OPCItems library and selecting Deploy. This will publish the shared variables.
Viewing Shared Variables with Variable Manager
- From the project explorer window, select Tools » Shared Variable » Variable Manager. This will open a window that allows you to manage your shared variables in various ways (i.e. view, deploy, un-deploying, etc.).
- In the Tree view of the Variable Manager, expand the OPCItems library, select all the shared variables and drag them over to the Watched Variables: window. This will display the PLCs’ OPC tags updating with the simulated sine data as shown in figure 7.

Figure 7 Viewing the PLCs’ OPC tags through Variable Manager
Bringing the Shared Variables into LabVIEW
- From the project explorer window, right click on My Computer and select New » VI.
- From the new VI, show the block diagram by going to Window » Show Block Diagram.
- Back in the project explorer window, expand the OPCItems library and select all the shared variables (holding shift as you select variables allows you to do this).
Drag all the shared variables from the project explorer window to the VI block diagram. Notice all the shared variables populate on the block diagram. This now means you have access to all your PLCs’ OPC tags in LabVIEW. You can now use all LabVIEW has to offer with your PLCs.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
