Starting with pymodbus

715 views
Skip to first unread message

Iván González Cano

unread,
Oct 2, 2012, 11:14:46 AM10/2/12
to pymo...@googlegroups.com
Hi,

I am just starting with pymodbus and I wanted to ask some questions:

- I have installed pymodbus using easy_install. It creates a "pymodbus-1.0.0-py2.7.egg" file and also creates a "Twisted-12.2.0-py2.7-win32.egg" folder. I am using Eclispe with PyDev Plugin and when I copy the synchronous client and server examples it doesn't recognize the pymodbus packages:

http://packages.python.org/pymodbus/examples/index.html#example-library-code

Client error line:
from pymodbus.client.sync import ModbusTcpClient as ModbusClient

Server error lines:
from pymodbus.server.sync import StartTcpServer
from pymodbus.server.sync import StartUdpServer
from pymodbus.server.sync import StartSerialServer

from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext

- Yet it seems to run but I get some errors when trying to run the client:

Client console:
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x5 0x0 0x1 0xff 0x0
DEBUG:pymodbus.factory:Factory Response[5]
DEBUG:pymodbus.transaction:Running transaction 2
DEBUG:pymodbus.transaction:0x0 0x2 0x0 0x0 0x0 0x4 0x0 0x1 0x1 0x1
DEBUG:pymodbus.factory:Factory Response[1]
DEBUG:pymodbus.transaction:Running transaction 3
DEBUG:pymodbus.transaction:0x0 0x3 0x0 0x0 0x0 0x6 0x0 0xf 0x0 0x1 0x0 0x8
DEBUG:pymodbus.factory:Factory Response[15]
DEBUG:pymodbus.transaction:Running transaction 4
DEBUG:pymodbus.transaction:0x0 0x4 0x0 0x0 0x0 0x4 0x0 0x1 0x1 0xff
DEBUG:pymodbus.factory:Factory Response[1]
DEBUG:pymodbus.transaction:Running transaction 5
DEBUG:pymodbus.transaction:0x0 0x5 0x0 0x0 0x0 0x6 0x0 0xf 0x0 0x1 0x0 0x8
DEBUG:pymodbus.factory:Factory Response[15]
DEBUG:pymodbus.transaction:Running transaction 6
DEBUG:pymodbus.transaction:0x0 0x6 0x0 0x0 0x0 0x4 0x0 0x2 0x1 0xff
DEBUG:pymodbus.factory:Factory Response[2]
Traceback (most recent call last):
  File "C:\Users\ivan.gonzalez\Desktop\workcopy-LEW\trunk\Feve\workspace\PyModbus\src\Cliente.py", line 59, in <module>
    assert(rr.bits == [False]*8)        # test the expected value
AssertionError

