7
1/7 www.ni.com 1. 2. 1. 2. 1. 2. 3. Connect LabVIEW to Any PLC Using OPC Publish Date: Nov 21, 2012 | 24 Ratings | out of 5 3.92 Overview This article is part of a series outlining the capabilities of the LabVIEW Data logging and Supervisory Control (DSC) module. to view the list of other articles. Click here 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 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. Launch NI OPC Servers 2012 by selecting . With NI OPC Servers 2012, you can create, Start»All Programs»National Instruments»NI OPC Servers 2012»NI OPC Servers Configuration configure, and view tags that are associated with your PLCs. 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 and browse to File»Open… C:\Program Files\National Instruments\Shared\NI OPC . The project should look like Figure 1. Servers\V5\Projects\simdemo.opf Figure 1. NI OPC Servers 2012 Displaying Simulated PLCs View the Sine tags by expanding and selecting . The tags populate in the right-most window. These tags, which are bound to registers on the PLCs, can be Simulation Examples Functions read by LabVIEW. View the data from the PLCs’ OPC tags In NI OPC Servers 2012, launch the by selecting , which you can use to view the OPC tag data. Quick Client Tools>>Launch OPC Quick Client Under the folder and select . This selects the device to monitor. National Instruments.NIOPCServers.V5 Simulation Examples.Funtions Notice that all the Sine tags populate in the right-most window and are updating with simulated sine data as shown in Figure 2.

Tutorial servidor OPC en LabView

Embed Size (px)

DESCRIPTION

Tutorial de creación de un servidor OPC en LabView. Tomado de la página de NI.com. Se sigue paso a paso para hacer el servidor

Citation preview

Page 1: Tutorial servidor OPC en LabView

1/7 www.ni.com

1.

2.

1.

2. 1.

2.

3.

Connect LabVIEW to Any PLC Using OPCPublish Date: Nov 21, 2012 | 24 Ratings | out of 53.92

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

to view the list of other articles.Click here

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 plantdata 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 touse 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 historicaltrending, 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, LabVIEWbecomes 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 2012The steps in this section are written for NI OPC Servers 2012, but similar steps can be used for previous versions of NI OPC Servers.

Launch NI OPC Servers 2012 by selecting . With NI OPC Servers 2012, you can create,Start»All Programs»National Instruments»NI OPC Servers 2012»NI OPC Servers Configurationconfigure, and view tags that are associated with your PLCs.

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 and browse to File»Open… C:\Program Files\National Instruments\Shared\NI OPC. The project should look like Figure 1.Servers\V5\Projects\simdemo.opf

Figure 1. NI OPC Servers 2012 Displaying Simulated PLCs

View the Sine tags by expanding and selecting . The tags populate in the right-most window. These tags, which are bound to registers on the PLCs, can beSimulation Examples Functionsread by LabVIEW.

View the data from the PLCs’ OPC tagsIn NI OPC Servers 2012, launch the by selecting , which you can use to view the OPC tag data. Quick Client Tools>>Launch OPC Quick ClientUnder the folder and select . This selects the device to monitor. National Instruments.NIOPCServers.V5 Simulation Examples.FuntionsNotice that all the Sine tags populate in the right-most window and are updating with simulated sine data as shown in Figure 2.

Page 2: Tutorial servidor OPC en LabView

2/7 www.ni.com

1.

2.

3.

1.

2.

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

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

In the window of LabVIEW, click . This opens a new LabVIEW Project.Getting Started File»New ProjectIf the window is not visible, press to display the window. Keep this window open for helpful information about items under your cursor.Context Help Ctrl+HIn the LabVIEW Project window, right-click and select , as shown in Figure 3.My Computer New»I/O Server

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

Select in the Create New I/O Server Window and click OPC Client Continue. Choose from the Registered OPC servers field and set to 100. This creates a connection from LabVIEW to the OPC tags, whichNational Instruments.NIOPCServers.V5 Update rate (ms)updates every 100 ms.

Page 3: Tutorial servidor OPC en LabView

3/7 www.ni.com

1.

2.

1.

1.

2.

