【问题标题】:linux usb-hid :add libhid library to eclipse(C++) or netbeans IDEs or native input.h or hiddev.h?linux usb-hid:将 libhid 库添加到 eclipse(C++) 或 netbeans IDE 或本机 input.h 或 hiddev.h?
【发布时间】:2009-08-24 05:30:57
【问题描述】:

我对 libhid 有疑问。

我发现有 2 种方式 4 访问 linux 中的 usb-hid

1)linux 默认库,如 input.hhiddev.h 和 ...

2) 使用 libhid

我发现 libhid 有些令人困惑并尝试使用 input.h 但我对那个 2 有疑问。

我不知道如何从 ubuntu 获取有关我的设备的信息

我使用open()打开设备

str="/dev/inpt/eventX" \\where X=0,1,...,7(I'm not sure about this)
open(str,O_RDWR)

然后使用 ioctl 获取信息

ioctl(fd,EVIOCGVERSION,&version);

但它给了我错误的供应商和产品 ID

那么 我尝试使用 libhid,但知道如何在 eclipse 或 netbeans 中使用 libhid(或任何其他库)

您能告诉我您是如何在任何 IDE(如 eclipse 或 netbeans)或仅使用终端和 gcc 编译代码的吗? 要么 如何使用 ioctl() 和 open() ?

我的整个示例代码:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ftw.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <asm/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
#include <linux/input.h>
#include <strings.h>


struct input_devinfo
{
        uint16_t bustype;
        uint16_t vendor;
        uint16_t product;
        uint16_t version;
};


int main(void) {
    //puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
    //usb_device ud;
    //int i=0;
    //string str;
    //str=char[100];
    //str="/dev/input/event0\n";

    printf("------------- start -----------------\n");
    char str[]="" ;
    int version=0;
    char c[16];
    char t;
    int i,fd;
    //for (i=0 ; i<8 ; i++)
    {
        //strcpy(c,str);
        //t=i-'0';
        //printf("salam5\n");
        //c[15]=t;

        //openning
        //open(str,O_RDONLY);//read and write
        if ((fd = open(str,O_RDWR)) < 0)
            perror("str open\n");
        else
            printf("%s opened successfully\n",str);


        ioctl(fd,EVIOCGVERSION,&version);
        printf("version = %d \n",version);
        printf("evdev driver version is %d.%d.%d\n",version >> 16, (version >> 8) & 0xff, version & 0xff);

        //geting info from device
        struct input_devinfo device_info;
        ioctl(fd,EVIOCGID,&device_info);
        printf("vendor 0x%04hx product 0x%04hx version 0x%04hx is on ?",
            device_info.vendor, device_info.product,
            device_info.version);
    }



    return EXIT_SUCCESS;
}

【问题讨论】:

    标签: eclipse netbeans linux-device-driver libusb hid-device


    【解决方案1】:

    我找到了在 eclipse 中编译我的代码的方法

    1 个问题已解决

    要在终端中使用 GCC 编译代码,您应该通过在命令中添加“-lhid”来为 GCC 定义 libhid: gcc test_libhid.c -lhid

    如果你使用 eclipse 并且你想使用 libhid,你应该添加“-lhid”到 gcc 链接器,以便 gcc 在编译你的代码时可以使用 libhid 请按照以下步骤操作:

    1)在项目资源管理器面板上,右击您的项目选择属性(最后一个选项) 或选择您的项目并按 Alt+Enter

    2)在左侧面板中展开“c/c++ build”并选择“setting”

    3)在右侧选择“工具设置”选项卡

    4) 你应该在那里看到 GCC C 编译器和 GCC C 链接器和 GCC 汇编器。 展开 GCC C 链接器并选择库

    5)在右侧选择后,您应该会看到 2 个框:Libraries(-l) 和 Library search path(-L) 在库(-l)中添加“隐藏”

    注意:当您执行此步骤时,eclipse 使用 GCC 编译您的代码 eclipse 将“-lhid”参数添加到 gcc 以使其能够识别 libhid。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      相关资源
      最近更新 更多