PLCs can communicate with the host computer in various ways, such as directly using existing configuration and monitoring software. However, for small-scale control systems, finding a high-performance, cost-effective communication method is of great practical significance.
1 Hardware Description of the Communication Device
Establishing a communication channel between a PLC and a PC allows them to complement each other's functionalities. PLCs are convenient and reliable for control, while PCs offer strong capabilities in graphic display, data processing, report printing, and Chinese character display. Therefore, PLC manufacturers have developed interface modules for communication between their various PLC models and PCs.
Mitsubishi developed the FX-232AW interface module for communication between FX2 series PLCs and computers. Other interface modules include the AJ71E71 for Ethernet connection, the AJ71M51-S1 for MAP network connection, and the AJ71M51M1 for FAISMAP network connection.
Different communication methods have different costs and applicable scopes. This article introduces a method for communicating with a PLC via the RS-232 port of a PC. (PLC recycling)
The programming interface of the FX2 series PLC uses the RS-422 standard, while the serial port of a computer uses the RS-232 standard. Therefore, the interface circuit used to implement PLC-computer communication must convert the RS-422 standard to the RS-232 standard.
The RS-232 and RS-422 standards differ in signal transmission and logic voltages.
RS-232 uses a single-ended receiver and a single-ended transmitter, transmitting information with only one signal line. The logic "1" (-3 to -15V) and "0" (3 to 15V) are determined by the voltage level on that signal line relative to the common ground level.
The RS-422 standard is a balanced transmission standard, meaning it transmits and receives data from both ends, determining the logic state based on the potential difference between the two transmission lines. An RS-422 circuit consists of a transmitter, a balanced connection cable, a cable termination load, and a receiver. It converts logic levels and potential differences (2V represents "0", -2V represents "1") through a balanced transmitter and a differential receiver. (Siemens PLC recycling.)
The MAX202 from Maxim Integrated is used for level conversion between RS-232 and TTL. The MAX202 has internal voltage multiplier and conversion circuits, requiring only a 5V power supply to operate, making it very convenient to use. The MAX490 is used for conversion between RS-485 and TTL. Each MAX490 has one transmitter/receiver pair; since the communication uses full-duplex mode, two MAX490s are required, along with only four external capacitors.
The RS-422 interface of the PLC is used with a DB-25 connector, while the PC generally uses a DB-9 connector.
Shorting the RS and CS pins of the RS-232 connector ensures the PLC is always in a ready state for data transmission from the computer. This means the computer can send data to the PLC at any time. However, because the DR and ER pins are cross-connected, the computer must wait until the PLC is in a ready state before receiving data. (PLC recycling.)
2. Software Description of the Communication Device
2.1 Communication Protocol between FX2 Series PLC and Computer
The communication between the FX2 series PLC and the computer uses the RS-232 standard, with a fixed transmission rate of 9600bps and even parity. Data is sent and received in frames.
A multi-character frame consists of the five parts shown in the image. The checksum is calculated by adding the ASCII codes (hexadecimal numbers) of the characters between the command codes ETX, and obtaining the lowest two digits of the sum. STX and ETX represent the start and end markers of the character frame, respectively. (Siemens PLC recycling.)
Communication between the FX2 series and the computer is based on an initial command issued by the host computer, to which the PLC responds. There are four commands: 0, 1, 7, and 8. The host computer reads, writes, and forcibly sets bits on the PLC. The host computer coordinates the communication and response between the PLC using ENQ, ACK, and NAK commands.
2.2 Communication Process
The communication program between the host computer and the PLC is written using BlandC. First, the COM1 port must be initialized with a baud rate of 9600bps, even parity, and seven valid data bits. Once the computer receives the ACK character from the PLC, data communication can begin.
The computer can read, write, and force ON/OFF operations on various software devices within the PLC. Except for the PLC's timers and counters when their setpoints are constants, and the data in the file registers, all digital inputs and outputs, as well as all software devices, of the FX2 series PLC are transparent to the computer.
The format of the multi-character frame during operation is shown in Figure 3. However, different operations differ in the "multiple characters" field. For example, when the computer performs a read operation on the PLC's soft devices Y20 to Y37, the device address table is looked up as 00A2, and 2 bytes of data are read. (PLC acquisition.)
If the transmitted command is incorrect, the PLC returns a NAK signal, indicating that the operation has failed and needs to be repeated.
To ensure accurate communication between the host computer and the PLC, the host computer must also perform calibration according to the communication protocol. If the received information is incorrect, it should be read again. If the error persists after three attempts, an error message should be displayed.
The above programming can be easily implemented using the C language.
The host computer can also write data to the PLC and perform single-point strong proximity setting and reset.
This solution is reliable, cost-effective, and compact for operation in high-speed control and laboratory environments. However, for long communication distances and harsh environments, measures such as opto-isolation are required.