我有一台NEC PX-42VM5HA等离子电视,我试图用连接的电脑控制。我有数据表,显示控制电视和协议信息的所有代码。我不确定如何在python中构建正确的数据结构来发送HEX控制代码。以下是电源控制代码和通信协议。
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
这是我到目前为止的代码:
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()
答案 0 :(得分:5)
将控制代码写为字符串
ON = "\x9f\x80\x60\x4e\x00\xcd"
ser.write(ON)