This commit is contained in:
2022-06-05 15:56:40 +02:00
parent 8e53b4346b
commit 5405db9e7e
4 changed files with 9 additions and 12 deletions

View File

@@ -28,8 +28,8 @@ if __name__ == "__main__":
verbose = args.verbose verbose = args.verbose
proj = ProjectorSerial() proj = ProjectorSerial(verbose)
extr = ExtronSerial() extr = ExtronSerial(verbose)
if args.input: if args.input:
proj.power_on() proj.power_on()

View File

@@ -36,8 +36,8 @@ class ExtronSerial(SerialDevice):
baudrate = 9600 baudrate = 9600
super().__init__(serial_port, baudrate, verbose) super().__init__(serial_port, baudrate, verbose)
def send_command(self, command: str, verbose: bool = False) -> str: def send_command(self, command: str) -> str:
response = super().send_command(command, verbose) response = super().send_command(command)
if response[0] == "E": if response[0] == "E":
print(response, self.ERRORS.get(response, "Unknown")) print(response, self.ERRORS.get(response, "Unknown"))

View File

@@ -11,14 +11,12 @@ class ProjectorSerial(SerialDevice):
super().__init__(serial_port, baudrate, verbose) super().__init__(serial_port, baudrate, verbose)
def send_command( def send_command(self, command: str, device_id: str = "ZZ") -> str:
self, command: str, verbose: bool = False, device_id: str = "ZZ"
) -> str:
assert device_id in ["01", "02", "03", "04", "05", "06", "ZZ"] assert device_id in ["01", "02", "03", "04", "05", "06", "ZZ"]
full_command = f"\x02AD{device_id};{command}\x03" full_command = f"\x02AD{device_id};{command}\x03"
return super().send_command(full_command, verbose) return super().send_command(full_command)
def power_on(self) -> None: def power_on(self) -> None:
self.send_command("PON") self.send_command("PON")

View File

@@ -10,11 +10,10 @@ class SerialDevice:
self.baudrate = baudrate self.baudrate = baudrate
self.verbose = verbose self.verbose = verbose
def send_command(self, command: str, verbose: bool = False) -> str: def send_command(self, command: str) -> str:
verbose = verbose or self.verbose
with Serial(self.serial_port, self.baudrate, timeout=1) as s: with Serial(self.serial_port, self.baudrate, timeout=1) as s:
if verbose: if self.verbose:
print("Send:", command) print("Send:", command)
s.write(command.encode()) s.write(command.encode())
@@ -30,7 +29,7 @@ class SerialDevice:
else: else:
response = "" response = ""
if verbose: if self.verbose:
print("Resp:", response) print("Resp:", response)
if not response: if not response:
print("No response") print("No response")