forked from rsnodgrass/pyxantech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-async.py
More file actions
executable file
·87 lines (66 loc) · 2.1 KB
/
example-async.py
File metadata and controls
executable file
·87 lines (66 loc) · 2.1 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /usr/local/bin/python3
#
# Running:
# ./example-async.py --help
# ./example-async.py --tty /dev/tty.usbserial-A501SGSZ
import logging
import argparse
import asyncio
import sys
from pyxantech import async_get_amp_controller
####----------------------------------------
LOG = logging.getLogger()
LOG.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)
LOG.addHandler(handler)
####----------------------------------------
parser = argparse.ArgumentParser(
description="Xantech RS232 client example (asynchronous)"
)
parser.add_argument(
"--tty", help="/dev/tty to use (e.g. /dev/tty.usbserial-A501SGSZ)", required=True
)
parser.add_argument(
"--model", default="xantech8", help=f"model (e.g. xantech8, monoprice6)"
)
parser.add_argument(
"--baud",
type=int,
default=9600,
help="baud rate (9600, 14400, 19200, 38400, 57600, 115200)",
)
args = parser.parse_args()
serial_config = {"baudrate": args.baud}
async def main():
zone = 1
amp = await async_get_amp_controller(
args.model,
args.tty,
asyncio.get_event_loop(),
serial_config_overrides=serial_config,
)
await amp.all_off()
# print(f"Xantech amp version = {await amp.sendCommand('version')}")
for zone in range(1, 8):
await asyncio.sleep(0.5)
await amp.set_power(zone, True)
await asyncio.sleep(0.5)
await amp.set_source(zone, 1)
await amp.set_mute(zone, False)
status = await amp.zone_status(zone)
print(f"Zone {zone} status: {status}")
# ensure all zones are turned off
# for zone in range(1, 8):
# await amp.set_power(zone, False)
await amp.all_off()
exit()
# Valid zones are 11-16 for main xantech amplifier
# zone_status = await amp.zone_status(zone)
# Set balance for zone #11
# amp.set_balance(zone, 3)
# Restore zone #11 to it's original state
# amp.restore_zone(zone_status.dict)
asyncio.run(main())