18 lines
528 B
Python
18 lines
528 B
Python
# -*- 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)
|
|
|