-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_serial.py
More file actions
executable file
·51 lines (41 loc) · 1.47 KB
/
test_serial.py
File metadata and controls
executable file
·51 lines (41 loc) · 1.47 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
#!/usr/bin/env python3
import argparse
import asyncio
import epson_projector as epson
from epson_projector.const import (POWER, PWR_ON, PWR_OFF)
import logging
_LOGGER = logging.getLogger(__name__)
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
_LOGGER.addHandler(console_handler)
_LOGGER.setLevel(logging.DEBUG)
logging.basicConfig(level=logging.DEBUG)
async def main_serial(args):
"""Run main with serial connection."""
projector = epson.Projector(host=args.serial_url,
type='serial',
timeout_scale=2.0)
data = await projector.get_power()
print(data)
cmd = None
if data == '01':
cmd = PWR_OFF
elif data == '00':
cmd = PWR_ON
if cmd:
data2 = await projector.send_command(cmd)
print(data2)
serialno = await projector.get_serial_number()
print("Projector serial number:", serialno)
projector.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Example/test application for Epson Projector package through serial connection."
)
parser.add_argument(
"serial_url",
help="Can be a devicename like /dev/ttyUSB0 or COM3 for real serial port or use socket://<ip-or-host>:<port> for connections to tcp-to-serial solutions.",
)
args = parser.parse_args()
asyncio.run(main_serial(args))