pymodbus auf einem Pi 3 mit RS-485-HAT: keine Antwort vom Zähler auf ttyS0
Von English mit KI übersetzt ·
Pi 3B, ein RS-485-HAT am GPIO-Header (automatische Richtung), ein Schneider PM5110 Energiezähler auf Adresse 1, 9600 8E1 am Frontpanel des Zählers eingestellt. Geplant ist, einige Register auszulesen und alle 10 s an Hermetry zu senden.
from pymodbus.client import ModbusSerialClient
c = ModbusSerialClient(port="/dev/ttyS0", baudrate=9600, parity="E", stopbits=1, bytesize=8, timeout=1)
c.connect()
print(c.read_holding_registers(3027, count=2, slave=1))
Jedes Mal das gleiche Ergebnis:
Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response
Die Kommunikations-LED des Zählers blinkt, wenn ich sende, also kommt etwas bei ihm an. Derselbe Zähler antwortet an meinem Laptop über einen USB-RS-485-Stick mit den gleichen Einstellungen. Ich arbeite seit Jahren mit Modbus an SPSen, aber Pis sind für mich neu.
Pi 3B, an RS-485 HAT on the GPIO header (auto direction), one Schneider PM5110 power meter at address 1, 9600 8E1 set on the meter’s front panel. The plan is to read a handful of registers and publish them to Hermetry every 10 s.
from pymodbus.client import ModbusSerialClient
c = ModbusSerialClient(port="/dev/ttyS0", baudrate=9600, parity="E", stopbits=1, bytesize=8, timeout=1)
c.connect()
print(c.read_holding_registers(3027, count=2, slave=1))
Result every time:
Modbus Error: [Input/Output] No Response received from the remote slave/Unable to decode response
The meter’s comms LED blinks when I send, so something reaches it. Same meter answers a USB RS-485 stick on my laptop with the same settings. I’ve done Modbus for years on PLCs but Pis are new to me.
Von English mit KI übersetzt ·
Ist die Baudrate auf beiden Seiten gleich? Ich bekomme diesen Fehler immer, wenn ich vergesse, sie umzustellen.
Is the baud the same on both ends? I always get that error when I forget to change it.
Von English mit KI übersetzt ·
Hast du Bluetooth ausgeschaltet? Beim Pi 3 wird die gute UART standardmäßig für Bluetooth verwendet.
Did you turn Bluetooth off? On the Pi 3 the good UART goes to Bluetooth by default.
Von English mit KI übersetzt ·
Baudrate stimmt überein. Bluetooth habe ich nicht angefasst.
Baud matches. Bluetooth I haven’t touched.
Von English mit KI übersetzt ·
Ich bin kein Ingenieur, aber ich habe diesen genauen Fehler eine Woche lang bekämpft, mit einem Pi 3 und einem Wärmezähler im Heizungsraum unseres Hotels, und es waren zwei Dinge zusammen.Beim Pi 3 ist der eigentliche UART (PL011) mit Bluetooth verbunden, und die GPIO-Pins bekommen den Mini-UART, ttyS0. Die Baudrate des Mini-UART folgt dem Core-Takt, daher ist 9600 nicht mehr 9600, sobald die CPU ihre Geschwindigkeit ändert. Der Mini-UART hat außerdem keine Parität, Ihr Zähler läuft aber mit 8E1. Der Zähler hört also Ihre Anfrage, antwortet, und der Pi kann die Antwort nicht richtig deuten.Der zweite Punkt hat mich erwischt: die serielle Login-Konsole. Wenn in cmdline.txt noch console=serial0,115200 steht, schreibt der Pi beim Booten seinen Login-Prompt auf den RS-485-Bus und hält einen getty auf dem Port offen.Was bei mir geholfen hat:
# /boot/firmware/config.txt (oder /boot/config.txt bei älteren Images)
enable_uart=1
dtoverlay=disable-bt
sudo systemctl disable hciuart
# raspi-config: Interface Options > Serial Port
# login shell over serial: No, serial port hardware: Yes
Neu starten, dann in pymodbus /dev/serial0 verwenden (zeigt danach auf ttyAMA0). Prüfen Sie außerdem, ob Ihr Zähler Register ab 0 oder ab 1 zählt. Schneider-Handbücher listen sie 1-basiert, also ist 3028 im Handbuch auf der Leitung 3027, und Sie lagen damit richtig.
I’m not an engineer, but I fought this exact error for a week with a Pi 3 and a heat meter in our hotel’s boiler room, and it was two things together.
On a Pi 3 the proper UART (PL011) is wired to Bluetooth and the GPIO pins get the mini UART, ttyS0. The mini UART’s baud rate follows the core clock, so when the CPU changes speed the 9600 isn’t 9600 any more. The mini UART also has no parity, and your meter is on 8E1. So the meter hears your request, answers, and the Pi can’t make sense of the reply.
Second one got me: the serial login console. If cmdline.txt still has console=serial0,115200, the Pi writes its login prompt onto the RS-485 bus at boot and keeps a getty on the port.
What fixed it for me:
# /boot/firmware/config.txt (or /boot/config.txt on older images)
enable_uart=1
dtoverlay=disable-bt
sudo systemctl disable hciuart
# raspi-config: Interface Options > Serial Port
# login shell over serial: No, serial port hardware: Yes
Reboot, then use /dev/serial0 (it points to ttyAMA0 after this) in pymodbus. Also check whether your meter counts registers from 0 or 1. Schneider manuals list them 1-based, so 3028 in the book is 3027 on the wire, and you had that right.
Von English mit KI übersetzt ·
Es war beides. getty lief auf serial0, und der Mini-UART mit gerader Parität hat nie funktioniert. Nach disable-bt und ausgeschalteter Konsole hat der PM5110 beim ersten Versuch geantwortet: 230,4 V L1-N. Es wird jetzt alle 10 s veröffentlicht. Danke David, und Megan für den Hinweis auf Bluetooth.
It was both. getty was sitting on serial0, and the mini UART with even parity never worked. After disable-bt and the console off, the PM5110 answered on the first try: 230.4 V L1-N. Publishing every 10 s now. Thanks David, and Megan for pointing at Bluetooth.
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.
Mitdiskutieren
Melde dich an, um Fragen zu stellen und zu beantworten, hilfreiche Beiträge mit „Gefällt mir“ zu markieren und die Antwort zu kennzeichnen, die dein Problem gelöst hat. Jeder Beitrag bringt Punkte und Stufen.

