
A few thoughts from someone who worked with serial ports, parallel ports and USB and covered Linux and Windows for some these. 1. Serial ports are dead 2. UNIX and Windows implementations are fundamentally different. 3. Even within UNIX, there's quite a variety 1. The hardware serial ports still exist on some rare PC motherboards, but it's quite rate to actually use those. Instead, there are a lot of other ports where serial port abstraction can be used, in chronological order: * USB serial dongles * USB devices that integrate a microprocessor that's connected via its serial interface * USB devices that integrate a microprocessor with USB stack that fakes a serial port * Bluetooth devices following the above * Bluetooth devices with modem (acm, not serial port) interface Access to both USB and Bluetooth is done differently now, UMDF for USB, and I think something similar for bluetooth, 2. UNIX APIs are pretty consistent wrt. file descriptor use, even when there are major gotchas in the kernel mode (serial vs tty for example). Windows APIs are frankly all over the place. Their pipes are not the same as pipes, etc. Their UNIX-like APIs only work so far. For a random example, see e.g. https://github.com/microsoft/terminal/issues/262 3. There's classical UNIX, but then there were tons of improvements: Linux got epoll, aio, io_submit... Mac got AsyncBytes and something or other underneath *BSD for something or other, but a bit differently Thus, a "good" asyncio loop implementation is likely to use OS-specific primitives So, where does it leave you? If your aim is to contribute to asyncio, may I suggest that you find another target than serial interfaces. If your aim is to support some specific device -- follow how that device is connected to the machine: ioports? iomem? usb? bt? etc. If your aim is to achieve high-bandwidth or low-latency -- get close to hardware If your aim is to support, let's say 100 ports at once -- one of the two approaches above If I couldn't guess your aim, please explain why `asyncio` in the first place. Cheers, Dima Tisnek On Thu, Sep 1, 2022 at 2:58 AM J.P. Hutchins <jphutchins@gmail.com> wrote:
Greetings!
I would like to modify/replace an existing library, pySerial, to use asyncio in Windows/Mac/Linux. I have a Windows implementation working by "listening for an event" like this:
read_future = loop._proactor.wait_for_handle(overlapped_read.hEvent)
Where overlapped_read is the OVERLAPPED structure (via ctypes or pywin32) and the event is setup previously, e.g. "received chars on the serial port" event here.
My question is in regards to the best practices for awaiting an OS event providing for the most efficient and maintainable implementation. Reference to other multi-platform libraries or builtins that accomplish similar would be appreciated.
Thanks for your time, J.P. Hutchins _______________________________________________ Async-sig mailing list -- async-sig@python.org To unsubscribe send an email to async-sig-leave@python.org https://mail.python.org/mailman3/lists/async-sig.python.org/ Code of Conduct: https://www.python.org/psf/codeofconduct/