The communication between the PC and Mitsubishi FX series PLC described in this article is carried out through the programming port of the PLC and the serial port of the PC. The SC-09 programming cable is used as the connection between the computer and the PLC. The 9-core D-shaped plug of the cable is connected to the computer serial port, and the other end is connected to the RS-422 programming port of the PLC.
The communication program of the PC can be written in assembly language, various high-level languages, industrial control configuration software or the communication software of the PLC manufacturer can be used directly. This article uses VB6. 0 Software, it must write the communication protocol according to the communication procedures of the connected PLC, so first briefly introduce the communication protocol of the FX series PLC.
1. Communication protocol of FX series PLC
1 . Data transmission format
FX series PLC adopts asynchronous format, which is composed of 1 start bit, 7 data bits, l even parity bit and l stop bit. The baud rate is 9600bps and the characters are ASCi Ⅱ codes.
2 . Communication command
FX series PLC has 4 communication commands, namely read command, write command, forced on command and forced off command. In Table 1, X is the input relay; Y is the output relay; M is the auxiliary relay; S is the status element; T is the timer; C is the counter; D is the data register.
3. Communication control characters
FZ series PLC adopts character-oriented transmission procedures, and uses 5 communication control characters, as shown in Table 2.
4. Message format
The message format sent from the PC to the PLC is shown in Table 3. Among them, STX is the start mark; ETS is the end mark; CMD is the ASC Ⅱ code of the command: SUMH and SUML are the cumulative sum of bytes from CMD to ETX, overflow is not counted. Since each byte of hexadecimal number becomes a two-byte ASC Ⅱ code, the checksum is SUMH and SUMI.
The format of the reply message sent from PLC to PC is shown in Table 4.
2. Writing of PC communication program
1 . Communication port initialization
, Introduction to MSComm control: VB comes with MSComm control for managing serial communication. Only need to set a few main parameters to realize the serial communication between PLC and PC. To complete the communication, the relevant attribute value of MSComm must be set, that is, the communication port is initialized. The steps are as follows:
(1)CoinmPort: Set or return the communication connection port code.
(2) Settings: Set initialization parameters. Set or return 4 parameters in the form of word-string, such as connection speed, parity, data bit, and stop bit.
(3) PortOpen: Set or return the status of the communication connection port.
(4) Input: Return and remove characters from the input register.
(5) Output: Write a character string to the output register.
(6) InputLen: Specify the length of the string read in by the serial port.
(7) InBufferCount: Return the number of characters in the receiving register.
2 . Communication program example
1. before the form starts to design, add MSComm controls and buttons, text boxes, labels, etc.
(1) PC reads data from PLC
Suppose that the PC wants to read 4 bytes of data starting from D123 from the PLC (occupies two data registers: D123, D124), and the message is shown in Table 5.
According to the Mitsubishi FX series PLC programming port communication protocol, the address algorithm is
address=address×2+1000h
The address 123 is converted to hexadecimal as 7Bh, so the first address is:
address=addressx2+1000h=7Bhx2+1000h=10F 6h.
Then converted to ASCII code 31h, 30h, 46h, 36h
Checksum SUM=30H+31H+30H+46H+36H+30H+34H+03H=174H, the overflow part is not counted, so SUMH is "7", SUML is "4", and the corresponding ASC Ⅱ code is "37H" and "34H".
The response message format of PLC is shown in Table 6.
(2) Write data to PLC
For example, the message format for writing data "1234ABCD" to the D123 data register of the PLC is shown in Table 7
The use of VB6 introduced in this article. O The basic method to realize the communication between PC and Mitsubishi PLC is practical and has a wide range of practical value. Very helpful for beginners.
Mitsubishi FX series PLC programming port communication protocol example | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1. DEVICE READ (read the value of the software device status) The computer sends to the PLC:
Example: Read 4 bytes of data from D123
Address algorithm: address=address*2+1000h, convert 123 to hexadecimal*2 to get F6, 10F6 Convert to ASCII 31h,30h,46h,36h PLC return
Note: Up to 64 bytes of data can be read Example: read 3584 data from the specified memory unit
2. DEVICE WRITE (write value to PLC soft device)
Example: Write 1234,ABCD to the two memories starting from D123
PLC return ACK (06H) Accepted correctly NAK (15H) acceptance error 3. Forced setting/reset of bit device FORCE ON set
FORCE OFF reset
PLC return ACK(06H) Accepted correctly NAK(15H) accept error Address formula in device enforcement: Address=Address/8+100h Description: 1. BYTES in the frame indicates the number of bytes that need to be read or written. 2. There are instructions on the address algorithm. 3. The accumulated sum is the sum accumulated from one byte after STX to ETX. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mitsubishi FX series PLC programming port communication protocol overview | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This protocol is actually suitable for the communication of PLC programming port and FX-232AW module. Thanks to netizen visualboy providing. Communication format:
Transmission format: RS232C Baud rate: 9600bps Hexadecimal code:
Frame format:
example: STX ,CMD ,ADDRESS, BYTES, ETX, SUM 02H, 30H, 31H,30H,46H,36H, 30H,34H, 03H, 37H,34H SUM=CMD+......+ETX; 30h+31h+30h+46h+36h+30h+34h+03h=74h; Accumulate more than two digits, take the lower two digits Source content: https://blog.katastros.com/a?ID=00600-dc9d9ec0-fe00-4aec-81ce-58b997dcd4a2 |
No comments:
Post a Comment