Pyfirmata 在创建 arduino 对象后抛出错误

问题描述 投票:0回答:2

我正在尝试启动一个arduino项目,但每次我尝试运行它时都会抛出错误。我想我可能有些设置错误?

我已将标准 Firmata Sketch 上传到 Arduino Mega 并安装了 pyFirmata。我真的想不出我还能做错什么。

请注意,我已经在另一台计算机上尝试过,虽然它并没有真正工作,但电路板已初始化,并且没有抛出任何像这样的错误

这是我的Python代码

import pyfirmata as pf

board = pf.ArduinoMega('COM5')

这是抛出的错误

Traceback (most recent call last):
  File "C:\Users\stiky\Desktop\Code\Python Codes\Arduino\test.py", line 3, in <module>
    board = pf.ArduinoMega('COM5')
            ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\stiky\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyfirmata\__init__.py", line 32, in __init__
    super(ArduinoMega, self).__init__(*args, **kwargs)
  File "C:\Users\stiky\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyfirmata\pyfirmata.py", line 101, in __init__
    self.setup_layout(layout)
  File "C:\Users\stiky\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyfirmata\pyfirmata.py", line 157, in setup_layout
    self._set_default_handlers()
  File "C:\Users\stiky\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyfirmata\pyfirmata.py", line 161, in _set_default_handlers
    self.add_cmd_handler(ANALOG_MESSAGE, self._handle_analog_message)
  File "C:\Users\stiky\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyfirmata\pyfirmata.py", line 185, in add_cmd_handler
    len_args = len(inspect.getargspec(func)[0])
                   ^^^^^^^^^^^^^^^^^^
AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?

我做错了什么?

python arduino python-module pyfirmata
2个回答
0
投票

这可能是 PyFirmata 和你的 Python 版本之间的兼容性问题。

getargspec 自 Python 3.11 起已弃用。

最新的 PyFirmata 版本应该已将其替换为 getfullargspec。

https://github.com/tino/pyFirmata/commit/1f6b116b80172e70c7866d595120413078ae1222

PyFirmata 文档也说

它在 Python 2.7、3.6 和 3.7 上运行。

所以我不一定期望 3.11 运行没有问题。


0
投票

端口错误尝试更改arduino

© www.soinside.com 2019 - 2024. All rights reserved.