MCU/CODE/Python/Motor/Motor_0417.py

18 lines
528 B
Python
Raw Permalink Normal View History

2024-04-19 11:11:09 +08:00
# -*- coding: UTF-8 -*-
import serial, time
import sys
print(sys.getfilesystemencoding())
#port = '/dev/ttyTHS0'
port = 'COM4'
#ser = serial.Serial(port, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1)
ser = serial.Serial("COM4",115200,bytesize=8, parity='N', stopbits=1, timeout=1)
time.sleep(2)
while True:
# 向串口发送数据
command = "move_36" # 发送给Arduino的命令
ser.write(command.encode()) # 将命令转换为字节并发送到串口
print(ser.readline())
time.sleep(2)