在python 3中,我导入了pySerial库,因此我可以通过串行命令与我的arduino uno通信,它在python 2.7中工作得非常好但在python 3中我一直遇到错误,它说这个TypeError:不支持unicode字符串,请编码到bytes:'allon'在python 2.7中我唯一不同的是使用raw_input但是我不知道python 3中发生了什么这里是我的代码
import serial, time
import tkinter
import os
def serialcmdw():
os.system('clear')
serialcmd = input("serial command: ")
ser.write (serialcmd)
serialcmdw()
ser = serial.Serial()
os.system('clear')
ser.port = "/dev/cu.usbmodem4321"
ser.baudrate = 9600
ser.open()
time.sleep(1)
serialcmdw()
Run Code Online (Sandbox Code Playgroud)