小编Nik*_*cks的帖子

python3 pySerial TypeError:不支持unicode字符串,请编码为字节:

在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)

arduino pyserial python-3.x

20
推荐指数
3
解决办法
6万
查看次数

标签 统计

arduino ×1

pyserial ×1

python-3.x ×1