3.

1.

2.

1.

2.

1.

2.

3.

1.

2.

Figure 4. Configuring the OPC Client I/O Server

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

Create Shared Variables that Connect to the OPC Tags through the I/O ServerIn 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 LabVIEWapplications on a single computer or across the network.

Create new shared variables that are bound to the PLCs’ OPC tags.

In the LabVIEW Project window, right-click My Computer and select . This creates a new library for the shared variables, which are used to connect to the PLCs’ OPC tags.New»LibraryRight-click the newly created library and select Create Bound Variables…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.

Figure 5. Select OPC Tags to Bind to Shared Variables

Select all the sine items and click and This creates shared variables that are bound to the PLCs’ OPC tags and loads them into the Multiple Variable Editor.Add OK.In the Multiple Variable Editor, select . This adds the new shared variables to the library that was created earlier.Done

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.

Save the new library as in the project explorer window by right-clicking the library and selecting .OPCItems.lvlib Save AsDeploy the shared variables by right-clicking the OPCItems library and selecting . This publishes the shared variables, making them available on the network to other computers, OPCDeployclients, 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 ManagerFrom the Project Explorer window, select . This opens a window that you can use to manage your shared variables in various ways (view, deploy, undeploy,Tools»Distributed System Manageretc.).

In the Tree pane of the Variable Manager, expand the localhost item under the My Systems category. Right-click the library, and select to display the shared variables,OPCItems Watch Listwhich are bound to the PLCs’ OPC tags.

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 and dragging the shared variables intoTools»Shared Variable»Variable Managerthe window.Watched Variables:

Using OPC Tag Data in LabVIEWFrom the project explorer, right-click My Computer and select . This creates a new virtual instrument or VI. A VI is used to create a user interface and executable graphical code.New»VI

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

Page 4: Tutorial servidor OPC en LabView

4/7 www.ni.com

2.

3.

1.

2.

3.

4.

5.

6.

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 apowerful, intuitive UI. Select or right-click anywhere on the Front Panel to bring up the Controls palette. Mouse over the various categories to explore the UI componentsView»Controls Palettein LabVIEW.

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

Figure 6. Select a Waveform Chart from the Controls Palette

Figure 7. Waveform Chart Placed on the Front Panel

In the VI, select or press to show the Block Diagram. The Block Diagram is where you build the behavior of your application. Notice the icon on the BlockWindow»Show Block Diagram Ctrl+EDiagram, which represents the chart on the Front Panel. By passing data into this terminal, you can display it in the chart on the Front Panel.

In the project explorer, expand the library and select the shared variable.OPCItems Sine1Drag and drop the 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.Sine1Select or press Shift+right-click to show the Tools palette, which contains various tools for building the Block Diagram. By default you use the View»Tools Palette Automatic Tool Selectiontool, which selects the appropriate tool based on the location of the cursor.

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

Figure 8. Select the Connect Wire Tool

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

Page 5: Tutorial servidor OPC en LabView

5/7 www.ni.com

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 tool from the Tools palette.Automatic Tool Selection

Figure 10. Automatic Tool Selection from the Tools Palette

11. Open the Functions palette by selecting or right-clicking anywhere on the Block Diagram. The Functions palette contains hundreds of analysis functions, controlView»Functions Palettefunctions, and structures for graphical programming.

12. Select a while loop from the Functions palette by navigating to . Once you select the while loop, your cursor appears as shown in Figure 12. This allowsProgramming»Structures»While Loopyou 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 onthe and selecting . This places a Stop button on your Front Panel which allows the user to stop the VI.Loop Condition Create Control

Page 6: Tutorial servidor OPC en LabView

6/7 www.ni.com

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 VI should be added to the loop so that the loop will execute every set amount of seconds, in this caseWait Until Next ms Multiple 100ms.

Figure 14. Adding timing to the While Loop

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

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

Figure 17. Run Button

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

Page 7: Tutorial servidor OPC en LabView

7/7 www.ni.com

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 LinksNI Developer Zone: How LabVIEW Uses I/O Servers

NI Developer Zone: Introduction to OPC