"""合成PJLink记录，不连接设备；CR明确保留。"""
import re

command = b"%1POWR 1\r"
query = b"%1POWR ?\r"
responses = [b"%1POWR=OK\r", b"%1POWR=3\r", b"%1POWR=1\r"]
assert command.hex(" ") == "25 31 50 4f 57 52 20 31 0d"
assert query.hex(" ") == "25 31 50 4f 57 52 20 3f 0d"
pattern = re.compile(rb"%1POWR=(OK|[0-3]|ERR[1-4])\r")
states = []
for response in responses:
    match = pattern.fullmatch(response)
    assert match
    states.append(match[1].decode("ascii"))
    print(repr(response))
assert states == ["OK", "3", "1"]
assert pattern.fullmatch(b"%1POWR=OK\n") is None
assert pattern.fullmatch(b"%1POWR=9\r") is None
print("命令已接受；状态：预热→开机；现场画面未核实。")
