Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial + Async + RTU: Callback is never fired #160

Closed
submerged15 opened this issue Apr 30, 2017 · 13 comments
Closed

Serial + Async + RTU: Callback is never fired #160

submerged15 opened this issue Apr 30, 2017 · 13 comments

Comments

@submerged15
Copy link

submerged15 commented Apr 30, 2017

Hi again,

I'm using pymodbus over RS485 with RtuFramer and AsyncModbusProtocol based on the twisted serialport. (Python 2.7)

The callback of the method transaction/ModbusRtuFramer/processIncomingPacket is never fired. In this case the method async/ModbusClientProtocol/_handleresponse.

Workaround: Derivate the ModbusClientProtocol, override the dataReceived method and insert the complete content of the processsIncomingPacket method and replace the callback with the actual method _handleresponse.

@dhoomakethu
Copy link
Contributor

If you have a working solution could you please raise a PR, so that it could be reviewed and merged if necessary?
Thanks

@wexi
Copy link

wexi commented May 18, 2017

I probably encounter the same problem with long RTU queries. It is not "firing" since client/async.py dataReceived() receives incomplete data. Indeed, serial.Serial is using non blocking timeout=0, so why would we receive the complete packet if it is long...
I will try to use timeout=None with a short inter_byte_timeout and report if I am successful.

@dhoomakethu
Copy link
Contributor

I believe with the latest release 1.3.0rc1, the issue should be fixed. Just give a try and update your findings.

@wexi
Copy link

wexi commented May 18, 2017

Thanks, however with pymodbus-1.3.0rc1 I encounter the following unhandled error.

  File "/home/wexi/.local/lib/python2.7/site-packages/pymodbus/client/async.py", line 93, in dataReceived
    self.framer.processIncomingPacket(data, self._handleResponse)
  File "/home/wexi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 604, in processIncomingPacket
    self._process(callback, error=True)
  File "/home/wexi/.local/lib/python2.7/site-packages/pymodbus/transaction.py", line 631, in _process
    raise ModbusIOException("Unable to decode request")
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request

@dhoomakethu
Copy link
Contributor

@wexi do see this error always ? I am not able to reproduce this at my end. Could you give more info regarding your setup ?

@wexi
Copy link

wexi commented May 19, 2017

I solved my problem by simplifying/correcting transaction.py processIncomingPacket(self, data, callback). I can't say that I am satisfied: With a given Modbus query the normal response length is known in advance and this information is not utilized. To your question, I am using the Kivy modified twisted reactor. My OS is Ubuntu. Thanks.

patch.txt

@wexi
Copy link

wexi commented May 27, 2017

Adding to my previous comment regarding async RTU (improper repacking, a criticism which still stands):

To add timeout protection to async RTU we have to addTimeout() to the deferred.
addTimeout, when fired, causes a CancelledError response errback.
It is pymodbus responsibility then to remove the transaction from its FifoTransactionManager instance, which it doesn't... bad things then happen, need I explain?

As far as async RTU is concerned we are not at RC quality yet. Please fix :-)

@dhoomakethu
Copy link
Contributor

dhoomakethu commented May 27, 2017 via email

@wexi
Copy link

wexi commented May 27, 2017

A proper solution for the addTimeout() bug requires pymodbus to supply a canceller function during the construction of its deferred. This canceller should remove the transaction from the appropriate manager. Since I am only interested in async RTU now I took a shortcut. I leave it for those with write access to this repository (aka the maintainers) to do the hard work.

Again, processIncomingPacket(), also requires a rewrite...

@dhoomakethu
Copy link
Contributor

dhoomakethu commented May 27, 2017 via email

@bhagn
Copy link
Contributor

bhagn commented Oct 14, 2017

@submerged15, @wexi can you share the code that instantiates the async client? Is the reactor running in its own thread?

@wexi
Copy link

wexi commented Oct 14, 2017

You are welcome to examine my 'local' branch:
https://github.com/wexi/pymodbus/tree/local
See Foreword in README.rst

@dhoomakethu dhoomakethu modified the milestones: 1.4.0, 2.0.0 Dec 23, 2017
@dhoomakethu dhoomakethu mentioned this issue Dec 23, 2017
12 tasks
@rahulraghu94 rahulraghu94 self-assigned this Jan 4, 2018
@rahulraghu94
Copy link
Contributor

Hello, I'm unable to reproduce this problem as of the new pymodbus 1.4.0 release and will be closing this now.

If you are still facing this issue, feel free to reopen this and make sure you leave your code excerpts, logs, expected outputs and anything else that can help us track the problem.

Thanks :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants