2016-02-26 123 views
3

在python 3中,我導入了pySerial庫,所以我可以通過串行命令與我的arduino uno進行通信,它在python 2.7中工作得很好,但是在python 3中我保留運行到它說這個錯誤TypeError:unicode字符串不支持,請編碼爲字節:'allon'在python 2.7我唯一不同的是使用raw_input,但我不知道python 3在這裏發生了什麼是我的代碼python3 pySerial TypeError:不支持unicode字符串,請編碼爲字節:

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

回答

8

將您正在寫入串行的數據進行編碼,在您的情況「serialcmd」爲bytes.try fol正在降低:

ser.write(serialcmd.encode())

+0

非常感謝你, –

相關問題