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

Consider Adding Support For loop:// #34

Open
kb1lqc opened this issue Mar 29, 2018 · 0 comments
Open

Consider Adding Support For loop:// #34

kb1lqc opened this issue Mar 29, 2018 · 0 comments

Comments

@kb1lqc
Copy link

kb1lqc commented Mar 29, 2018

Per Pyserial URL Handlers documentation it's useful to have a loop:// handler. In unit testing I've used this extensively for simple testing. This avoids having to setup a TCP socket server as done in #1 .

Would it be possible to better support this? My hunch is this has something to do with how pyserial handles the loop:// functionality and it may not work well with asyncio.

Tests

Running the base pyserial-asyncio boilerplate code with loop:// shown below:

    loop = asyncio.get_event_loop()
    coro = serial_asyncio.create_serial_connection(loop, faraday.Output, 'loop://', baudrate=115200)
    loop.run_until_complete(coro)
    loop.run_forever()
    loop.close()

Results in the following output which is missing the "Hello, world" text that is expected (using pytest):

(.venv) bryce@bryce-ubuntu:~/Documents/git/faradayio$ sudo .venv/bin/python3 -m pytest -sk serialAsyncio
============================= test session starts ==============================
platform linux -- Python 3.5.2, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /home/bryce/Documents/git/faradayio, inifile:
plugins: cov-2.5.1
collecting 34 items                                                            WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
collected 39 items                                                             

tests/test_serial.py port opened SerialTransport(<_UnixSelectorEventLoop running=True closed=False debug=False>, <faradayio.faraday.Output object at 0x7f571ca91b00>, Serial<id=0x7f571ca91b38, open=True>(port='loop://', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False))
port closed
.

============================= 38 tests deselected ==============================
=================== 1 passed, 38 deselected in 0.38 seconds ====================

Yet the same code using a loopback hardware serial device on /dev/ttyUSB0 results in:

=================== 1 passed, 38 deselected in 0.40 seconds ====================
(.venv) bryce@bryce-ubuntu:~/Documents/git/faradayio$ sudo .venv/bin/python3 -m pytest -sk serialAsyncio
============================= test session starts ==============================
platform linux -- Python 3.5.2, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /home/bryce/Documents/git/faradayio, inifile:
plugins: cov-2.5.1
collecting 34 items                                                            WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
collected 39 items                                                             

tests/test_serial.py port opened SerialTransport(<_UnixSelectorEventLoop running=True closed=False debug=False>, <faradayio.faraday.Output object at 0x7ff7bcb159e8>, Serial<id=0x7ff7c248c6a0, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False))
data received b'Hello, World!\n'
port closed
.

============================= 38 tests deselected ==============================
=================== 1 passed, 38 deselected in 0.38 seconds ====================
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

No branches or pull requests

1 participant