1 Introduction
In modern industry, the application of communication networking between PLCs or between PLCs and computers is becoming increasingly widespread. PLC networking capabilities are becoming increasingly powerful. Taking Omron's CP1, CJ1, and CS1 series PLCs as examples, with the use of various modules, they can support industrial Ethernet, ControllerLink, and other fieldbus communication networking functions. However, the communication networking of widely used small and medium-sized PLCs such as the CPM1A and CPM2A generally can only adopt the physical layer form of industrial buses (such as RS232 or RS485), and the communication stability and anti-interference capability are not very strong.
2. Introduction to CAN Bus
The CAN bus was first proposed by the German company BOSCH and is now the most widely used bus in industry.
The CAN controller operates in a multi-master mode, where each node in the network can compete to send data to the bus using a lossless, bit-by-bit arbitration method based on bus access priority. The CAN protocol eliminates traditional station address encoding, theoretically allowing an unlimited number of nodes in the network, resulting in strong real-time communication and improved system reliability and flexibility.
The message uses a short frame format, resulting in short transmission time, low probability of interference, and an extremely low data error rate. Each CAN frame includes CRC checksum and other error detection measures, providing excellent error detection performance. CAN communication can use twisted-pair cable, coaxial cable, or fiber optic cable, offering flexible selection. CAN nodes automatically shut down their outputs in the event of an erroneous frame, while the operation of other nodes on the bus remains unaffected. The CAN bus is connected to the physical bus via two output terminals, CANH and CANL, preventing damage to any nodes. In the event of a severe error, CAN nodes automatically shut down their outputs to ensure the operation of other nodes on the bus is unaffected, preventing a "deadlock" state.
3 Communication Structure
The communication system is shown in Figure 1. The host computer runs monitoring software and OMRON's dedicated PLC programming and configuration software, and connects the computer's serial port to the RS232-CAN adapter, configuring it as a CAN bus. The lower-level PLCs consist of multiple OMRON CPM2A model PLCs, with their serial ports connected to the RS232-CAN adapter to achieve CAN bus communication.
Figure 1 Communication System Structure
Through the adapter, the computer and PLC become nodes on the CAN bus.
The nodes are connected via a bus-like structure using twisted-pair shielded cable, with 120Ω matching resistors required at both ends. The host computer can monitor the PLC system's operation in real time via the CAN bus.
This solution organically combines fieldbus technology with centralized control technology. The networked PLC network can form a DCS system. Users can remotely monitor and configure the program or status of any PLC on a computer. It achieves good system performance with relatively low hardware costs. This solution fully leverages the communication characteristics of the CAN bus : real-time, reliable, high-speed, long-distance, and easy to maintain.
After using the RS232-CAN adapter, the communication distance is extended to 5 kilometers (at 9600bps), and the number of PLCs that can be networked can be increased to 110 (in reality, due to the limitations of the PLC's internal system software, it can only support a maximum of 32 PLCs to be networked).
The RS232-CAN adapter uses opto-isolation, which greatly improves the system's anti-interference capability and safety performance.
In addition, using the RS232-CAN adapter does not require changing the original PLC communication protocol and host computer monitoring software of the PLC system. Developers do not need to modify the currently used serial communication program, thus saving costs to the maximum extent.
4HOST-LINK communication protocol
An RS232-CAN adapter is used, and the serial ports of both the computer and the PLC are configured as CAN buses. The communication method and the programming method of the host computer monitoring software are exactly the same as those for serial communication. The communication protocol generally adopts OMRON's HOST-LINK communication protocol.
OMRON's HOST-LINK communication system is a network consisting of multiple PLCs connected by a host computer (IBM PC or compatible machine) via HOST-LINK units or serial communication interfaces installed on each PLC. The host computer centrally manages and monitors the PLCs in the system. Through communication with the HOST-LINK units, it can edit or modify the programs of each PLC, monitor their operation in real time, and achieve distributed control of the automation system. For small PLCs (such as the CPM2A), linking can be achieved through their RS232 communication ports.
The system uses the HOST-LINK communication protocol for communication. The host computer has transmission priority and always issues the command and starts communication first. The HOST-LINK unit receives the command and hands it over to the PLC for execution, and then returns the execution result to the host computer. The two exchange data in turn, using communication frames as the unit.
During communication, a group of transmitted data is called a "block," which is the unit of command or response. The data block sent from the host computer to the HOST-LINK unit is called a command block, and conversely, the data block sent from the HOST-LINK unit to the host computer is called a response block. In multi-point communication, the maximum data block that can be sent as a single frame is 131 characters. Therefore, when a data block contains 132 or more characters, it must be divided into two or more frames for transmission.
Each data block begins with a device number and a header, and ends with a checksum (FCS) and a terminator. The response block also includes a response code indicating the execution result. The communication format is shown in Figure 2.
Figure 2 HOST-LINK communication frame format
5. Communication Implementation
Users can use general configuration software (such as KingSCADA) to achieve communication between the computer and the PLC, or they can write computer programs.
To write a computer communication program, you can use high-level languages such as VB and VC for programming. There are many ways to program [4]. Using the MSComm control to transmit and receive data through the serial port to realize data communication between the computer and the PLC is relatively simple.
The MSComm control provides an efficient method for handling serial communication : event-driven processing. This method utilizes the OnComm event to capture and handle communication and its errors. When the CommEvent property changes, an event is generated and the system waits for appropriate processing. Each MSComm control corresponds to a serial port.
Visual Basic 6.0 (hereinafter referred to as VB) is a powerful and easy-to-learn programming language. The ActiveX control MSComm makes it very convenient to develop computer communication programs that use the computer's serial port. This article demonstrates how to use the MSComm control in VB to implement serial communication between a host computer and a PLC.
The VB program consists of several main parts, including serial port initialization, data transmission, and data reception. The main program segments are shown below.
Serial port initialization is performed during Rem program loading.
The above outlines the main program segments for communication between the computer and the PLC. It's important to note that if the transmitted data exceeds 132 characters, it can be divided into a start frame, several intermediate frames, and an end frame for transmission. The start frame must contain the device number, command code, etc.; otherwise, errors will occur during communication. After sending each frame, the host computer waits for the PLC to return a delimiter (i.e., "↙") before sending the next frame. A response code is only returned after the end frame data has been completely transmitted.
6. Conclusion
This paper implements serial communication between a host computer and an Omron PLC using the MSComm control in VB, fully leveraging the real-time, reliable, high-speed, long-distance, and easy-to-maintain characteristics of the CAN bus. The computer can work seamlessly with various software provided by the PLC manufacturer to achieve more powerful functions, such as system configuration, human-machine interface, and configuration development.
Typically, computers and PLCs are connected via serial ports to achieve various communication functions. However, the communication distance and number of nodes of a serial port are limited by the performance of the serial port itself. For example, the RS-232 standard can only achieve 1 : 1 communication, and the RS-422/485 standard can achieve communication of up to 32 nodes. The communication distance and anti-interference ability are relatively weak, which cannot meet the needs of multiple PLCs networking applications in actual industrial sites. Even with the help of RS232/RS485-CAN adapters, it is difficult to overcome the functional limitations of serial communication itself [5].
In response to this situation, a PC-CAN interface card built into a computer can be used to establish one or more CAN bus networks. Through the RS232/RS485-CAN adapter connected in the CAN bus network, and with the help of the virtual serial port software that comes with the CAN bus network, up to 2047 standard serial communication ports can be established, thereby connecting up to 2047 serial networks [6]. In other words, up to 2047 PLC devices can be connected on the same ordinary twisted pair cable. The access of the PLC devices connected to this CAN bus network by the industrial control PC is also completely consistent with the operation of the standard serial port.
This approach fully leverages the capabilities of industrial control PCs, offers high communication efficiency, and provides flexible applications, making it the mainstream direction for general PLC network construction.