Server console:
DEBUG:pymodbus.server.sync:Started thread to serve client at ('127.0.0.1', 57280)
DEBUG:pymodbus.server.sync:Client Connected [127.0.0.1:57280]
DEBUG:pymodbus.server.sync:0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x5 0x0 0x1 0xff 0x0
DEBUG:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x5 0x0 0x1 0xff 0x0
DEBUG:pymodbus.factory:Factory Request[5]
DEBUG:pymodbus.datastore.context:validate[5] 2:1
DEBUG:pymodbus.datastore.context:setValues[5] 2:1
DEBUG:pymodbus.datastore.context:getValues[5] 2:1
DEBUG:pymodbus.server.sync:send: 00010000000600050001ff00
DEBUG:pymodbus.server.sync:0x0 0x2 0x0 0x0 0x0 0x6 0x0 0x1 0x0 0x1 0x0 0x1
DEBUG:pymodbus.transaction:0x0 0x2 0x0 0x0 0x0 0x6 0x0 0x1 0x0 0x1 0x0 0x1
DEBUG:pymodbus.factory:Factory Request[1]
DEBUG:pymodbus.datastore.context:validate[1] 2:1
DEBUG:pymodbus.datastore.context:getValues[1] 2:1
DEBUG:pymodbus.server.sync:send: 00020000000400010101
DEBUG:pymodbus.server.sync:0x0 0x3 0x0 0x0 0x0 0x8 0x0 0xf 0x0 0x1 0x0 0x8 0x1 0xff
DEBUG:pymodbus.transaction:0x0 0x3 0x0 0x0 0x0 0x8 0x0 0xf 0x0 0x1 0x0 0x8 0x1 0xff
DEBUG:pymodbus.factory:Factory Request[15]
DEBUG:pymodbus.datastore.context:validate[15] 2:8
DEBUG:pymodbus.datastore.context:setValues[15] 2:8
DEBUG:pymodbus.server.sync:send: 000300000006000f00010008
DEBUG:pymodbus.server.sync:0x0 0x4 0x0 0x0 0x0 0x6 0x0 0x1 0x0 0x1 0x0 0x8
DEBUG:pymodbus.transaction:0x0 0x4 0x0 0x0 0x0 0x6 0x0 0x1 0x0 0x1 0x0 0x8
DEBUG:pymodbus.factory:Factory Request[1]
DEBUG:pymodbus.datastore.context:validate[1] 2:8
DEBUG:pymodbus.datastore.context:getValues[1] 2:8
DEBUG:pymodbus.server.sync:send: 000400000004000101ff
DEBUG:pymodbus.server.sync:0x0 0x5 0x0 0x0 0x0 0x8 0x0 0xf 0x0 0x1 0x0 0x8 0x1 0x0
DEBUG:pymodbus.transaction:0x0 0x5 0x0 0x0 0x0 0x8 0x0 0xf 0x0 0x1 0x0 0x8 0x1 0x0
DEBUG:pymodbus.factory:Factory Request[15]
DEBUG:pymodbus.datastore.context:validate[15] 2:8
DEBUG:pymodbus.datastore.context:setValues[15] 2:8
DEBUG:pymodbus.server.sync:send: 000500000006000f00010008
DEBUG:pymodbus.server.sync:0x0 0x6 0x0 0x0 0x0 0x6 0x0 0x2 0x0 0x1 0x0 0x8
DEBUG:pymodbus.transaction:0x0 0x6 0x0 0x0 0x0 0x6 0x0 0x2 0x0 0x1 0x0 0x8
DEBUG:pymodbus.factory:Factory Request[2]
DEBUG:pymodbus.datastore.context:validate[2] 2:8
DEBUG:pymodbus.datastore.context:getValues[2] 2:8
DEBUG:pymodbus.server.sync:send: 000600000004000201ff
ERROR:pymodbus.server.sync:Socket error occurred [Errno 10054] Se ha forzado la interrupción de una conexión existente por el host remoto
DEBUG:pymodbus.server.sync:Client Disconnected [127.0.0.1:57280]

This is the line when the program crashes:

rq = client.write_coils(1, [False]*8)
rr = client.read_discrete_inputs(1,8)
assert(rq.function_code < 0x80)     # test that we are not an error
assert(rr.bits == [False]*8)        # test the expected value

Do you know what is the problem? Have I installed pymodbus well?

Thanks, 




Bashwork

unread,
Oct 2, 2012, 11:45:46 AM10/2/12
to pymo...@googlegroups.com
Ivan,

Is there any way to can install the code from source on github (https://github.com/bashwork/pymodbus)?  The packages on pypi are a little old at the moment (I will update them shortly).  Also, the documentation is now located at http://pymodbus.readthedocs.org/en/latest/index.html (it is automatically updated when I check in).  Try that, rerun your test, and let me know if the error persists.

I actually have not used pydev so I can't really help you with those errors right now, however, I will give it a try when I have a free moment and add instructions to the project.

Thanks,

Galen

Alejandro Mesias

unread,
Oct 2, 2012, 12:27:51 PM10/2/12
to pymo...@googlegroups.com
indeed, i've used the version from github too. Not sure why, the version from git worked very well.
--
======================================
Alejandro Mesias André Nebra Perez
Java/Python/Js/Something else Developer
Twitter: @meszias
Linux User #442506
Campinas - SP - Brasil - South America
======================================
Message has been deleted

Iván González Cano

unread,
Oct 3, 2012, 3:19:58 AM10/3/12
to pymo...@googlegroups.com

I have installed that version and I think now it does it well. I changed the client example port to 502 instead of 5020 and it did it. However, I am not sure the setup finished right.

The eclipse import errors didn't go away, but is fine as long as I can run the client and server programs.

Thanks.

Bashwork

unread,
Oct 4, 2012, 11:14:44 AM10/4/12
to pymo...@googlegroups.com
Okay,

I installed PyDev and configured it to work with the project (I checked in the .project and .pydevproject files).  You may have to change some of the library configurations as I point to a virtualenv (and I don't know how your system is set up), but I didn't see any errors being displayed, the tests run correctly, and the examples run correctly.

Galen

Iván González Cano

unread,
Oct 4, 2012, 11:22:27 AM10/4/12
to pymo...@googlegroups.com
I have added the .egg file to my project and the errors dissapeared. I seams to work well since I installed the version you told me.

Thanks a lot.
Reply all
Reply to author
Forward
0 new messages