Hello,
At the moment I want to apply the TCP server example on my needs. I want to read registers from a SMA photovoltaic inverter via MODBUS. The occuring protocol can be found here. The most important parameters are port = 502 and Unit ID = 3.
One registers of interest is 30535 which is an U32 value which means to read two registers.
I tried the following implementation in Python. I tried both to use holding registers and analog inputs.
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import sys
import modbus_tk
import modbus_tk.defines as cst
import modbus_tk.modbus as modbus
import modbus_tk.modbus_tcp as modbus_tcp
if __name__ == '__main__':
try:
#Create the server
server = modbus_tcp.TcpServer(address='192.168.178.26', port=502)
server.start()
slave = server.add_slave(3)
slave.add_block('0', cst.HOLDING_REGISTERS, 30535, 2)
slave.add_block('1', cst.ANALOG_INPUTS, 30535, 2)
values = slave.get_values('0', 30535, 2)
sys.stdout.write(str(values))
values = slave.get_values('1', 30535, 2)
sys.stdout.write(str(values))
finally:
server.stop()
On
the other hand by using QModMaster I can read the correct values for
the register. The reading is succesfully for both Read Input Registers
and Read Holding Registers.See the following screenshots for more
details:
--
You received this message because you are subscribed to the Google Groups "modbus-tk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modbus-tk+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.