linux usb hid:将libhid库添加到eclipse(C++)或netbeans IDE或本机input.h或hiddev.h?
我对利希德有意见 我发现在linux中有两种方式4访问usb hid 1linux默认库,如input.h和hiddev.h以及 2使用libhid 我发现libhid有些混乱,并尝试使用input.h,但我对这2有问题 我不知道如何从ubuntu获取有关我的设备的信息 我使用open打开设备linux usb hid:将libhid库添加到eclipse(C++)或netbeans IDE或本机input.h或hiddev.h?,eclipse,netbeans,linux-device-driver,libusb,hid-device,Eclipse,Netbeans,Linux Device Driver,Libusb,Hid Device,我对利希德有意见 我发现在linux中有两种方式4访问usb hid 1linux默认库,如input.h和hiddev.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获取信息 io
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)或仅使用terminal和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中编译代码的方法 1问题解决 要在terminal中使用GCC编译代码,您应该通过在命令中添加-lhid来为GCC定义libhid: gcc测试(libhid.c)-lhid 如果您正在使用eclipse,并且希望使用libhid,那么应该将-lhid添加到gcc链接器中,以便gcc在编译代码时可以使用libhid 按照以下步骤操作: 1在“项目资源管理器”面板上,右键单击项目“最后选择属性”选项 或者选择项目并按Alt+Enter键 2在左侧面板中展开c/c++构建并选择设置 3在右侧选择刀具设置选项卡 4您应该在这里看到GCC编译器、GCC链接器和GCC汇编程序。 展开GCC链接器并选择库 5在右侧选择后,您将看到两个框:Libraries-l和Library search path-l 在库中-l添加hid 注意:当您执行以下步骤时,eclipse使用GCC编译您的代码:eclipse向GCC添加-lhid参数以使其能够识别libhid