Connect LabVIEW To Any PLC Using OPC - NI
Connect LabVIEW To Any PLC Using OPC - NI
Environment
Software
LabVIEW
LabVIEW Datalogging and Supervisory Control Module
OPC Servers
Operating System
Windows
NI LabVIEW software can communicate with any programmable logic controller (PLC) in a variety of ways. OLE for Process Control
(OPC) defines the standard for communicating real-time plant data between control devices and human machine interfaces (HMIs).
OPC Servers are available for virtually all PLCs and programmable automation controllers (PACs). In this tutorial, learn how to use
LabVIEW to communicate with a networked PLC using OPC.
The LabVIEW Datalogging and Supervisory Control (DSC) Module is used in this tutorial. This module includes tools for logging data
to a networked historical database, real-time and historical trending, managing alarms and events, networking LabVIEW Real-Time
targets and OPC devices into one complete system, and adding security to user interfaces. With these features, LabVIEW becomes
a powerful HMI/SCADA package for industrial control applications.
Create Shared Variables that Connect to the OPC Tags through the I/O Server
In this section, create shared variables, which are bound to the OPC tags, giving you native access in LabVIEW to PLC data. With the
shared variable, you can share data across LabVIEW applications on a single computer or across the network.
1. Create new shared variables that are bound to the PLCs’ OPC tags.
2. 1. In the LabVIEW Project window, right-click 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.
2. Right-click the newly created library and select Create Bound Variables…
3. In the Create Bound Variables window, select the OPC tags to bind the shared variables to by browsing down to the
simulated sine data from the OPC server as shown in Figure 5.
4. 4. Select all the sine items and click Add and OK. This creates shared variables that are bound to the PLCs’ OPC tags and loads
them into the Multiple Variable Editor.
5. In the Multiple Variable Editor, select Done. This adds the new shared variables to the library that was created earlier.
Note: The LabVIEW 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.
2. Save the new library as OPCItems.lvlib in the project explorer window by right-clicking the library and selecting Save As.
3. Deploy the shared variables by right-clicking the OPCItems library and selecting Deploy. This publishes the shared variables,
making them available on the network to other computers, OPC clients, and the LabVIEW Real-Time PAC .
You now have access to PLC data natively in LabVIEW through the shared variables.
Viewing Shared Variables with Distributed System Manager
1. From the Project Explorer window, select Tools»Distributed System Manager. This opens a window that you can use to manage
your shared variables in various ways (view, deploy, undeploy, etc.).
2. In the Tree pane of the Variable Manager, expand the localhost item under the My Systems category. Right-click
the OPCItems library, and select Watch List to display the shared variables, which are bound to the PLCs’ OPC tags.
3. The shared variables will be updating with the simulated sine data.
Note: The Distributed System Manager is new in LabVIEW 8.6. Previous versions of LabVIEW did this by going to Tools»Shared
Variable»Variable Manager and dragging the shared variables into the Watched Variables: window.
Connected Terminals
Figure 9. Connecting Block Diagram Items
Now data flows from the shared variable to the waveform chart when the VI is running.
10. Select the Automatic Tool Selection tool from the Tools palette.
The while loop causes the code within it to execute continuously until stopped by the user or additional logic in the VI.
14. As the while loop is now, it will run as fast as possible. A Wait Until Next ms Multiple VI should be added to the loop so that the
loop will execute every set amount of seconds, in this case 100ms.
17. Click Close on the Deploy… window once the deployment completes. When the application begins executing, you see the Sine1
sine wave displayed on the waveform chart.
Figure 18. Completed Front Panel – Displaying PLC Data on a Waveform Chart
Congratulations! You successfully accessed PLC data in your LabVIEW application, so you can incorporate powerful analysis and
control functions in your solution.
Related Links
How LabVIEW Uses I/O Servers
Introduction to OPC