Design method of PLC network communication control based on Winsock

Publisher:beta12Latest update time:2009-08-12 Source: EDN ChinaKeywords:Winsock  PLC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In industrial control, projects controlled by PLC generally use RS-232/RS-485 serial communication for upper/lower computer communication. This method is difficult to meet the communication needs of control systems with large data volumes, long communication distances, and high real-time requirements.

In recent years, with the rapid development of computer network technology, networked numerical control has become an inevitable trend in the development of modern manufacturing industry. Control systems are developing in the direction of virtualization, networking, integration, distribution and node intelligence. [1] Many PLCs produced by large PLC manufacturers are equipped with corresponding Ethernet communication modules. This paper discusses the Ethernet communication architecture of OMRON PLC and takes the ENT2l Ethernet module of CP1H PLC as an example to realize communication with the computer.

1. Winsock network communication control

The Winsock control is a non-visual control that allows programmers to develop client/server applications without having to understand the details of TCP or call low-level Winsock API functions. They can directly connect to a remote computer and implement two-way data exchange simply by setting the properties of the Winsock control and calling its methods.

WinSock mainly supports two types of sockets: ① Stream Socket, also known as connection-oriented mode, corresponds to the TCP protocol, and its transmission characteristics are high communication reliability, which can ensure that the transmission of data streams is reliable, orderly, and non-repetitive, and can provide bidirectional data streams. Data is regarded as byte streams with no length restrictions. ② Datagram Socket, also known as connectionless mode, corresponds to the UDP protocol. This mode does not provide correctness, orderliness, and non-repetitiveness of data transmission CONTROL, because it supports record-oriented data streams. Therefore, the transmitted data may be lost and repeated, and the receiving order is chaotic, and the message length is limited. Considering that this system has high requirements for communication reliability and correctness, the stream socket method is selected. The stream socket communication process based on the Client/Server mode is shown in Figure 1.

Figure 1 Sequence diagram of streaming socket process communication

2. Setting up the Ethernet network communication unit

When building a network, each node in the network needs to be installed with a corresponding communication unit according to the different network types, and the PLC needs to be installed with an Ethernet network communication module, such as the CJ1W-ETN21 Ethernet module from OMRON. Before application, the network must be set up, which is divided into switch settings and CPU bus unit system settings.

The switch settings mainly include the following items: determine the memory working area (CIO area, DM area) allocated to the CJ1W-ETN21 unit. The address is in the CPU bus area. The unit number range of the ETN unit is determined by the UNIT No. switch, which is 0 to F; the NODE No. rotary switch sets two groups of hexadecimal numbers as the node number of the ETN unit in the network, ranging from O1 to 7E; the IP address sets the network number and the host node number, which consists of a 32-bit binary number and is expressed in decimal in 4 segments.

The CPU bus unit settings are mainly set through programming devices such as CX-Programmer software or programmers to set the network unit mode, local IP address, subnet mask, FINS port number, FTP login name and password, and IP router table. If the FINS/TCP protocol is used, it is also necessary to modify some parameters of the FINS/TCP item in the Ethernet unit settings, such as: automatically assigned FINS node number, whether to keep activated, etc.

3. Communication protocol for host computers

As shown in Figure 2, the layered model of Ethernet is divided into the physical layer, the Internet layer, the transport layer, and the application layer. Among them: the transport layer can use the connectionless UDP or the TCP protocol that requires a connection; the application layer is the FINS (Factory InteRFace Network Service) protocol. The FINS protocol is a command response system developed by OMRON for factory automation control networks. It mainly stipulates the operation methods such as reading and writing data in the PLC storage space. The communication implementation method that uses the FINS protocol in the application layer and the TCP protocol in the transport layer is called the FINS/TCP method.

Figure 2 Network layered structure

The FINS protocol includes a command system and a response system. Its command frame consists of several parts, including a FINS header, a command code, a response code, and a body. The commands and responses sent from the host computer must comply with the format requirements of the following frames and provide appropriate FINS header information. [3-4] FINS communication services are implemented through the exchange of FINS command frames and their corresponding response frames.

The FINS command/response frame format is shown in Figure 3. The FINS/TCP header specifies five commands for communication between the client (host computer) and the server (PLC): (1) Send the client node address; (2) Send the server node address; (3) Send the Fins frame; (4) Send the Fins frame error notification; (5) Confirm the client and server are online.

Figure 3 FINS command/response frame format [page]

4. Specific implementation of communication program

After creating a new VB project, you need to execute the "Project/Component" command in the VB toolbar to add the Winsock control to the project and name it "WskClient". The program uses the TCP/IP protocol for communication, and its main properties are set as follows:

After the initialization is completed, a connection request is made to the PLC. After the PLC accepts the request and sends a response message, the client program builds the information frame to be sent according to various frame formats, and then two-way data communication can be carried out with the PLC. In this process, a retransmission mechanism can be established after a transmission failure to enhance the reliability of communication.

