Mitsubishi FX series plc communicates with PC

1 Introduction PLC is widely used in industrial control with excellent reliability and convenient programmability. The purpose of PC and PLC communication is to provide users with various functions such as process flow chart display, dynamic data screen display, report display, window technology, etc., to provide a good man-machine interface for PLC. This article introduced the communication protocol of FX series PLC in detail, and developed the communication program using VB6.0 in Windows environment, realized the serial communication between PC and FX series PLC.
2 Conditions for PCs and PLCs to communicate Communication The PCs and PLCs with asynchronous communication adapters can only communicate with each other if they meet the following conditions:
(1) A PLC with an asynchronous communication interface can be interconnected with a PC with an asynchronous communication adapter. It also requires that the bus standards adopted by both parties be the same, otherwise they will be interconnected after being transformed by the "bus standard conversion unit."
(2) Initialization of both sides makes the baud rate, data bits, stop bits, and parity the same.
(3) It is necessary to analyze the communication protocol of the PLC clearly and write the communication program of the PC in strict accordance with the provisions of the protocol and the frame format. The PLC is equipped with a communication mechanism and generally does not require user programming.
3 PC and serial communication with FX series PLC 3.1 Hardware connection PC and FX series PLC can't be connected directly, it needs to go through RS-232C/RS-422 conversion through FX-232AW unit, the following figure shows the relationship between them. Connection relationship:

3.2 Communication protocol of FX series PLC In the PC, the communication program must be written according to the interconnected PLC communication protocol. Therefore, the communication protocol of the FX series PLC is introduced first.
(1) Data format FX series PLC adopts asynchronous format and consists of 1 start bit, 7 data bits, 1 even parity bit and 1 stop bit. The baud rate is 9600bps and the character is ASCII code. The format is as follows:

(2) Communication Commands The FX-series PLC has four communication commands, which are read commands, write commands, forced-on commands, and forced-off commands, as shown in the following table. Table X-input relay; Y-output relay; M-auxiliary relay; S-state element; T-timer; C-counter; D-data register.

(3) Communication Control Characters The FX series PLC adopts a character-oriented transmission protocol and uses 5 communication control characters as shown in the following table.

* When the PLC does not understand the ENQ sent from the PC, answer it with NAK.
(4) Message format The format of the message sent from the PC to the PLC is as follows:

STX is the start flag: 02H; ETX is the end flag: 03H; CMD is the ASCII code of the command; SUMH, SUML is the sum of the bytes from CMD to ETX, and the overflow does not count. Since the hexadecimal number per byte becomes a two-byte ASCII code, the checksum is SUMH and SUML.
The format and meaning of the data segment are as follows:

* The data segment of the write command has data, and the data segment of the read command has no data.
The number of read/write bytes is 01H to 40H (1 to 64).
The format of the response message sent from the PLC to the PC is as follows:

* The data segment of the reply message to the read command is the data to be read. One data occupies two bytes and is divided into upper and lower bits:

There is no data segment for the reply message of the write command, and ACK and NAK are used as the reply content.
(5) Transmission process The PC and the FX series PLCs communicate in an acknowledgment mode, and if the transmission is erroneous, they are retransmitted. The transmission process is as follows:

The PLC organizes automatic responses after the END statement at the end of each loop scan according to the PC's command, without requiring the user to write the program on the PLC side.
4 Writing Communication Programs Using VB6.0 The following is a simple example to illustrate the point of writing communication programs. Assume that the PC requires to read 4 bytes of data (D123, D124) starting from D123 from the PLC, and the transmission response process and the message are as follows (The diagram is slightly available from the author):
In the command message, 10F6H is the address of D123, and 04H indicates that 4 bytes of data are to be read. Checksum SUM=30H+31H+30H+46H+36H+30H+34H+
03H = 174H, overflow part does not count, so SUMH is '7', SUML is '4', the corresponding ASCII code is "37H", "34H". The 4-byte hexadecimal number in the reply message, the corresponding ASCII code is 8 bytes, so the response message is 12 bytes in length.
According to the transfer process of the PC and the FX series PLC, the flow chart of the communication program shown below is omitted.
Using VB's MSComm control, according to the flow chart can write the following communication program to achieve serial communication between PC and FX series PLC to complete the data read. The MSComm control can take data from the port using polling or event-driven methods. The polling method is used in this example.
(1) Communication Port Initialization Private Sub Initialize()
MSComm1. CommPort = 1
MSComm1. Settings = "9600,E,7,1"
MSComm1. InBufferSize = 1024
MSComm1. OutBufferSize = 1024
MSComm1. InputLen = 0
MSComm1. InputMode = comInputModeText
MSComm1. Handshaking = comNone
MSComm1. PortOpen = True
End Sub
(2) Request Communication and Confirmation Private Function MakeHandShaking() As Boolean
Dim InPackage As String
MSComm1. OutBufferCount = 0
MSComm1. InBufferCount = 0
MSComm1. Output = Chr(&H5)
Do
DoEvents
Loop Until MSComm1. InBufferCount = 1
InPackage = MSComm1. Input
If InPackage = Chr(&H6) Then
MakeHandShaking = True
Else
MakeHandShaking = FalseEnd If
End Function
(3) Send Command Message Private Sub SendFrame()
Dim OutString As String
MSComm1. OutBufferCount = 0
MSComm1. InBufferCount = 0
OutStrin = Chr(&H2)+"0"+"10F604"+Chr(&H3)+"74"
MSComm1. Output = OutString
End Sub
(4) Read reply message Private Sub ReceiveFrame()
Dim InString As String
Do
DoEvents
Loop Until MSComm1. InBufferCount = 12
InString = MSComm1. Input
End Sub
5 Conclusion The communication program written by the mechanism described in this article has been successfully used in high-rise building glass curtain wall cleaning robot system with FX2N PLC as the main controller. Through this communication program, PC monitoring and control of PLC is realized. At the same time, this program also has certain reference significance for the communication between PC and other types of PLC.

This entry was posted in on