是否有一个Python函数可以像arduino中的Wire.available函数那样响应,以获取网络上的所有数据,而不必指定要获取的字节数?
这就是我现在所拥有的,它工作得很好,但我必须知道有多少数据即将到来,否则它将提供意想不到的结果。
for i in range(0, 13):
data += chr(bus.read_byte(address));谢谢!
发布于 2013-04-22 12:35:14
这不是一个完美的解决方案,但我找到了一种方法,可以准确地知道有多少字节在处理中。
在Arduino上,我指定了缓冲区的最大大小(128),添加我的数据,然后将其余的清零,然后发送整个内容。在Pi上,我接收整个缓冲区,然后发生的第一件事就是过滤\x00字符。它不是完美的,但它现在是有效的。
for i in range(0, 128):
data += chr(bus.read_byte(address))
print repr(data)
#prints the whole string as it is received
data = filter(lambda a: a != '\x00')
print repr(data)
#prints the string without any '\x00' characters.发布于 2015-04-01 04:08:48
我在raspberrypi上使用PIGPIO库来执行i2c命令,它有更接近线路的函数。
http://abyz.co.uk/rpi/pigpio/python.html#i2c_read_device
我想这就是你要找的函数。
https://stackoverflow.com/questions/16118580
复制相似问题