在Python 3中,我导入了pySerial库以便通过串行命令与我的Arduino Uno通信。
在Python 2.7中它运行得很好,但是在Python 3中,我不断遇到一个错误,它说:
在Python 2.7中它运行得很好,但是在Python 3中,我不断遇到一个错误,它说:
TypeError: Unicode字符串不受支持,请编码为字节:'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()