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

Add connected property to AsyncModbusClientMixin. #229

Merged
merged 2 commits into from
Nov 20, 2017

Conversation

d21d3q
Copy link

@d21d3q d21d3q commented Oct 15, 2017

When using pymodbus with pyserial-asyncio ther is problem when calling protocol right after creation pair of transport an protocol.
On transport initialization protocol.connection_made callback is being added via loop.call_soon so that this example works because client.read_coils is called from coroutine (after several event loop iterations).

When I use it like this:

transport, protocol = await create_serial_connection(...)
coils = await protocol.read_coils(...)

I am getting error 'NoneType' object has no attribute 'write' because transport is not assigned yet to protocol.

connected property allows for such workaround:

while not protocol.connected:
    await asyncio.sleep(0)  # let event loop run

Maybe transport should be responsible for awaiting connection_made inside initializer?

@d21d3q
Copy link
Author

d21d3q commented Nov 19, 2017

Another thing that I've included in this PR is checking if future is done before setting exception.
In case of using in in this way:

result = await asyncio.wait_for(client.read_holding_registers(...), timeout=0.5)

When reaching timeout, inner future is being canceled, and I am obtaining InvalidStateError comming from here

@dhoomakethu dhoomakethu merged commit 6578121 into pymodbus-dev:python3 Nov 20, 2017
@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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants