Modbus Error: Exception code = 2

830 views
Skip to first unread message

Wolfgang Bertram

unread,
Mar 6, 2014, 5:29:46 AM3/6/14
to modb...@googlegroups.com
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.

Luc JEAN

unread,
Mar 6, 2014, 8:00:48 AM3/6/14
to modb...@googlegroups.com
Did you try to use the READ_HOLDING_REGISTERS function code rather than READ_INPUT_REGISTERS?
Best
luc


--
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/groups/opt_out.

Wolfgang Bertram

unread,
Mar 6, 2014, 8:35:44 AM3/6/14
to modb...@googlegroups.com

From time to time, do not you see the forest for the trees Thank you luc!

Luc JEAN

unread,
Mar 6, 2014, 8:53:16 AM3/6/14
to modb...@googlegroups.com
;-) You are welcome 
Best
luc  


2014-03-06 14:35 GMT+01:00 Wolfgang Bertram <nixf...@gmail.com>:

From time to time, do not you see the forest for the trees Thank you luc!

--
Reply all
Reply to author
Forward
0 new messages