Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to test Modbus RTU communication on raspberry pie 3

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to test Modbus RTU communication on Raspberry Pi 3. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

You need to run sudo raspi-confg command configuration

A reboot is required to make the configuration take effect.

Modify the cmdline.txt configuration file and open the file with vi or nano

Enter the command sudo nano/boot/cmdline.txt

Settings config.txt

Enter the command sudo nano/boot/config.txt

Add a ban on Bluetooth to the last line of the file,

After all configurations are complete, reboot the Raspberry Pi.

Connect the computer through serial port and Raspberry Pi, because the GPIO pin serial port of Raspberry Pi is TTL level, so we need to use TTL to RS232, if your laptop has RS232 serial port, then you can use TTL to RS232 to connect your computer, but now most laptops do not have serial port, so add an RS232 to USB converter to connect to the computer, pay attention to wiring must be correct, to prevent damage to Raspberry Pi hardware. as shown in the following figure

=============

Before testing, you need to modify some source code. On the Raspberry Pi, you need to modify some code because the routine is not ttyAMA0 serial port.

Then save and exit compilation

Run it under the tests folder in the libmodbus source directory on your computer

sudo ./ unit-test-server rtu

Run sudo on the Raspberry Pi./ unit-test-client rtu

Be sure to include the parameter rtu, and it is lowercase, because if there is no parameter, the default is to test modbus TCP/IP.

You can see that many function codes have been tested, such as 01, 02, 03, 04, 05 06, 10, etc. Finally, we can see all tests pass with success. Proof that our MODBUS RTU test can pass completely, which also tested some exception codes, interested can see these source codes. So far we have completed the MODBUS RTU mode test of the libmodbus protocol stack, plus the MODBUS TCP/IP pushed by the public number. So far we have introduced the RTU and TCP under libmodbus. On this basis, we can modify the routine to realize our own functions. For example, we can use the Raspberry Pi as a client to connect some devices. For example, we can use the serial port of the Raspberry Pi to communicate with some controller devices with serial ports through mdobus RTU. The Raspberry Pi can then connect to the Internet via Modbus TCP/IP, implementing a gateway function.

Thank you for reading! About "How to test Modbus RTU communication on Raspberry Pi 3" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report