2015-08-22 47 views
0

在做树莓派串行编程和我的代码是:错误而使用python

import serial 
s="Hello" 
a=serial.Serial('/dev/ttyAMA0',9600) 
while True: 
    a.write(s) 

错误:

TypeError: 'str' does not support the buffer interface 

回答

0

修复此行:

a.write(s) 

带:

a.write(s.encode()) 
+0

但我不想编码它,我只是想将pi数据传输到我的PC终端 – user5241812

+0

如果是Python 3,则必须将字符串编码为字节,因为字节是唯一可以通过串行连接传输的东西。 – BlackJack