tests: support windows#84
Conversation
|
I have confirmed the small unit test with two USB UARTs on Windows 10. |
|
OK, I think I see that |
|
The following is working for me in serialwin32.py: Setup listener for EV_TXEMPTY in win32.SetCommMask(self._port_handle, win32.EV_ERR | win32.EV_TXEMPTY)And replace if self.out_waiting == 0:
return
EvtMask = win32.DWORD(0)
while (EvtMask.value & win32.EV_TXEMPTY) != win32.EV_TXEMPTY:
win32.WaitCommEvent(self._port_handle, ctypes.byref(EvtMask), ctypes.byref(self._overlapped_write)) |
|
OK, combined with the modification above we can create an awaitable Future by listening for the Windows event. async def write_complete(self):
await self._write_complete_future
async def send(self, data):
self._register_write_complete()
self.write(data)
await self.write_complete()
def _register_write_complete(self):
if platform.system() == "Windows":
self._write_complete_future = self.loop._proactor.wait_for_handle(self._serial._overlapped_write.hEvent) And with that we have a serial I think I will move along to PR pyserial instead since it should support asyncio directly. |
More of a question than a PR. I have used the tool com0com-2.2.2.0 to create a pair of virtual com ports and do the loopback test provided in the tests module. Tomorrow I will test with a pair of FTDI USB adapters and report back.
I am currently working on a project that must run under Windows - I would love to help get this fully supported. I do not understand the note here since the tests pass:
pyserial-asyncio/serial_asyncio/__init__.py
Lines 13 to 16 in 6e1baf2
Perhaps this is a good place for me to start?
Regarding flush (in regular pyserial), I'm not sure that I understand this comment:
https://github.com/pyserial/pyserial/blob/31fa4807d73ed4eb9891a88a15817b439c4eea2d/serial/serialwin32.py#L345-L349
My reading of the documentation is that
lpEvtMaskis a 16-bit value so we could listen to all, for example 0xffff and in this function just mask for 0x0004 to check if the buffer is empty. I don't have much experience with these Windows APIs but my hope would be thatWaitCommEventblocks until an event occurs and that it would avoid the busy loop altogether.Regardless of the number of events listened for it would look something like:
Very excited to learn more!