无法在Adafruit FT232H上使用gpiod_line_request_output访问gpio行

问题描述

我正在使用Adafruit Ft232H分组接口向我的Linux PC添加GPIO端口。尽管我在用libftdi和bitbang模式闪烁发光二极管方面取得了一些成功,但我却没有像libgpiod那样幸运,因为gpiod_line_request_output失败了。

我的系统的某些gpio信息:

sudo gpiodetect
gpiochip0 [ftdi-cbus] (4 lines)

sudo gpioinfo
gpiochip0 - 4 lines:
        line   0:      unnamed       unused   input  active-high 
        line   1:      unnamed       unused   input  active-high 
        line   2:      unnamed       unused   input  active-high 
        line   3:      unnamed       unused   input  active-high

这是试图访问第0行的C程序。

#include <stdio.h>
#include <stdlib.h>

#include <gpiod.h>

#define LINE_NUM 0

void gpio_fatal(struct gpiod_chip* chip,const char msg[20]);

int main(int argc,char** argv)
{
    struct gpiod_chip*  chip;
    struct gpiod_line*  line;
    const char path[] = "/dev/gpiochip0";

    chip = gpiod_chip_open(path);
    if(!chip)
    {
        fprintf(stderr,"Error opening path\n");
        return EXIT_FAILURE;
    }

    line = gpiod_chip_get_line(chip,LINE_NUM);
    if(!line)
    {
        fprintf(stderr,"error getting this line\n");
        return EXIT_FAILURE;
    }

    int ret = gpiod_line_request_output(line,"ftdi-cbus",1);
    if(ret != 0)
        gpio_fatal(chip,"Request output failed");

    for(;;)
    {
        gpiod_line_set_value(line,1);
        printf("On\n");
        sleep(1);
        gpiod_line_set_value(line,0);
        printf("Off\n");
        sleep(1);
    }

    gpiod_line_release(line);
    gpiod_chip_close(chip);

    return EXIT_SUCCESS;
}

void gpio_fatal(struct gpiod_chip* chip,const char* msg)
{
    fprintf(stderr,"%s\n",msg);
    gpiod_chip_close(chip);
    exit(EXIT_FAILURE);
}

使用sudo运行可执行文件会给我:

sudo g_gpiod/build/g_gpiod 
Password: 
Request output failed

gpiod.h针对失败的功能指出以下内容:

/**
 * @brief Reserve a single line,set the direction to output.
 * @param line GPIO line object.
 * @param consumer Name of the consumer.
 * @param default_val Initial line value.
 * @return 0 if the line was properly reserved,-1 on failure.
 */
int gpiod_line_request_output(struct gpiod_line *line,const char *consumer,int default_val) GPIOD_API;

参数似乎正确,这可能是由于什么原因导致的?使用libftdiCircuitPython的其他示例可以访问端口并正常工作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...