ReadDeviceInformationRequest returns None

298 views
Skip to first unread message

Adam L

unread,
Oct 20, 2014, 7:05:01 AM10/20/14
to pymo...@googlegroups.com
Hi everybody!

It's my first post in the google group so...nice to meet you guys :) I'm quite new with modbus and recently I decided to implement some simple functionality to my app. I tested examples and synchronous-client.py combined with synchronous-server.py work as I expected. Today I was trying to test examples from synchronous-client-ext.py and my script stuck at command ReadDeviceInformationRequest(), which returns None after execution. I'm using pymodbus 1.2.0 (installed by pip) and python 3.4. Here is some code cutted to minimum.

test_server.py
#!/usr/bin/env python
from pymodbus.server.sync import StartTcpServer
from pymodbus.device import ModbusDeviceIdentification
import logging

logging
.basicConfig()
log
= logging.getLogger()
log
.setLevel(logging.DEBUG)

identity
= ModbusDeviceIdentification()
identity
.VendorName  = 'Pymodbus'
identity
.ProductCode = 'PM'
identity
.VendorUrl   = 'http://github.com/bashwork/pymodbus/'
identity
.ProductName = 'Pymodbus Server'
identity
.ModelName   = 'Pymodbus Server'
identity
.MajorMinorRevision = '1.0'

StartTcpServer(identity=identity, address=("localhost", 502))

test_client.py
#!/usr/bin/env python

from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.mei_message import *
import logging

logging
.basicConfig()
log
= logging.getLogger()
log
.setLevel(logging.DEBUG)

client
= ModbusClient('127.0.0.1')
client
.connect()

rq
= ReadDeviceInformationRequest()
rr
= client.execute(rq)
print(rr) #gives None

client
.close()

server's console output:
DEBUG:pymodbus.server.sync:Started thread to serve client at ('127.0.0.1', 61107)
DEBUG
:pymodbus.server.sync:Client Connected [127.0.0.1:61107]
DEBUG
:pymodbus.server.sync:0x0 0x1 0x0 0x0 0x0 0x5 0x0 0x2b 0xe 0x1 0x0
DEBUG
:pymodbus.transaction:0x0 0x1 0x0 0x0 0x0 0x5 0x0 0x2b 0xe 0x1 0x0
DEBUG
:pymodbus.factory:Factory Request[43]
DEBUG
:pymodbus.server.sync:Client Disconnected [127.0.0.1:61107]

and client's output:
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG
:pymodbus.transaction:
DEBUG
:pymodbus.transaction:getting transaction 1
None

could you tell me how I could perform correct ReadDeviceInformationRequest? I tested Serial version with simple hardware loop between two devices, but failed with the same result...



Adam L

unread,
Oct 20, 2014, 4:37:14 PM10/20/14
to pymo...@googlegroups.com
After checking on another machine the newest pymodbus version for python 2.x ("Bumping the version to 1.3.0 ", commit eb51b4df4f) everything works fine. Does anybody have info about this issue/bug? Unfortunately I have to use python 3.x in my project...

greets,
Adam

Galen Collins

unread,
Oct 20, 2014, 5:48:38 PM10/20/14
to pymo...@googlegroups.com

There is a python 3 branch on github, see if that works for you.

--
You received this message because you are subscribed to the Google Groups "pymodbus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymodbus+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam L

unread,
Oct 21, 2014, 3:20:57 AM10/21/14
to pymo...@googlegroups.com
Hi Bashwork,

I've tried with cloned branch for python3 (commit from 2013-07-21) but with the same result...also test_mei_messages.py gives me error:

F......
======================================================================
FAIL
: testReadDeviceInformationRequest (__main__.ModbusMeiMessageTest)
Test basic bit message encoding/decoding
----------------------------------------------------------------------
Traceback (most recent call last):
 
File "C:\Users\alutkows\git\pymodbus\test\test_mei_messages.py", line 55, in testReadDeviceInformationRequest
   
self.assertTrue(result.information[0x02], "v2.1.12")
AssertionError: '' is not true : v2.1.12

----------------------------------------------------------------------
Ran 7 tests in 0.002s

I've tried with connection over TCP, Serial(ascii, rtu, binary) with the same result... should I somehow download version for python 2.x and convert it? Do you have any possibility to test it on python 3.4?

Adam L

unread,
Oct 23, 2014, 9:43:45 PM10/23/14
to pymo...@googlegroups.com
Finally I think I found  a bug. In master and python3 branch is a wrong _rtu_frame_size for MEI message ReadDeviceInformationRequest.

mei-messages.py
class ReadDeviceInformationRequest(ModbusRequest):
   
(...)

    function_code
= 0x2b
    sub_function_code
= 0x0e
    _rtu_frame_size
= 3

If we use RTU framer, it will get this wrong value directly from the class instead of calculating it. For this request correct size should be 7.

1b - [UID]
1b - [0x2b]
1b - [0x0e]
1b - [Read Device ID code]
1b - [Object ID]
2b - [CRC]

After changes everything works fine.
Reply all
Reply to author
Forward
0 new messages