mirror of
https://github.com/lowobservable/coax.git
synced 2026-02-27 09:28:56 +00:00
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
import sys
|
|
import time
|
|
import os
|
|
from contextlib import contextmanager
|
|
|
|
sys.path.append('..')
|
|
|
|
from coax import open_serial_interface, Poll, PollAck
|
|
|
|
DEFAULT_SERIAL_PORT = '/dev/ttyACM0'
|
|
|
|
@contextmanager
|
|
def open_example_serial_interface(reset=True, poll_flush=True):
|
|
serial_port = os.environ.get('COAX_PORT', DEFAULT_SERIAL_PORT)
|
|
|
|
print(f'Opening {serial_port}...')
|
|
|
|
with open_serial_interface(serial_port, reset=False) as interface:
|
|
if reset:
|
|
print('Resetting interface...')
|
|
|
|
interface.reset()
|
|
|
|
if interface.legacy_firmware_detected:
|
|
print(f'Firmware version is {interface.legacy_firmware_version}')
|
|
|
|
if poll_flush:
|
|
print('POLLing...')
|
|
|
|
count = 0
|
|
|
|
poll_response = interface.execute(Poll(), timeout=1)
|
|
|
|
while poll_response:
|
|
interface.execute(PollAck())
|
|
|
|
count += 1
|
|
|
|
poll_response = interface.execute(Poll(), timeout=1)
|
|
|
|
print(f'ACK\'d {count} POLL responses')
|
|
|
|
yield interface
|