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

Supports any serial protocol supported by the serial module #7

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

Governa
Copy link
Contributor

@Governa Governa commented Jul 19, 2019

Usage:

import aioserial
import serial
import asyncio

loop = asyncio.get_event_loop()

serial_port = serial.serial_from_url("aioserial://<device>", loop=loop)
loop_port = serial.serial_from_url("aioserial://test?handler=loop", loop=loop)
alt_port = serial.serial_from_url("aioserial://<device>?handler=alt&class=<class>", loop=loop)
telnet_port = serial.serial_from_url("aioserial://<host>:<port>?handler=rfc2217", loop=loop)

async def test():
   await loop_port.write_async(b"OK\n")
   assert (await loop_port.readline_async()) == b"OK\n"

mrjohannchang and others added 11 commits November 13, 2018 14:49
  Usage:
  import aioserial
  import serial

  port = serial.serial_from_url("aioserial://test?handler=loop")
  port = serial.serial_from_url("aioserial://<device>?handler=alt&class=<class>")
  port = serial.serial_from_url("aioserial://<host>:<port>?handler=rfc2217")
  ...
@mrjohannchang
Copy link
Owner

mrjohannchang commented Jul 29, 2019

Thank for the contribution, @Governa. The idea looks great. Please allow me to take some time digesting the PR.

@Governa
Copy link
Contributor Author

Governa commented Jul 31, 2019

If this helps, I'm going to try explaining the code a bit.

I've tried to change as little as possible. Divided AioSerial in two. The first part, AioSerialMixin, is the old implementation of all methods. The AioSerial is there just so the constructor signature is fully documented and the API doesn't change.

The Mixin class has a generic constructor that extracts the loop parameter and forwards all other parameters to the super class.

The magic is done in protocol_serial.py. Here we find the needed serial class (using code shamelessly stolen from the serial module :) ) and create a new class using the class we found and the AioSerialMixin. The created class is named AioSerial[class name].

And finally, in the module init, we register this module as the handler of "aioserial://" URLs so that by importing aioserial this functionality is already working. This is the part I like the least, as it is a bit magical and inspecting the code, the import may seem not to be used.

@Governa
Copy link
Contributor Author

Governa commented Nov 11, 2019

Now there are conflicting changes in the repository. I could try to fix the conflicts, but only if you think this is mergeable

@skyareyes
Copy link

Hello to everyone,

Following the documentation that states that all of the pyserial's API can be called from your library, can you illustrate a quick example of a RS485 support? https://pyserial.readthedocs.io/en/latest/pyserial_api.html#rs485-support

Repository owner deleted a comment from JGConsulting Mar 15, 2024
Cynerd added a commit to silicon-heaven/pyshv that referenced this pull request Jan 22, 2025
The executor that reads the serial port is not terminated gracefully by
aioserial when close is called and thus it touches some variables set to
`Note` at that point causing `TypeError` to be raised. We handle this as
disconnect because it should happen only on disconnect.

The fix seems to be present in PR
mrjohannchang/aioserial.py#7 but it seems that
development of this project somewhat stalled. We should think about
moving to some alternative if nothing happens in year or two.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants