Modbus Error: Exception code = 2 when polling values

295 views
Skip to first unread message

Michael McCarty

unread,
Mar 28, 2014, 11:27:06 AM3/28/14
to modb...@googlegroups.com
Hello all,
  I copied this code from another topic in these groupd and changed the address to listen on any.

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='0.0.0.0', 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()

  I poll the server using a client but I always get exception code = 2 this is the traffic

S:  00 27 00 00 00 06 01 03 9F B8 00 01
R:  00 27 00 00 00 03 01 83 02

  I try and read the register 40888, thinking the "holding registers" to be at 40000 + offset ?
Any idea whats wrong ?

Thanks !

Luc JEAN

unread,
Mar 28, 2014, 11:30:05 AM3/28/14
to modb...@googlegroups.com
Hello Michael,

Did you try to read at the 888 address without any 40000?

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/d/optout.

Michael McCarty

unread,
Mar 28, 2014, 11:39:01 AM3/28/14
to modb...@googlegroups.com
Yes tried that I get the same result. I also tried swapping the byte order but then I get

quantity_of_x is 256
Modbus Error: Exception code = 3
quantity_of_x is 256
Modbus Error: Exception code = 3

This is the poll trying to read at 888
S:  00 2D 00 00 00 06 01 03 03 78 00 01
R:  00 2D 00 00 00 03 01 83 02

I see the 3 78 which is 888 decimal and in my previous post I do ask for 40888 in the mb request.

Michael McCarty

unread,
Mar 28, 2014, 1:59:42 PM3/28/14
to modb...@googlegroups.com
So will that code produce values at 888 or 40888 or at all ? Should this be working ? if so I can look down other avenues. I did have to comment out the "console" part because the select did not work in the embedded linux Im using could that have anything to do with this ?

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 530, in __bootstrap_inner
  File "/usr/lib/python2.7/site-packages/modbus_tk-0.4-py2.7.egg/modbus_tk/simulator.py", line 145, in run
    if self._check_console_input(): #if something to read on the console
  File "/usr/lib/python2.7/site-packages/modbus_tk-0.4-py2.7.egg/modbus_tk/simulator.py", line 135, in _check_console_input
    (inputready, abcd, efgh) = select.select([sys.stdin], [], [], 0.5)
NameError: global name 'select' is not defined

Michael McCarty

unread,
Mar 28, 2014, 2:58:13 PM3/28/14
to modb...@googlegroups.com
I figured it out. I should not have been reading "888" register, but reading at register 0

now it works fine, thanks

 S:  00 30 00 00 00 06 01 03 00 00 00 01
 R:  00 30 00 00 00 05 01 03 02 00 80
Reply all
Reply to author
Forward
0 new messages