I have an NEC PX-42VM5HA plasma tv that I am trying to control with the connected computer. I have the data sheet that shows all the codes to control the tv and the protocol information. I am unsure how to build the right data structure in python to send the HEX control codes. Below is the Power Control Codes and the Communications Protocol.
Communication Protocol:
Interface: RS-232C
Communication: Asynchronous
Baud Rate: 9600
Data Length: 8bits
Parity: Odd
Stop Bit: 1bit
Communication Code: Hex
Power Control Codes
ON 9FH 80H 60H 4EH 00H CDH
OFF 9FH 80H 60H 4FH 00H CEH
Here is the code I have so far:
import time
import serial
ser = serial.Serial(
port='COM1',
baudrate=9600,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.close()
ser.open()
ser.isOpen()
ON=bytearray([0x9FH,0x80H,0x60H,0x4EH,0x00H,0xCDH])
OFF=bytearray([0x9FH,0x80H,0x60H,0x4FH,0x00H,0xCEH])
ser.write(OFF)
time.sleep(30)
ser.write(ON)
ser.close()