我正在尝试使用Python从Arduino读取序列值。
>>> ser.read()
'2'
>>> a = ser.readLine()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Serial' object has no attribute 'readLine'
为什么我在readLine中出错,而read()却没有?或者阅读(10)?
我正在使用的完整代码:
>>> import serial
>>> ser = serial.Serial('/dev/tty.usbmodem1411', 9600, timeout=10)
>>> ser.read()
'\n'
>>> ser.readLine()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Serial' object has no attribute 'readLine'
>>> ser.read()
'2'
>>> ser.readLine()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Serial' object has no attribute 'readLine'
答案 0 :(得分:2)
感谢@Goyo指出我的愚蠢错误。
.readLine()不是方法,但.readline()是。糟糕。
>>> ser = serial.Serial('/dev/tty.usbmodem1411', 9600)
>>> ser.readline()
'2456.05\r\n'