I am using a Pi4B to try to read data from a SDM630 energy meter. Because the meter is far from the Pi I us a HF2211 ethernet to RS485 converter to bridge the distance. the HF2211 is in transparent mode so the payload of the ethernet messages is forwarded to the RS485 bus. This setup is already working good for my PV inverter with Modbus interface. I hooked up the energy meter to the other side of the RS485 bus.
to start I generate a virtual serial device on the Pi (virtual communication) with socat.
sudo socat pty,link=/dev/sdm, raw tcp:172.17.x.y:8899 &
so now I have a virtual serial device that talks to my ethernet <=> RS485 converter.
next I call minimalmodbus
device = minimalmodbus.Instrument('/dev/sdm', 1, debug = True)
device.serial.baudrate = 9600
print (device)
print ( device.read_register(2))
the result is
MinimalModbus debug mode. Create serial port /dev/sdm
minimalmodbus.Instrument<id=0xb61a5cf0, address=1, mode=rtu, close_port_after_each_call=False, precalculate_read_size=True, clear_buffers_before_each_transaction=True, handle_local_echo=False, debug=True, serial=Serial<id=0xb61a5d10, open=True>(port='/dev/sdm', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=0.05, xonxoff=False, rtscts=False, dsrdtr=False)>
and
MinimalModbus debug mode. Will write to instrument (expecting 7 bytes back): 01 03 00 00 00 01 84 0A (8 bytes)
MinimalModbus debug mode. Clearing serial buffers for port /dev/sdm
MinimalModbus debug mode. No sleep required before write. Time since previous read: 18336983.37 ms, minimum silent period: 4.01 ms.
MinimalModbus debug mode. Response from instrument: (0 bytes), roundtrip time: 0.1 ms. Timeout for reading: 50.0 ms.
and
Traceback (most recent call last):
File "/home/domotica/scripts/python/sdm-test.py", line 24, in <module>
print ( device.read_register(0, 0))
File "/usr/local/lib/python3.7/dist-packages/minimalmodbus.py", line 486, in read_register
payloadformat=_Payloadformat.REGISTER,
File "/usr/local/lib/python3.7/dist-packages/minimalmodbus.py", line 1245, in _generic_command
payload_from_slave = self._perform_command(functioncode, payload_to_slave)
File "/usr/local/lib/python3.7/dist-packages/minimalmodbus.py", line 1322, in _perform_command
response_bytes = self._communicate(request_bytes, number_of_bytes_to_read)
File "/usr/local/lib/python3.7/dist-packages/minimalmodbus.py", line 1490, in _communicate
raise NoResponseError("No communication with the instrument (no answer)")
minimalmodbus.NoResponseError: No communication with the instrument (no answer)
what did I check
- there are no overlapping Modbus addresses used
- I tried various numbers of the registers and numbers for number of decimals
- Socat creates a device called /dev/pts/number. this device is owned by root, I change the owner to pi, which is running the program.
- config parameters of the RS485 devices are all 9600,8,1,N
- proper connection and termination of the bus
- traffic on the bus with scope, yes there is traffic with expected voltages, but is looks like only the Master is talking, no response from the Slave.