Python script Optoma UHD40
Posted: Monday 11 May 2020 22:22
hello, here is my simple script to control on/off my optoma projector UHD40 (RS232)
but should work on other models too... (tested on raspberry with USB serail convertor)
but should work on other models too... (tested on raspberry with USB serail convertor)
Code: Select all
#!/usr/bin/env python3
import time
import serial
import sys
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout = 1,
xonxoff = False,
rtscts = False,
dsrdtr = False,
writeTimeout = 2
)
command_off = "~0000 0\r"
command_on = "~0000 1\r"
# command = "~00352 1"
def send_command(command_):
print ('Connection is %s' % ('open' if ser.isOpen() else 'closed'))
ser.write(str(command_).encode())
if ser.isOpen():
ser.flushInput()
ser.flushOutput()
ser.write(str(command_).encode())
time.sleep(0.1)
while True:
line = ser.readline()
if line:
print (line.decode('utf-8'))
break
ser.close()
try:
command = sys.argv[1]
except:
print("no input")
command = ''
if command == 'ON':
send_command(command_on)
print ('Optoma ON')
elif command == 'OFF':
send_command(command_off)
print ('Optoma OFF')
else:
print ('Wrong command')