NI LabVIEW software can communicate with programmable logic controllers (PLCs) in a variety of ways. OLE for Process Control (OPC) defines a standard for real-time object data communication between control devices and human-machine interfaces (HMIs). OPC servers are available for nearly all PLCs and programmable automation controllers (PACs). In this tutorial, you will learn how to use OPC in LabVIEW to communicate with a networked PLC.
Table of contents
This tutorial uses the LabVIEW Datalogging and Supervisory Control (DSC) Module. This module includes many tools, including data logging to a networked historian, real-time and historical trending, alarm and event management, connecting LabVIEW Real-Time targets and OPC devices in a complete system, and adding security to the user interface. With these features, LabVIEW becomes a powerful HMI/SCADA tool for industrial control applications.
Require
• Windows XP/2000
• LabVIEW FDS and LabVIEW DSC
• NI OPC Server
Viewing Existing PLC Tags Using NI OPC Servers
1. Select Start>Programs>National Instruments>NI OPC Servers>NI OPC Servers to start the NI OPC Server. Using the NI OPC Server, you can create, configure, and view tags associated with the PLC.
2. The NI OPC Server needs to be started with a PLC simulation project already loaded. This project simulates the PLC that has been set up and configured in the NI OPC Server.
Note: If the simulation project is not loaded, select File>Open in the NI OPC Server and browse to C:Program FilesNational InstrumentsSharedNI OPC ServersProjectssimdemo.opf. The project is shown in Figure 1.
Figure 1: NI OPC Server showing a simulated PLC
Expand Channel_0_User_Defined, select Sine, and view the Sine tags. The tags are displayed in the rightmost window. These tags are bound to registers in the PLC and are read by LabVIEW.
View data via PLC OPC tags.
1. In the NI OPC Server, select Tools»Launch OPC Quick Client. This launches the OPC Quick Client, which you can use to view OPC tag data.
2. Expand the National Instruments.NIOPCServers folder and select Channel_0_User_Defined.Sine. This will select the device you want to monitor.
3. Note that all the sine labels are listed in the right window and are updating to display the simulated sine data as shown in Figure 2.
Figure 2: NI OPC Express Client showing the Simulated Sine OPC tag
Note: For a list of devices/drivers supported by NI OPC, visit ni.com/opc.
Connecting LabVIEW to OPC Tags by Creating an I/O Server
In this section, you will create a LabVIEW interface to an OPC tag, called an I/O server. An I/O server updates LabVIEW with the current tag value at a rate that you specify.
1. In the Getting Started window of LabVIEW, click File>New Project. This will open the New LabVIEW Project.
2. If the Context Help window is not visible, press Ctrl+H to display it. Keep the window open to get help information for the object that the mouse pointer is pointing to.
3. In the LabVIEW Project Explorer window, right-click My Computer and select New>I/O Server, as shown in Figure 3.
Figure 3: Creating a new I/O server in a LabVIEW project
4. In the New I/O Server window, select OPC Client and click Continue.
5. In the Registered OPC Servers box, select National Instruments.NIOPCServers and set the Update Rate (ms) to 100. This will create a connection between LabVIEW and the OPC tag, which will update every 100 ms.
Figure 4: OPC client i/o server configuration
6. Select OK. A library is automatically created in your Project Explorer window to manage the I/O Servers.
7. From the Project Explorer window, select File>Save All and save the project as OPCDemoProject and the library as OPCDemoLibrary.
Create a shared variable that connects to an OPC tag through an I/O server
In this section, you will create shared variables that bind to OPC tags so that you can access PLC data locally in LabVIEW. Using shared variables, you can share data between multiple LabVIEW applications on a single computer or across a network.
Create a new shared variable bound to the PLC OPC tag.
In the LabVIEW Project window, right-click My Computer and select New>Library. This will create a new library for the shared variables that will be connected to the OPC tags of the PLC.
Right-click on the newly created library and select Create Binding Variable...
In the Create Bound Variable window, select OPC Tag, and select the OPC tag to which the shared variable needs to be bound by browsing the simulated sine data from the OPC server, as shown in Figure 5.
Figure 5: Select the OPC tag to bind to the shared variable
4. Select all the sine items and click Add OK. This will create shared variables bound to the PLC OPC tags and load them into the Multi-Variable Editor.
5. In the Multi-Variable Editor, select Finish. This will add the new shared variable to the library created previously.
Description: The LabVIEW DSC Module enhances shared variables by adding the ability to log data, alarms, and events directly to a database without writing a LabVIEW application.
Save the new library in the Project Explorer window with the file name OPCItem.lvlib by right-clicking the library and selecting Save As.
Deploy the shared variables by right-clicking the OPCItems library and selecting Deploy. This publishes the shared variables and makes them available on the network to other computers, OPC clients, and LabVIEW Real-Time Automation Controllers (PACs).
You can now access PLC data locally in LabVIEW through shared variables.
Viewing Shared Variables Using the Distributed System Manager
In the Project Explorer window, select Tools»Distributed Systems Manager. This opens a window that you can use to manage shared variables in a variety of ways (view, deploy, remove, and so on).
In the tree pane of the Variable Manager, expand the localhost item under the My System category. Right-click the OPCItems library and select Watch List to display the shared variables bound to the PLC OPC tags.
The shared variable will be updated simultaneously with the simulated sine data.
Note: The Distributed System Manager is a new feature in LabVIEW 8.6. In previous versions of LabVIEW, you could drag a shared variable into the Watch Variables window in Tools>Shared Variable>Variable Manager.
Using OPC Tag Data in LabVIEW
In the Project Explorer, right-click My Computer and select New>VI. This will create a new virtual instrument or VI. VIs are used to create user interfaces and executable graphical code.
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 powerful, intuitive UIs. Select View>Controls Palette or right-click on the front panel to open the Controls Palette. Use the mouse to view the different categories of UI components provided in LabVIEW.
Select Express>Graph>Waveform Chart, select the waveform chart from the Controls palette, and place it on the front panel, as shown in Figure 6.
Figure 6: Select the Waveform Chart from the Controls palette
Figure 7: Waveform chart placed on the front panel
In a VI, select Window>Show Block Diagram or press Ctrl+E to display the block diagram. The block diagram is used to define the behavior of the program. Notice the icons on the block diagram, which represent the chart on the front panel. You can display data on the front panel chart by sending data to this terminal.
In the Project Explorer, expand the OPCItems library and select the Sine1 shared variable.
Drag the Sine1 shared variable from the Project Explorer to the block diagram of the VI. The shared variable serves as a data source for other terminals in the block diagram.
Select View>Tool Palettes or press Shift+right click to display the Tool Palette, which contains a variety of tools for building block diagrams. By default, you can use the automatic tool selection tool, which selects the appropriate tool based on the current cursor position.
Select the Wiring tool as shown in Figure 8. This tool is used to connect terminals on the block diagram with wires.
Figure 8: Select the Wiring Tool
Use the Wiring tool to wire the Sine1 shared variable to the waveform chart by clicking the Sine1 shared variable and then clicking the waveform chart, as shown in Figure 9.
Figure 9: Connecting the Block Diagram Project
Now while the VI is running, data will flow from the shared variable into the waveform chart.
10. From the Tools palette, select the Automatic Tool Selection tool.
Figure 10: Automatic tool selection in the tool palette
11. Open the Function Palette by selecting View>Function Palette or right-clicking anywhere on the block diagram. The Function Palette contains hundreds of analysis functions, control functions, and structures for graphical programming.
12. Select the while loop from the Function palette by navigating to Express>Execution Process Control>While Loop. After you select the while loop, the cursor will appear as shown in Figure 12. This allows you to surround a block of code with a while loop.
Figure 11: Selecting the While Loop
Figure 12: While loop cursor
13. Using the while loop cursor, click and drag the cursor to place the while loop over the area that contains the shared variable and the waveform chart.
Figure 13: Placing a While Loop around the Shared Variable and Waveform Chart
A While Loop allows the code within it to execute continuously until stopped by the user or other logic in the VI.
14. A Timed Loop is an advanced while loop that includes additional configuration options for timing and execution control. Convert a while loop to a Timed Loop by right-clicking the while loop and selecting Replace with Timed Loop.
Figure 14: Converting a while loop to a timed loop
15. To configure the Timed Loop, double-click the Input node of the Timed Loop, as shown in Figure 15.
Previous article:Design of remote electrical parameter measurement system based on STM32 and Ethernet
Next article:Design of a Wireless Automatic Measurement and Control System Based on LabVIEW
- Popular Resources
- Popular amplifiers
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- In what situations are non-contact temperature sensors widely used?
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Today at 10:00 AM R&S Live Broadcast with Prizes [USB 3.2 Compliance Test]
- Let's talk about five cents: Today's manager is standing at work
- 【DFRobot wireless communication module】Hardware analysis
- Teach you how to design an accurate and thermally efficient wearable body temperature detection system?
- EtherCAT Interface Reference Design for High-Performance MCUs
- Popular Science: Why is the PPS charger not compatible with laptop batteries?
- US NB frequency band
- TI Wireless White Paper - Semiconductor Technology Evolving for Modern Telemedicine Applications
- Why GaN is the focus of future industries
- I would like to ask how these magical formulas are derived.