#!/usr/bin/env python # -*- coding: utf-8 -*- ''' # @Time : 2025/2/14 14:44 # @Author : hjw # @File : send_target.py ''' import socket import json cmd_set_target = { # 称量 "command": "set_target", "payload": { "target_weight": 200, "algorithm": "pid" } } cmd_get_weight = { # 获取重量 "command": "get_weight" # "payload": { # "target_weight": 200, # "algorithm": "pid" # } } cmd_set_zero = { # 去皮 "command": "set_zero" # "payload": { # "target_weight": 200, # "algorithm": "pid" # } } cmd_set_vibrate = { # 振动控制 "command": "set_vibrate", "payload": { "time": 0 # 单位S } } with socket.socket() as s: s.connect(('127.0.0.1', 5000)) s.send(json.dumps(cmd_set_target).encode()) print(s.recv(1024).decode())