Files
License_plate_recognition/simple_client.py
2025-10-18 16:05:39 +08:00

53 lines
1.4 KiB
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.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单的UDP客户端程序
向Hi3861设备发送JSON命令
"""
import socket
import json
import time
def send_command():
"""发送命令到Hi3861设备"""
# 目标设备信息
target_ip = "192.168.43.12"
target_port = 8081
# 创建JSON命令
command = {
"cmd": 1, # 测试命令4只显示字符串舵机不动
"text": "沪AAAAAA 通行 2sec"
}
json_command = json.dumps(command, ensure_ascii=False)
try:
# 创建UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 发送命令
print(f"正在向 {target_ip}:{target_port} 发送命令...")
print(f"命令内容: {json_command}")
sock.sendto(json_command.encode('utf-8'), (target_ip, target_port))
print("命令发送成功!")
print("设备将执行以下操作:")
print("1. 顺时针旋转舵机90度")
print("2. 在OLED屏幕上显示沪AAAAAA")
print("3. 等待10秒")
print("4. 逆时针旋转舵机90度")
print("5. 清空OLED屏幕")
except Exception as e:
print(f"发送命令失败: {e}")
finally:
sock.close()
if __name__ == "__main__":
print("Hi3861 简单客户端程序")
print("=" * 30)
send_command()
print("程序结束")