connect labview to any plc using opc - developer zone - national instruments.pdf

11
02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments www.ni.com/white-paper/7450/en 1/11 Improve your ni.com experience. Login or Create a user profile. Overview This article is part of a series outlining the capabilities of the LabVIEW Data logging and Supervisory Control (DSC) module. Click here to view the list of other articles. 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. Requirements • Windows 7/Vista/XP • NI LabVIEW Full Development System and LabVIEW DSC • NI OPC Servers View Existing PLC Tags with NI OPC Servers 2012 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 Start»All Programs»National Instruments»NI OPC Servers 2012»NI 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 File»Open… and browse to C:\Program Files\National Instruments\Shared\NI OPC Servers\V5\Projects\simdemo.opf . The project should look like Figure 1. Connect LabVIEW to Any PLC Using OPC Tipo de Documento: Tutorial Soportado por NI: Sí Fecha de Publicación: nov 21, 2012

Upload: angel-giovanny-toapanta

Post on 03-Jan-2016

216 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 1/11

Improve your ni.com experience. Login or Create a user profile.

Overview

This article is part of a series outlining the capabilities of the LabVIEW Data logging and Supervisory Control(DSC) module.

Click here to view the list of other articles.

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). OPCServers are available for virtually all PLCs and programmable automation controllers (PACs). In this tutorial, learn how to use LabVIEW tocommunicate 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 toa networked historical database, real-time and historical trending, managing alarms and events, networking LabVIEW Real-Timetargets and OPC devices into one complete system, and adding security to user interfaces. With these features, LabVIEW becomes apowerful HMI/SCADA package for industrial control applications.

Requirements

• Windows 7/Vista/XP

• NI LabVIEW Full Development System and LabVIEW DSC

• NI OPC Servers

View Existing PLC Tags with NI OPC Servers 2012

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 Start»All Programs»National Instruments»NI OPC Servers 2012»NI OPC ServersConfiguration. 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 alreadybeen created and configured in NI OPC Servers 2012.

Note: If this simulation project is not already loaded in NI OPC Servers 2012, select File»Open… and browse to C:\ProgramFiles\National Instruments\Shared\NI OPC Servers\V5\Projects\simdemo.opf. The project should look like Figure 1.

Connect LabVIEW to Any PLC Using OPC

Tipo de Documento: TutorialSoportado por NI: Sí Fecha de Publicación: nov 21, 2012

Page 2: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 2/11

Figure 1. NI OPC Servers 2012 Displaying Simulated PLCs

3. View the Sine tags by expanding Simulation Examples and selecting Functions. The tags populate in the right-mostwindow. These tags, which are bound to registers on the PLCs, can be read by LabVIEW.

4. View the data from the PLCs’ OPC tags1. In NI OPC Servers 2012, launch the Quick Client by selecting Tools>>Launch OPC Quick Client, which you can use to view

the OPC tag data.2. Under the National Instruments.NIOPCServers.V5 folder and select Simulation Examples.Funtions. This selects the

device to monitor.3. Notice that all the Sine tags populate in the right-most window and are updating with simulated sine data as shown in

Figure 2.

Figure 2. NI OPC Quick Client Displaying Simulated Sine OPC Tags

Page 3: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 3/11

Note: For a list of supported devices/drivers for NI OPC, visit Supported Device & Driver Plug-in List for NI-OPC Server.

Connect LabVIEW to OPC Tags by Creating an I/O Server

In this section, you will create a LabVIEW interface to the OPC tags called an I/O Server. The I/O Server automatically updates LabVIEWwith the current tag values at a rate you specify.

1. In the Getting Started window of LabVIEW, click File»New 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 New»I/O Server, as shown in Figure 3.

Figure 3. Creating a New I/O Server through the LabVIEW Project

4. Select OPC Client in the Create New I/O Server Window and click Continue. 5. Choose National Instruments.NIOPCServers.V5 from the Registered OPC servers field and set Update rate (ms) to 100. This

creates a connection from LabVIEW to the OPC tags, which updates every 100 ms.

Page 4: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 4/11

Figure 4. Configuring the OPC Client I/O Server

6. Select OK. A library is automatically created in your project explorer window to manage the I/O Server. 7. Save the project as OPCDemoProject and the library as OPCDemoLibrary by selecting File»Save All from the project explorer

window.

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 theshared 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 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.

Page 5: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 5/11

Figure 5. Select OPC Tags to Bind to Shared Variab les

