Share this

Communication between host computer and PLC based on OPC technology

2026-04-06 05:42:58 · · #1
1. Introduction Modern industrial control systems typically use a PC as the host computer, achieving automatic control of the production process through data exchange and processing with field control equipment such as PLCs. For small control systems, using dedicated configuration software is too costly. Designing a monitoring system using VB can reduce costs, but the communication problem between the host computer and the PLC must first be solved. Previously, DDE (Dynamic Data Exchange) was the most commonly used inter-process communication method. With the development and popularization of OPC technology, it has become the communication standard for industrial process control. OPC servers have two types of interfaces, with the automation interface mainly used for development tools such as VB and Delphi. This paper utilizes the OPC interface provided by Rockwell Automation to write a client application in VB, realizing data exchange between the host computer and the AB programmable controller. 2. Introduction to OPC Technology OPC (Ole for Process Control) is a component object model interface standard based on Microsoft Object Connection and Embedding (OLE), Component Object Model (COM), and Distributed Component Object Model (DCOM) technologies, operating on the Windows platform. It provides efficient information integration and interaction functions between industrial applications. OPC essentially provides a mechanism that allows a system to retrieve data from a server and deliver it to any client application in a server/client standard manner. Thus, as long as the manufacturer develops a server that conforms to the OPC specification to communicate with the data, any other client application can access the device through the server. OPC servers have two types of interfaces: custom interfaces and automation interfaces. Custom interfaces serve C++ programs, while automation interfaces serve VB and similar programs that can use automation objects. Custom interfaces are mandatory for service providers, while automation interfaces are optional; however, the OPC Foundation provides a dynamic link library called "Automation Wrapper" for switching between the two. The OPC data access specification defines three basic object types: server, group, and item. A server object contains all the information about the server and is also a container for group objects. One server corresponds to one OPC server, which is a device driver. Group objects, in addition to containing their own information, are responsible for managing data items. Each data item represents a connection to a data source, but it does not provide an external interface; client programs cannot directly manipulate data items. Applications must rely on the group object, the container for the data item, to operate on it. 3. Communication Implementation 3.1 RS-Linx Configuration RS-Linx is a tool used by AB programmable controllers to establish factory communication solutions under the Windows environment. It not only provides various network drivers but also offers the fastest OPC, DDE, and custom C/C++ interfaces. In this design, the host computer and the Logix5550 controller are connected via RS-232 serial port. In RS-Linx, the DF1 network driver needs to be configured, setting the serial port characteristics as follows: COM1, baud rate 19200bps, one stop bit, no parity, full-duplex, and BCC checksum. Furthermore, to use the RS-Linx OPC interface as a server, OPC also needs to be configured within RS-Linx. 3.2 Installing the OPC Automation Interface Service To develop OPC applications using VB, the OPC Automation Interface Service must be installed, ensuring that opcdaauto.dll is present in the computer's system directory. The OPC Foundation provides a dynamic link library called "Automation Wrapper," which can be downloaded from the OPC Foundation website (www.opcfoundation.org). In the VB environment, after clicking the "References..." submenu under "Project", a dialog box will pop up. Select the "RSLINX OPC Automation 2.0" item to use the automation interface. 3.3 Program Design An OPC client application was written in VB to realize communication between the host computer and the Logix5550 controller. The main program code is as follows: (1) Connect to the OPC server dim withevents myopcserver as opcserver ' Define the server object variable myopcserver dim withevents myopcgroup as opcgroup ' Define the OPC group object variable myopcgroup set myopcserver = new opcserver myopcserver.connect "rslinx opc server" ' Connect to the rslinx OPC server (2) Add an OPC group object set myopcgroup=myopcserver.opcgroups.add("group1") ' Add an OPC group object myopcgroup.issubscribed= true ' Set the group data to be refreshed in the background myopcgroup.isactive = true ' Set the group to be active myopcgroup.updaterate=1000 ' Set the data refresh time to 1000 (3) Add data items dim abitemids() as string ' Item identifier dim abclienthandles() as long ' Client handle dim abserverhandles() as long 'Server-side handle dim aberrors() as long dim i as long itemcount=5 dim oopcitem as rslinxopcautomation.opcitem for i = 1 to 5 abitemids(i) = "[" & txttopic & "]" & txtitem(i) 'Assign topic name and tag name to item identifier abclienthandles(i) = i 'Assign value to client handle next i myopcgroup.opcitems.additems itemcount, abitemids, abclienthandles, abserverhandles, aberrors 'Add data item operation (4) Synchronous data reading and writing OPC data access has two modes: synchronous and asynchronous. Asynchronous data reading and writing is complex and needs to be used in conjunction with events. Compared with synchronous, it is slower but more accurate. Synchronous data reading and writing is simple and can be done directly using the methods of opcitem. `dim one as opcitem` `dim index as long` 'index is the tag sequence number` `dim oneread as string` `dim xie as string` `set one = myopcgroup.opcitems(index)` `one.read opccache` `oneread = one.value` 'Read data` `one.write(xie)` 'Write data` If you only want to read data, you can use the `datachange` event. This event will be triggered when the data to be accessed in the controller changes, and the data will be automatically read into the `txtvalue` text box. private sub myopcgroup_datachange(byval transactionid as long, byval numitems as long, clienthandles() as long, itemvalues() as variant, qualities() as long, timestamps() as date) 'Automatically refresh data dim i as long for i = 1 to numitems txtvalue(clienthandles(i)) = itemvalues(i) 'Get item value txttime(clienthandles(i)) = timestamps(i) 'Get item timestamp txtquantity(clienthandles(i)) = getqualitystring(qualities(i)) 'Get item quality next i end sub (5) Disconnect the OPC server myopcserver.opcgroups.removeall 'Remove all OPC groups and free up resources set myopcgroup = nothing myopcserver.disconnect 'Disconnect 4 Conclusion Using the method introduced in this article, communication between the host computer and the PLC was implemented in the laboratory. Figure 1 shows the OPC client settings interface. In addition, we have designed an urban water supply monitoring system. Due to space limitations, the monitoring interfaces will not be listed one by one.
Read next

CATDOLL Kelsie Hard Silicone Head

The head made from hard silicone does not have a usable oral cavity. You can choose the skin tone, eye color, and wig, ...

Articles 2026-02-22