Communication between PC and Mitsubishi PLC using VB6.0

Source: Internet
Author: User

Http://www1.eccn.com/tech06/te083733.asp

 

In this paper, the PC and Mitsubishi FX series PLC communication is through the PLC programming port and the serial port of the PC machine, using SC-09 programming cable as the connection between the computer and PLC communication. The 9-core d-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.

PC communication program can be compiled using assembly language, a variety of advanced languages, Industrial Control Configuration Software or directly using the PLC manufacturer's communication software. This article uses VB6.0 software, it must be based on the communication procedures of the connected PLC to write the communication protocol, so first briefly introduce the FX series PLC communication protocol.

I. Communication Protocols of FX series PLC

1. Data Transmission Format

FX series PLC adopts asynchronous format and consists of one-bit start bit, seven-Bit Data bit, l-bit even check bit, and l-bit stop bit. The baud rate is 9600bps, and the character is ASCI ⅱ code.

2. Communication commands

Fx plc has four Communication commands: read, write, force, and force-disconnect. In table 1, x is the input relay, Y is the output relay, M is the auxiliary relay, S is the state element, T is the timer, C is the counter, and D is the data register.

3. Communication control characters

The FZ Series PLC adopts character-oriented transmission procedures and uses five 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. STX indicates the Start mark, ETS indicates the end mark, and CMD indicates the ASC ⅱ code of the command. sumh and suml accumulate and overflow from cmd to etx in bytes. Because the hexadecimal number of each byte is changed to two-byte ASC ⅱ code, the checksum is sumh and SUMI.

The Response Message format sent by the PLC to the PC is shown in table 4.

Ii. Compiling of PC communication program

1. Communication Port Initialization

, MSComm control Introduction: VB comes with MSComm control dedicated for managing serial communication. You only need to set several major parameters to implement serial communication between the PLC and the PC. To complete the communication, you must set the MSComm attribute value, that is, the communication port initialization. The steps are as follows:

(1) coinmport: set or return the Communication Connection port code.

(2) settings: Set initialization parameters. Set or return four parameters, including connection speed, parity, data bit, and stop bit, as a string.

(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 string to the output register.

(6) inputlen: Specifies the length of the string read by the serial port.

(7) inbuffercount: number of characters returned in the receiving register.

2. Example of a communication program

First, add MSComm controls, buttons, text boxes, labels, and so on before the form is designed.

(1) PC reads data from PLC

Assume that the PC needs to read 4 bytes of data starting from d123 from the PLC (occupying two data registers: d123 and d124), as shown in table 5.

The address algorithm is

Address = address × 2 + 1000 h

Convert address 123 to 7bh in hexadecimal format, so the first address is:

Address = addressx2 + 1000 h = 7bhx2 + 1000 h = 10f 6 h.

Convert the ASCII code to 31 H, 30 h, 46 h, and 36 h.

Sum = 30 h + 31 H + 30 h + 46 h + 36 h + 30 h + 34 h + 03 H = 174 h, the overflow part is not counted, therefore, sumh is "7", suml is "4", and the corresponding ASC ⅱ code is "37 h" and "34 h ".

The PLC Response Message format is shown in table 6.

(2) write data into PLC

For example, the packet format for writing data "1234 ABCD" to the d123 data register of PLC is shown in table 7.

This article describes how to use VB6. O to realize the communication between PC and Mitsubishi PLC. It is practical and has extensive practical value. It is very helpful for beginners.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.