简体   繁体   English

使用 Python 模块 SMBus、Raspberry Pi 的输入/输出错误

[英]Input/output error using Python module SMBus, Raspberry Pi

I have connected a Raspberry Pi and a separate board together with a homemade I²C level shifter, and installed the Python module SMBus, the Raspberry Pi can communicate with the the PiGlow on the other board, but every so often I get an input/output error message when trying the command:我用自制的 I²C 电平转换器将一个 Raspberry Pi 和一个单独的板连接在一起,并安装了 Python 模块 SMBus,Raspberry Pi 可以与另一块板上的 PiGlow 通信,但我经常收到输入/输出错误尝试命令时的消息:

bus.write_i2c_block_data(address, signal, data) bus.write_i2c_block_data(地址,信号,数据)

It says:它说:

IOError: [Errno 5] Input/output error IOError: [Errno 5] 输入/输出错误

I found a work around for it through this post: Input/output error using Python module SMBus, a Raspberry Pi and an Arduino (and this is more or less a follow up to that question)我通过这篇文章找到了解决方法: 使用 Python 模块 SMBus、Raspberry Pi 和 Arduino 的输入/输出错误(这或多或少是该问题的后续)

I currently have try-catch's around the calls that gave me the error like so:我目前有 try-catch 围绕给我这样的错误的调用:

try:
    bus.write_i2c_block_data(address, signal, data)
except IOError:
    subprocess.call(['i2cdetect', '-y', '1'])

which works perfectly fine to work around the i/o errors.它可以很好地解决 i/o 错误。 My problem is, due to all the try-catch's, the code seems to run significantly slower.我的问题是,由于所有的 try-catch,代码的运行速度似乎要慢得多。 I was wondering if there was another known work around of if there was a more efficient way to do this.我想知道是否有另一种已知的解决方法,是否有更有效的方法来做到这一点。 Any help would be appreciated!任何帮助,将不胜感激!

Thanks谢谢

Do you call Serial.print or similar in the reception interrupt handler of your separate board ?您是否在separate board的接收中断处理程序中调用Serial.print或类似方法? If yes, it may be the problem.如果是,则可能是问题所在。 On an Arduino , for example, one should avoid calling Serial.xxx functions inside an interruption.例如,在Arduino ,应该避免在中断内调用Serial.xxx函数。

Removing Serial.print lines on Arduino solved the problem for me.删除 Arduino 上的Serial.print行为我解决了这个问题。

Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM