This action might not be possible to undo. Are you sure you want to continue?
Publish Date: Nov 21, 2012 | 24 Ratings | 3.92 out of 5
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.
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. 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.
Figure 1. NI OPC Servers 2012 Displaying Simulated PLCs 1. View the Sine tags by expanding Simulation Examples and selecting Functions. The tags populate in the right-most window. These tags, which are bound to registers on the PLCs, can be read by LabVIEW. 2. View the data from the PLCs’ OPC tags 1. 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.
Creating a New I/O Server through the LabVIEW Project 1. NI OPC Quick Client Displaying Simulated Sine OPC Tags Note: For a list of supported devices/drivers for NI OPC.NIOPCServers. 2. In the Getting Started window of LabVIEW. This opens a new LabVIEW Project. you will create a LabVIEW interface to the OPC tags called an I/O Server. If the Context Help window is not visible. This creates a connection from LabVIEW to the OPC tags. click File»New Project. visit Supported Device & Driver Plug-in List for NI-OPC Server . The I/O Server automatically updates LabVIEW with the current tag values at a rate you specify.ni. Choose National Instruments. In the LabVIEW Project window. right-click My Computer and select New»I/O Server. Figure 3.Figure 2.V5 from the Registered OPC servers field and set Update rate (ms) to 100. as shown in Figure 3. 3. 2. Select OPC Client in the Create New I/O Server Window and click Continue. Connect LabVIEW to OPC Tags by Creating an I/O Server In this section. which updates every 100 ms. Keep this window open for helpful information about items under your cursor. press Ctrl+H to display the window.com . 2/7 www. 1.
which are used to connect to the PLCs’ OPC tags. From the Project Explorer window. Figure 5. In the Tree pane of the Variable Manager. select Done. and the LabVIEW Real-Time PAC. Select OPC Tags to Bind to Shared Variables 1. undeploy.). 2. This publishes the shared variables. 2. which are bound to the PLCs’ OPC tags. expand the localhost item under the My Systems category. Previous versions of LabVIEW did this by going to Tools»Shared Variable»Variable Manager and dragging the shared variables into the Watched Variables: window. By default.ni. create shared variables.com . that you can use to build a 3/7 www. you see the Front Panel. deploy. Note: The LabVIEW DSC Module enhances shared variables by adding the ability to log data. A library is automatically created in your project explorer window to manage the I/O Server. Create Shared Variables that Connect to the OPC Tags through the I/O Server In this section. Right-click the OPCItems library. A VI is used to create a user interface and executable graphical code. 1. alarms. This creates a new virtual instrument or VI. Using OPC Tag Data in LabVIEW 1. 2. Select OK.lvlib in the project explorer window by right-clicking the library and selecting Save As. 3. and so on. 2. which are bound to the OPC tags. making them available on the network to other computers. 2.6. dials. 2. Viewing Shared Variables with Distributed System Manager 1. giving you native access in LabVIEW to PLC data. you can share data across LabVIEW applications on a single computer or across the network. With the shared variable. right-click My Computer and select New»VI. 1. 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. This opens a window that you can use to manage your shared variables in various ways (view. charts. and select Watch List to display the shared variables. This creates a new library for the shared variables. and events directly to a database without ever writing a LabVIEW application. In the Multiple Variable Editor. Save the new library as OPCItems. LabVIEW has many built-in UI components. Right-click the newly created library and select Create Bound Variables… 3. You now have access to PLC data natively in LabVIEW through the shared variables. The shared variables will be updating with the simulated sine data. OPC clients. Create new shared variables that are bound to the PLCs’ OPC tags. etc. Configuring the OPC Client I/O Server 1. right-click My Computer and select New»Library. In the LabVIEW Project window. Save the project as OPCDemoProject and the library as OPCDemoLibrary by selecting File»Save All from the project explorer window.Figure 4. Note: The Distributed System Manager is new in LabVIEW 8. 1. In the Create Bound Variables window. select Tools»Distributed System Manager. which is the user interface of the VI. such as graphs. From the project explorer. Deploy the shared variables by right-clicking the OPCItems library and selecting Deploy. This adds the new shared variables to the library that was created earlier. 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.
which is the user interface of the VI. 3. expand the OPCItems library and select the Sine1 shared variable. The shared variable acts as a source of data to other terminals on the Block Diagram. The Block Diagram is where you build the behavior of your application. By default. 4/7 www. intuitive UI. Waveform Chart Placed on the Front Panel 1.com .2. Mouse over the various categories to explore the UI components in LabVIEW. In the project explorer. Select the Connect Wire Tool 6. as shown in Figure 6. which contains various tools for building the Block Diagram. LabVIEW has many built-in UI components. By default you use the Automatic Tool Selection tool. charts. such as graphs. 4. Use the Connect Wire tool to wire the Sine1 shared variable to the waveform chart by clicking on the Sine1 shared variable and then on the waveform chart. Select View»Controls Palette or right-click anywhere on the Front Panel to bring up the Controls palette. and place it on the Front Panel. Select a waveform chart from the Controls palette by selecting Express»Graph Indicators»Chart. 2. Select a Waveform Chart from the Controls Palette Figure 7.ni. This tool is used to wire terminals together on the Block Diagram. that you can use to build a powerful. 3. you see the Front Panel. Drag and drop the Sine1 shared variable from the project explorer to the Block Diagram of the VI. Notice the icon on the Block Diagram. By passing data into this terminal. which selects the appropriate tool based on the location of the cursor. select Window»Show Block Diagram or press Ctrl+E to show the Block Diagram. In the VI. dials. 5. Figure 6. and so on. which represents the chart on the Front Panel. Figure 8. you can display it in the chart on the Front Panel. Select View»Tools Palette or press Shift+right-click to show the Tools palette. as shown in Figure 9. Select the Connect Wire tool as shown in Figure 8.
This allows you to wrap a while loop around a section of code. Select the Automatic Tool Selection tool from the Tools palette. control functions. Select a while loop from the Functions palette by navigating to Programming»Structures»While Loop.ni. Figure 10. Selecting a While Loop Figure 12.com . place a while loop around the shared variable and waveform chart by clicking and dragging the cursor. This places a Stop button on your Front Panel which allows the user to stop the VI. Now create a Stop control in while loop by right-clicking on the Loop Condition and selecting Create Control. Using the while loop cursor. 5/7 www. 12. 10. and structures for graphical programming. your cursor appears as shown in Figure 12. Figure 11.Wiring the Terminals Together Connected Terminals Figure 9. Automatic Tool Selection from the Tools Palette 11. Connecting Block Diagram Items Now data flows from the shared variable to the waveform chart when the VI is running. While Loop Cursor 13. Once you select the while loop. Open the Functions palette by selecting View»Functions Palette or right-clicking anywhere on the Block Diagram. The Functions palette contains hundreds of analysis functions.
Click the Run button on the toolbar to execute the VI. 6/7 www. Figure 17.ni. As the while loop is now. you see the Sine1 sine wave displayed on the waveform chart. Click Close on the Deploy… window once the deployment completes. Adding timing to the While Loop 15. 16. 14. it will run as fast as possible. When the application begins executing.com . Figure 14.Figure 13. in this case 100ms. Run Button 17. Return to the Front Panel by selecting Window»Show Front Panel or pressing Ctrl+E. 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. A Wait Until Next ms Multiple VI should be added to the loop so that the loop will execute every set amount of seconds.
com .Figure 18. Related Links NI Developer Zone: How LabVIEW Uses I/O Servers NI Developer Zone: Introduction to OPC 7/7 www. so you can incorporate powerful analysis and control functions in your solution.ni. Completed Front Panel – Displaying PLC Data on a Waveform Chart 18. Congratulations! You successfully accessed PLC data in your LabVIEW application.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.