Hello I have built two simple Parts of Software to do some tests with the modbus-tk lib.
Computer one are running with this code:
import modbus_tk
import modbus_tk.modbus_tcp as modbus_tcp
import modbus_tk.defines as mdef
logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s")
server = modbus_tcp.TcpServer(address='192.168.0.33', port=502, timeout_in_sec=5)
slave = server.add_slave(1)
slave.add_block("a", mdef.HOLDING_REGISTERS, 0, 2)
slave.set_values("a", 0, 888)
slave.set_values("a", 1, 999)
server.start()
Comuter two is running this Code:
import modbus_tk
import modbus_tk.defines as cst
import modbus_tk.modbus_tcp as modbus_tcp
logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s")
master = modbus_tcp.TcpMaster(host='192.168.0.33', port=502, timeout_in_sec=5.0)
value = master.execute(1, cst.READ_INPUT_REGISTERS, 0, 1)
print 'value:',value
Computer one is running without failure until the code on Computer two runs. Then I get this failure:
Computer one:
('192.168.0.111', 49545) is connected with socket 4...
4 is disconnected
Computer two:
Traceback (most recent call last):
File "modbus_04.py", line 8, in <module>
value = master.execute(1, cst.READ_INPUT_REGISTERS, 0, 1)
File "/usr/local/lib/python2.7/dist-packages/modbus_tk-0.4.2-py2.7.egg/modbus_tk/utils.py", line 26, in new
raise excpt
modbus_tk.modbus.ModbusError: Modbus Error: Exception code = 2
Please, can someone help and tell me what the error is.