First, create and send a "handshake information" instruction (20 bytes) to indicate the client node number; when the computer receives the PLC return frame (24 bytes), check whether the PLC has received the command and obtain the server and client node numbers. When the computer receives the data returned by the PLC, a DataArrival event is generated, and the parameter BytesTotal contains the number of bytes of data received. In the DataArrival event, you can call the GetData method to receive data. If a Close event is received, use the Close method to close the connection. In addition, the State property of Winsock can be used to reflect the current TCP/IP connection status. Here are only the main procedures listed as follows:

After receiving the information, when the PLC receives the transmitted information, it will send back the corresponding command feedback value. The program in this event program will display it in the text box and can be further processed. The main program flow chart is shown in Figure 4.

Figure 4 Program flow chart

If the UDP protocol is used, the basic communication process is the same as TCP, except that there is no need to establish a connection. In addition, UDP applications can be either clients or servers, without having to establish client programs and server programs separately like TCP applications. Since UDP does not need to establish a connection between the client and the server before transmitting datagrams, and there is no timeout retransmission mechanism, the transmission speed is very fast. Therefore, if there are not many devices in the network and the amount of data sent is not large, the UDP protocol that consumes less computer "resources" can be selected for communication.

5. Conclusion

The host computer Ethernet communication program implemented by Winsock control has been successfully applied to the digital sample drawing machine monitoring system. This method is simple and practical. It can realize the function of real-time monitoring of network data of workshop equipment without additional investment, and achieve the ideal effect. Moreover, with VB as the development platform of monitoring software, the secondary development of software is not restricted, saving costs, and the program can be upgraded at any time as needed. In order to realize effective information management and monitoring of the control system, the PLC control system based on Ethernet will have a wider application. The discussion in this article provides a certain reference value for solving such problems.

Keywords:Winsock  PLC Reference address:Design method of PLC network communication control based on Winsock

Previous article:Design and implementation of binocular vision monitoring system based on DM642
Next article:Simulation Debugging Based on DSP TMS320F206

Recommended ReadingLatest update time:2024-11-16 19:38

Using PLC to construct flying saw automatic control system
1. Purpose of the experiment The flying saw automatic control system is constructed using PLC. 2. Experimental Equipment YX-80 series PLC training device, FX-20P handheld programmer, or personal computer (WINDOW), SC-09 programming cable, FX-PCS/WIN programming environment Self-control
[Embedded]
Using PLC to construct flying saw automatic control system
Solution to the problem that Siemens PLC cannot be programmed online with a laptop
1. Try turning the CPU to the STOP position. 2. Close all software, especially the software occupying the communication port, and only keep the 200plc programming software. 3. To communicate normally with the latest S7-200CNCPU launched by Siemens, the following conditions must be met: Use progr
[Embedded]
PLC control of robot interference area and interlock signal control
VASS standard A/E41-56 robot interlock signal, A/E81-96 is used for robot and PLC to confirm the close interlock signal. Each robot standard has 16 lock commands available, which are permanently assigned to I/O. The corresponding lock input must be queried under online driving conditions. 1. When entering the safety
[Embedded]
PLC control of robot interference area and interlock signal control
How to connect the inverter to PLC
There are three connection control methods between PLC and inverter: 1. Use the analog output module of the PLC to control the inverter. The analog output module of the PLC outputs a 0-5V voltage signal or a 4-20mA current signal as the analog input signal of the inverter to control the output frequency of the
[Embedded]
How to connect the inverter to PLC
Application of PLC in the Control System of Vacuum Heat Treatment Furnace
0 Introduction Vacuum heat treatment is a necessary intermediate process used in the manufacturing industry to make industrial products have good performance. It is a branch of heat treatment. Its main purpose is to prevent oxidation and decarburization of workpieces during processing. Since programmable controllers
[Industrial Control]
Application of PLC in the Control System of Vacuum Heat Treatment Furnace
What does the PLC sequential function diagram consist of?
The SFC is a graphical representation method that describes the process, function and characteristics of a sequential control system. It is mainly composed of steps, directed segments, transitions (including transition conditions) and actions. To draw a good SFC, it is essential to understand and master each of its
[Embedded]
What does the PLC sequential function diagram consist of?
Design of Servo Control System for Optical Fiber Connector Grinding Machine
Fiber optic connectors are the most widely used optical passive devices in optical fiber communication networks, and their core components are fiber optic pins. An important process in the manufacturing process of fiber optic connectors is to use a fiber optic connector grinder to grind the end face of the ceramic p
[Industrial Control]
Simplified design and control scheme of inverter and PLC communication
1. Introduction In industrial automation control systems, the most common application is the combination of PLC and inverter, and a variety of PLC control inverter methods have been produced. Among them, the control scheme using RS-485 communication has been widely used: because it has strong anti-interfere
[Embedded]
Simplified design and control scheme of inverter and PLC communication
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号