-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-async.py
executable file
·50 lines (37 loc) · 1.27 KB
/
example-async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/local/bin/python3
import os
import sys
import pprint
import argparse
import asyncio
import logging
from anthemav_serial import get_async_amp_controller
#### Logging
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
####
parser = argparse.ArgumentParser(description='Anthem RS232 client example')
parser.add_argument('--series', default='d2v', help='Anthem amplifier series to test')
parser.add_argument('--tty', help='/dev/tty to use (e.g. /dev/tty.usbserial-A501SGSZ)')
parser.add_argument('--baud', help='baud rate')
args = parser.parse_args()
pp = pprint.PrettyPrinter(indent=4)
config = {}
if args.baud:
config['baudrate'] = args.baud
async def main(loop):
amp = await get_async_amp_controller(args.series, args.tty, loop, serial_config_overrides=config)
pp.pprint(amp)
await amp.set_power(2, True)
# show amp status
for zone in range(1, 4):
result = await amp.zone_status(zone)
pp.pprint(result)
await amp.set_power(zone, False)
loop = asyncio.get_event_loop()
loop.run_until_complete( main(loop) )