4. Select all the sine items and click Add and OK. This creates shared variables that are bound to the PLCs’ OPC tags andloads 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 databasewithout 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 manageyour 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 OPCItemslibrary, 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»SharedVariable»Variable 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 New»VI. This creates a new virtual instrument or VI. A VI is used tocreate 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 asgraphs, charts, dials, and so on, that you can use to build a powerful, intuitive UI. Select View»Controls Palette or right-clickanywhere on the Front Panel to bring up the Controls palette. Mouse over the various categories to explore the UI components inLabVIEW.

3. Select a waveform chart from the Controls palette by selecting Express»Graph Indicators»Chart, and place it on the Front Panel,as shown in Figure 6.

Page 6: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 6/11

Figure 6. Select a Waveform Chart from the Controls Palette

Figure 7. Waveform Chart Placed on the Front Panel

4. In the VI, select Window»Show Block Diagram or press Ctrl+E to show the Block Diagram. The Block Diagram is where you buildthe behavior of your application. Notice the icon on the Block Diagram, which represents the chart on the Front Panel. By passing

Page 7: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 7/11

data into this terminal, you can display it in the chart on the Front Panel.5. In the project explorer, expand the OPCItems library and select the Sine1 shared variable.6. Drag and drop the Sine1 shared variable from the project explorer to the Block Diagram of the VI. The shared variable acts as a

source of data to other terminals on the Block Diagram.7. Select View»Tools Palette or press Shift+right-click to show the Tools palette, which contains various tools for building the Block

Diagram. By default you use the Automatic Tool Selection tool, which selects the appropriate tool based on the location of thecursor.

8. Select the Connect Wire tool as shown in Figure 8. This tool is used to wire terminals together on the Block Diagram.

Figure 8. Select the Connect Wire Tool

9. Use the Connect Wire tool to wire the Sine1 shared variable to the waveform chart by clicking on the Sine1 shared variable andthen on the waveform chart, as shown in Figure 9.

Wiring the Terminals Together

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.

Figure 10. Automatic Tool Selection from the Tools Palette

11. Open the Functions palette by selecting View»Functions Palette or right-clicking anywhere on the Block Diagram. The Functions

Page 8: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 8/11

palette contains hundreds of analysis functions, control functions, and structures for graphical programming.

12. Select a while loop from the Functions palette by navigating to Programming»Structures»While Loop. Once you select the whileloop, your cursor appears as shown in Figure 12. This allows you to wrap a while loop around a section of code.

Figure 11. Selecting a While Loop

Figure 12. While Loop Cursor

13. Using the while loop cursor, place a while loop around the shared variable and waveform chart by clicking and dragging the cursor. Now create a Stop control in while loop by right-clicking on the Loop Condition and selecting Create Control. This places a Stop buttonon your Front Panel which allows the user to stop the VI.

Page 9: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 9/11

[+] Enlarge Image

Figure 13. Placing a While Loop around the Shared Variab le 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 theloop will execute every set amount of seconds, in this case 100ms.

Page 10: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 10/11

Figure 14. Adding timing to the While Loop

15. Return to the Front Panel by selecting Window»Show Front Panel or pressing Ctrl+E.

16. Click the Run button on the toolbar to execute the VI.

Figure 17. Run Button

17. Click Close on the Deploy… window once the deployment completes. When the application begins executing, you see the Sine1sine wave displayed on the waveform chart.

Page 11: Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments.pdf

02/04/13 Connect LabVIEW to Any PLC Using OPC - Developer Zone - National Instruments

www.ni.com/white-paper/7450/en 11/11

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 andcontrol functions in your solution.

Related Links

NI Developer Zone: How LabVIEW Uses I/O Servers

NI Developer Zone: Introduction to OPC

Legal Este tutorial (este "tutorial") fue desarrollado por National Instruments (“NI”). Aunque el soporte técnico para este tutorial seaproporcionado por National instruments, el contenido de este tutorial puede no estar completamente verificado y probado y NI nogarantiza su calidad, ni que NI continuará proporcionando soporte a este contenido en cada nueva revisión de productos ycontroladores relacionados. ESTE TUTORIAL ES PROPORCIONADO "COMO ES" SIN GARANTÍA DE NINGUN TIPO Y SUJETO ACIERTAS RESTRICCIONES QUE SE EXPONEN EN LOS TÉRMINOS DE USO EN NI.COM(http://ni.com/legal/termsofuse/unitedstates/us/).