ا سلام
من تو برنامه نويسي دراور usb-hid تحت لينوکس با مشکل مواجه شدم .
توضيح :
من ۲ راه واسه اين کار پيدا کردم
۱ - استفاده از کتابخانه هاي خود لينوکس مثل input.h و hiddev.
۲- استفاده از کتابخونه ي opensource به نام libhid یا libusb
کد من در روش اول :
#include <stdio.h>
#include <fcntl.h>
#include <linux/input.h>
#include <hid.h>
struct input_devinfo
{
uint16_t bustype;
uint16_t vendor;
uint16_t product;
uint16_t version;
};
int main(void) {
printf("------------- start -----------------\n");
char str[]="/dev/input/event0" ;// /dev/usb/hiddev0 tested
int fd,version=0;
if ((fd = open(str,O_RDONLY)) < 0)
perror("str open error\n");
else
printf("%s opened successfully\n",str);
//geting device version
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 more 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;
}
تو راه اول مشکلم اينه که از تابع open() استفاده ميکنم و آدرس "/dev/input/eventX" يا "/dev/usb/hiddevX" رو بهش ميدم
سپس از تابع ioctl() براي گرفتن اطلاعات مربوط به vendr ID و غيره استفاده ميکنم ولي جوابي که مي گيرم اشتباس
کجاي کارم اشتباس
تو راه دوم مشکلم اينه که نميدونم چطور ميشه libhid رو به eclipse يا netbeans اضافه کرد و باهاشون کد زد.
من با C++ کد ميزنم تو eclipse
متشکر و ممنون ميشم اگه کمکم کنيد.
مرسي.
سلام
من فهمیدم چطوری میشه libhid رو به eclipse و netbeans اضافه کرد.
روشو پایین نوشتم:
>>to compile your code with GCC in terminal you should define libhid for GCC by adding "-lhid" to your command :
gcc test_libhid.c -lhid
>>if your using eclipse and you want to use libhid with it you should add "-lhid" to gcc linker in order to gcc could use libhid when its compiling your code
follow the steps:
1)on the project Explorer panel , R-click on your project select propertise (last option)
or select your project and press Alt+Enter
2)in the left panel expand "c/c++ build" and select "setting"
3)in the right side select "tool setting" tab
4)you should see GCC C compiler and GCC C linker and GCC assembler in there .
expand GCC C linker and select Libraries
5)after selecting in the right side you should see 2 boxes: Libraries(-l) and Library search path(-L)
int the Libraries(-l) add "hid"
note:eclipse use GCC to compile your codes when you do this steps eclipse add "-lhid" parameter to gcc to able it recognizing the libhid.
[/left]