Modbus Protocol Hands-On Practice

Publisher:RadiantBreezeLatest update time:2024-07-01 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Let's prepare a PLC and communication first.

We need a PLC that supports Modbus RTU communication and a USB to serial cable.


Then prepare a tool software on the computer.

picture

1 Let's confirm the serial port parameters of the PLC.

picture

The current serial port of PLC supports Modbus protocol.

The serial port parameters are 115200 baud rate, 8 data bits, 1 stop bit, and no parity.

2 Open the Modbus Poll tool.

picture

The setting parameters are also 115200, 8, 1, or none.

3 Select Register Variable.

picture

Click the button in the figure to select the register to be read or written.

Slave ID is the ID of the slave device. Set it to 1 to correspond to the PLC.

Function: It is the function code. The function corresponding to the 0X register is 01 for read.

Address: The register address to be read. Set it to 0, that is, start reading from 0, which just corresponds to the output point on the PLC.

Quantity: The number of registers. Set it to 10, we read 10 first.

Sacn Rate: Scanning cycle. The default is 1000ms. That is, read once every 1000ms.

Don’t worry about other parameters, leave them as default, and click OK.

picture

Then it shows that all communications are connected.

Let's try setting all even addresses to 1.

picture

Double-click the value inside, and the setting value interface will appear. Because it is written separately, the default function code 05 can be used.

picture

picture

It can be seen that the corresponding output point in the PLC is also set to 1.

This is a very basic Modbus RTU communication demo.

If you thought that was the end of it, you were probably right.

We start learning the Modbus protocol. There is no need to make it so complicated. Learn a little bit every day and digest the Modbus protocol slowly.

First learn how to use it, and then learn more about the protocol.

Well, if you have digested the previous content, we can continue. If you have not digested it, I suggest you save the following content and continue reading it another day.

In the experiment just now, we saw the reading and writing operations of PLC through the computer's Modbus Poll.

Don't we want to know how they use it?

Modbus Poll has a function that can display the sent and received messages, which is very helpful for us to learn the Modbus protocol.

picture

We find the Display->Communication option and we can see the sent and received messages.

picture

Tx:072-01 01 00 00 00 0A BC 0D

Rx:073-01 01 02 55 01 47 6C

We copy a message.

1.jpg

For beginners, whether users or developers, it is recommended to find a device and tool that supports Modbus, such as Modbus Poll, to perform communication tests to see what the Modbus message looks like and the reading and writing status.

Because I have encountered some beginners who use a serial port tool to send data to the microcontroller or PLC, but find that the other party does not respond. In addition to setting the serial port parameters correctly, you must ensure that your message is the correct Modbus protocol.

For example, if we read 0X register and read 10, the message is 01 01 00 00 00 0A BC 0D

I guess many people know the previous message 01 01 00 00 00 0A.

Then use a tool or online to calculate CRC. Either the result is wrong, or the result is correct but the message is 01 01 00 00 00 0A 0D BC. The bytes of CRC are reversed.

No matter what I send, PLC just doesn't reply.

This is a common mistake made by many novices and beginners.

So don't underestimate a simple Modbus. It is not an easy task to use it well.

Sometimes, there is a problem when your device communicates with the other device, and you cannot clearly tell whether it is a problem with your device or the other device, which can easily lead to unnecessary misunderstandings and work.

picture

Modbus Poll also provides read and write tests for different function codes.


Reference address:Modbus Protocol Hands-On Practice

Previous article:What are the applications of frequency converters in mine hoists?
Next article:What does the Modbus protocol look like? What are the parameters of the Modbus RTU protocol?

Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号