Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 of 7
http://www.ni.com/tutorial/7450/en/
Overview
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.
Table of Contents
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.
Requirements
Windows 7/Vista/XP
NI OPC Servers
The steps in this section are written for NI OPC Servers 2012, but similar steps can be used for previous versions of NI OPC
Servers.
1. Launch NI OPC Servers 2012 by selecting StartAll ProgramsNational InstrumentsNI OPC Servers 2012NI OPC
Servers Configuration. With NI OPC Servers 2012, you can create, configure, and view tags that are associated with your
PLCs.
2. NI OPC Servers 2012 should launch with a PLC simulation project already loaded. This project simulates PLCs that have
already been created and configured in NI OPC Servers 2012.
Note: If this simulation project is not already loaded in NI OPC Servers 2012, select FileOpen and browse to C:\Program
Files\National Instruments\Shared\NI OPC Servers\V5\Projects\simdemo.opf. The project should look like Figure 1.
29/Oct/2016 10:58 AM
2 of 7
http://www.ni.com/tutorial/7450/en/
In this section, you will create a LabVIEW interface to the OPC tags called an I/O Server. The I/O Server automatically updates
LabVIEW with the current tag values at a rate you specify.
1. In the Getting Started window of LabVIEW, click FileNew Project. This opens a new LabVIEW Project.
2. If the Context Help window is not visible, press Ctrl+H to display the window. Keep this window open for helpful
information about items under your cursor.
3. In the LabVIEW Project window, right-click My Computer and select NewI/O Server, as shown in Figure 3.
29/Oct/2016 10:58 AM
3 of 7
http://www.ni.com/tutorial/7450/en/
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.
1. In the LabVIEW Project window, right-click My Computer and select NewLibrary. 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.
1. From the Project Explorer window, select ToolsDistributed 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.
29/Oct/2016 10:58 AM
4 of 7
http://www.ni.com/tutorial/7450/en/
Note: The Distributed System Manager is new in LabVIEW 8.6. Previous versions of LabVIEW did this by going to
ToolsShared VariableVariable Manager and dragging the shared variables into the Watched Variables: window.
Using OPC Tag Data in LabVIEW
1. From the project explorer, right-click My Computer and select NewVI. This creates a new virtual instrument or VI. A VI is
used to create a user interface and executable graphical code.
2. By default, you see the Front Panel, which is the user interface of the VI. LabVIEW has many built-in UI components, such
as graphs, charts, dials, and so on, that you can use to build a powerful, intuitive UI. Select ViewControls Palette or
right-click anywhere on the Front Panel to bring up the Controls palette. Mouse over the various categories to explore the
UI components in LabVIEW.
3. Select a waveform chart from the Controls palette by selecting ExpressGraph IndicatorsChart, and place it on the
Front Panel, as shown in Figure 6.
29/Oct/2016 10:58 AM
5 of 7
http://www.ni.com/tutorial/7450/en/
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.
29/Oct/2016 10:58 AM
6 of 7
http://www.ni.com/tutorial/7450/en/
Figure 13. Placing a While Loop around the Shared Variable and Waveform Chart
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.
29/Oct/2016 10:58 AM
7 of 7
http://www.ni.com/tutorial/7450/en/
Figure 18. Completed Front Panel Displaying PLC Data on a Waveform Chart
18. Congratulations! You successfully accessed PLC data in your LabVIEW application, so you can incorporate powerful
analysis and control functions in your solution.
Related Links
Customer Reviews
2 Reviews | Submit your review (http://zone.ni.com/apps/utf8/nidz_display_comments.create_comment?p_title=Conne
ct+LabVIEW+to+Any+PLC+Using+OPC&p_doc_id=DZTUT-7450-EN&p_doc_type=DZTUT&p_url=http://www.ni.com/t
utorial/7450/en&p_doc_url_id=7450)
29/Oct/2016 10:58 AM