Communication with S7-200

257 views
Skip to first unread message

Pierre-Yves

unread,
Oct 27, 2010, 8:59:01 AM10/27/10
to modbus-tk
Hello,

I'm trying to use modbus-tk to grab a few values from an S7-200. The
PLC is configured as slave, and as such I'm using the
rtumaster_example.py on the computer side.

I'm using an USB <=> RS-485 dongle, based on pl2303 chipset (fully
supported under linux).

However, it seems that everything I get back on the serial link is
"255". See below:

Code:
master = modbus_rtu.RtuMaster(serial.Serial(port="/dev/ttyUSB0",
baudrate=115200,
bytesize=8,

parity=serial.PARITY_NONE,
stopbits=1,
xonxoff=0))
master.set_timeout(10.0)
master.set_verbose(True)
logger.info("connected")

logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 40001, 1))

Ouptut:
2010-10-27 14:53:55,754 INFO modbus_rtu.__init__ MainThread RtuMaster /
dev/ttyUSB0 is opened
2010-10-27 14:53:55,768 INFO rtumaster_example.<module> MainThread
connected
2010-10-27 14:53:55,777 DEBUG modbus.execute MainThread ->
1-3-156-65-0-1-250-78
2010-10-27 14:53:55,794 DEBUG modbus.execute MainThread <-
255-255-255-255-255-255-255

Traceback (most recent call last):
File "/home/py/Software/modbus-tk/examples/rtumaster_example.py",
line 37, in <module>
logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 40001,
1))
File "/usr/local/lib/python2.6/dist-packages/modbus_tk-0.4-py2.6.egg/
modbus_tk/utils.py", line 26, in new
raise excpt
ModbusInvalidResponseError: Response address 255 is different from
request address 1


If I change the parameters of "execute" to grab more registers, I get
more bytes in return, but the value still is only 255:

Code:
logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 40001, 2))
(rest is identical)

Ouptut:
2010-10-27 14:56:12,986 DEBUG modbus.execute MainThread ->
1-3-156-65-0-2-186-79
2010-10-27 14:56:13,017 DEBUG modbus.execute MainThread <-
255-255-255-255-255-255-255-255-255
(rest is identical)

I have know idea about what I should check next. Any hint will be much
appreciated.

Pierre-Yves

Luc JEAN

unread,
Oct 27, 2010, 2:55:27 PM10/27/10
to modb...@googlegroups.com
Hello Pierre-Yves,

It's difficult to say what is the cause of this problem?

Have you tried to use a different modbus master? You may try to use Modbus Doctor for example and check if you have a similar result.
Have you checked that the serial settings of the PLC are similar to the one you use in the python script? Be careful with stop bits. I recommend to use pyserial constants (see http://pyserial.sourceforge.net/pyserial_api.html#constants)

I hope it helps
Best
luc

2010/10/27 Pierre-Yves <paul...@gmail.com>



--
http://www.apidev.fr

Pierre-Yves

unread,
Oct 28, 2010, 6:00:13 AM10/28/10
to modbus-tk
Hi Luc,

Thanks for your answer!

I realized it was a cabling/rs-485 adapter problem. So I switched to
an "official" siemens cable, and now I do not get those 255 anymore,
which is already a step in the proper direction.

Now as it still doesn't actually work properly (I get an answer, but
very slowly, and not each time), I went with your suggestion and
tested the setup using Modbus doctor. Which give me the exact same
poor results, so basically it seems the problem is in the PLC.

Let's read the siemens documentation again!

Thanks a lot,
Pierre-Yves

Pierre-Yves

unread,
Nov 3, 2010, 3:43:31 AM11/3/10
to modbus-tk
Hi again,

I am happy to let you know that the problem is solved!

To summarize, it was a combination of improper termination on the
RS-485 cable I was using, and at the same time, an addressing mistake
in my modbus requests (siemens' docs are really not clear about that
IMHO).

So, I can confirm that I'm able to read the holding registers of my
S7-200 without any problem. I've yet to test/use the other functions.

Thank you for this nice piece of software,
Pierre-Yves

Luc JEAN

unread,
Nov 3, 2010, 3:47:40 AM11/3/10
to modb...@googlegroups.com
Hello Pierre-Yves.
Congratulations. Thank you for the feedback. I've updated the wiki page http://code.google.com/p/modbus-tk/wiki/TalkToThem
Best
luc

2010/11/3 Pierre-Yves <paul...@gmail.com>



--
http://www.apidev.fr
Reply all
Reply to author
Forward
0 new messages