Files
cjgc_data/test/control.py
2026-03-12 17:03:56 +08:00

24 lines
516 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import socket
from protocol import build_frame
SERVER_IP = '127.0.0.1'
SERVER_PORT = 9000
TARGET_DEVICE = 10000052
# 控制 2、3 开5 关
payload = bytes([
0x02, 0x01,
0x03, 0x01,
0x05, 0x00
])
frame = build_frame(0xA0, TARGET_DEVICE, payload)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((SERVER_IP, SERVER_PORT))
# CTRL + device_id + frame
msg = b'CTRL' + TARGET_DEVICE.to_bytes(4, 'little') + frame
s.sendall(msg)
print("[CONTROL] send command")