sdk明文協議
#以下為教學程式 #改自https://robomaster-dev.readthedocs.io/zh_TW/latest/text_sdk/intro.html import socket import sys host = "192.168.2.1" port = 40923 address = (host, int(port)) # 與機器人控制命令建立 TCP 連接 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print("Connecting...") s.connect(address) print("Connected!") while True: # 等待用戶輸入控制指令 msg = input(">>> please input SDK cmd: ") # 當用戶輸入 Q 或 q 時,退出當前程序 if msg.upper() == 'Q': break # 添加結束符 msg += ';' # 發送控制命令給機器人 s.send(msg.encode('utf-8')) try: # 等待機器人返回執行結果 buf = s.recv(1024) print(buf.decode('utf-8')) except socket.error as e: print("Error receiving :", e) sys.exit(1) if not len(buf): break # 關閉port連接 s.shutdown(socket.SHUT_WR) s.close() #明文協議https://robomaster-dev.readthedocs.io/zh_TW/latest/text_sdk/protocol_api.html
沒有留言:
張貼留言