巫山雨_fz 2021-11-23 18:43 采纳率: 74.1%
浏览 45
已结题

Win10系统使用Usb转GPIO模块,Python导入Pygpio调用报错

我的代码如下
import sys
from sys import argv,exit
from pygpio import *

IN1 = 1
def setup_gpio():
BaseGPIO.setup(IN1, OUT)

if name == 'main':
app = QApplication(sys.argv)
setup_gpio()
sys.exit(app.exec_())
出现如下报错
File "D:\lpcj\Qt-Camera\lpcj3.py", line 166, in setup_gpio
BaseGPIO.setup(IN1, OUT)

setup() missing positional argument:'mode'

打开pygpio目录下的gpio.py文件,有如下内容
import Adafruit_GPIO.Platform as Platform

OUT = 0
IN = 1
HIGH = True
LOW = False

RISING = 1
FALLING = 2
BOTH = 3

PUD_OFF = 0
PUD_DOWN = 1
PUD_UP = 2
class BaseGPIO(object):
"""Base class for implementing simple digital IO for a platform.
Implementors are expected to subclass from this and provide an implementation
of the setup, output, and input functions."""

def setup(self,pin,mode,pull_up_down=PUD_OFF):
    """Set the input or output mode for a specified pin.  Mode should be
    either OUT or IN."""
    raise NotImplementedError

这个setup()里的第一个参数为什么是self,怎么赋值,我的pin是IN1,mode是OUT,为什么说我缺少mode参数?

  • 写回答

1条回答 默认 最新

  • soar3033 2021-11-23 19:10
    关注

    self不需要你赋值 那是代表类实例本身的
    你不应该调用BaseGPIO 你应该调用RPiGPIOAdapter

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月29日
  • 已采纳回答 11月24日
  • 创建了问题 11月23日

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失