working full
This commit is contained in:
parent
70786734bd
commit
7921e4417c
2 changed files with 12 additions and 9 deletions
|
@ -324,12 +324,9 @@ class BenQSmartBoard:
|
||||||
self._ensure_connection()
|
self._ensure_connection()
|
||||||
|
|
||||||
# Protocol format: [length][tv_id][command_type][command_code][value][CR]
|
# Protocol format: [length][tv_id][command_type][command_code][value][CR]
|
||||||
# Example: 801s!000\r where command_code 21(hex) = !(ASCII)
|
# Length includes the length byte itself
|
||||||
# Length includes the length byte itself: 1 + tv_id(2) + command_type(1) + command_code(1) + value(3) = 8
|
|
||||||
if len(command_code) != 2:
|
if len(command_code) != 2:
|
||||||
raise ValueError("command_code must be 2 ASCII chars (hex).")
|
raise ValueError("command_code must be 2 ASCII chars (hex).")
|
||||||
if len(value) != 3:
|
|
||||||
raise ValueError("value must be 3 ASCII chars.")
|
|
||||||
|
|
||||||
# Convert hex command code to ASCII character
|
# Convert hex command code to ASCII character
|
||||||
try:
|
try:
|
||||||
|
@ -338,12 +335,14 @@ class BenQSmartBoard:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError(f"Invalid hex command code: {command_code}")
|
raise ValueError(f"Invalid hex command code: {command_code}")
|
||||||
|
|
||||||
# Length = length_byte(1) + tv_id(2) + command_type(1) + command_code(1) + value(3) = 8 bytes total
|
|
||||||
length_ascii = b'8'
|
|
||||||
tv_id_ascii = b'01'
|
tv_id_ascii = b'01'
|
||||||
command_type_ascii = b's' # Set command is 's'
|
command_type_ascii = b's' # Set command is 's'
|
||||||
value_ascii = value.encode('ascii')
|
value_ascii = value.encode('ascii')
|
||||||
|
|
||||||
|
# Calculate dynamic length: length_byte(1) + tv_id(2) + command_type(1) + command_code(1) + value(variable)
|
||||||
|
total_length = 1 + len(tv_id_ascii) + len(command_type_ascii) + len(command_code_ascii) + len(value_ascii)
|
||||||
|
length_ascii = str(total_length).encode('ascii')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
packet = length_ascii + tv_id_ascii + command_type_ascii + command_code_ascii + value_ascii + self.CR
|
packet = length_ascii + tv_id_ascii + command_type_ascii + command_code_ascii + value_ascii + self.CR
|
||||||
_log_packet("Sent", packet)
|
_log_packet("Sent", packet)
|
||||||
|
@ -378,12 +377,13 @@ class BenQSmartBoard:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError(f"Invalid hex command code: {command_code}")
|
raise ValueError(f"Invalid hex command code: {command_code}")
|
||||||
|
|
||||||
# For get command: length + tv_id + command_type + command_code + CR
|
|
||||||
# Length = length_byte(1) + tv_id(2) + command_type(1) + command_code(1) = 5 bytes total
|
|
||||||
length_ascii = b'5'
|
|
||||||
tv_id_ascii = b'01'
|
tv_id_ascii = b'01'
|
||||||
command_type_ascii = b'g' # Get command is 'g'
|
command_type_ascii = b'g' # Get command is 'g'
|
||||||
|
|
||||||
|
# Calculate dynamic length: length_byte(1) + tv_id(2) + command_type(1) + command_code(1)
|
||||||
|
total_length = 1 + len(tv_id_ascii) + len(command_type_ascii) + len(command_code_ascii)
|
||||||
|
length_ascii = str(total_length).encode('ascii')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.debug(f"Sending get command: code={command_code}")
|
logging.debug(f"Sending get command: code={command_code}")
|
||||||
packet = length_ascii + tv_id_ascii + command_type_ascii + command_code_ascii + self.CR
|
packet = length_ascii + tv_id_ascii + command_type_ascii + command_code_ascii + self.CR
|
||||||
|
|
|
@ -50,6 +50,9 @@ def test_serial_connection():
|
||||||
try:
|
try:
|
||||||
print("Expected packet: 801s!000\\r (where 21 hex = ! ASCII, length=8 includes length byte)")
|
print("Expected packet: 801s!000\\r (where 21 hex = ! ASCII, length=8 includes length byte)")
|
||||||
board.set_power(PowerState.ON)
|
board.set_power(PowerState.ON)
|
||||||
|
time.sleep(2)
|
||||||
|
board.set_volume(20)
|
||||||
|
board.set_video_source(VideoSource.OPS)
|
||||||
print("Power OFF command sent successfully!")
|
print("Power OFF command sent successfully!")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to set power OFF: {e}")
|
print(f"Failed to set power OFF: {e}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue