LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-16-2004, 05:10 AM   #1
njel
LQ Newbie
 
Registered: Jul 2004
Posts: 3

Rep: Reputation: 0
How i can write to device /dev/usb/hiddev0 ?


Hivoo. Help me with little little question.

I trying to connect my USB keyboard and write data, but....



something like that....
//---------------------------------------------------//
char * dev = "/dev/usb/hiddev0"; /// or char * dev = "/proc/bus/usb/003/001";
fd = open(dev, O_RDWR|O_NONBLOCK))

// and now i try write to fd

unsigned char outbuff[USB_BUFFSIZE];
int bytes = write(fd,&outbuff,USB_BUFFSIZE);

// but bytes returned -1 and errno returned EINVAL.

WHY????? HELP PLEASE!!! ANYBODY HELP elsewhere i did my SUICIDE!
 
Old 07-23-2004, 12:43 AM   #2
Nightbird
LQ Newbie
 
Registered: May 2004
Posts: 7

Rep: Reputation: 0
ok odds are that your usb keyboard needs initialization. It may need you to send it some configuration string that turns the device online. Read in the manual search online, etc for your brand of keyboard and programming related to it. Also a possiblity is that, you need to talk through the ioctl() function. THis is the case with the HID that i am working on. I will try to help you with that once i have cracked through that problem.

-nightbird
 
Old 08-17-2004, 03:16 AM   #3
bast
LQ Newbie
 
Registered: Jul 2004
Posts: 2

Rep: Reputation: 0
usb hid for linux

Hi,
We are working on the same project... so give me your email
I would like to read and write informations (just some bytes) with USB.
(For information my device is a pic which works in low speed in interrupt transfer .)
That works properly under windows...
And now reading from device is succeful under linus-2.4.20.

First, I 'd like to know if hid is the only driver for my device?
Secondly how do I use the libusb? where can I find it?

I use the file /dev/usb/hiddev0.
Here is your program:

typedef struct {
unsigned hid;
signed int value;
} hiddev_event;

main(){
ssize_t bytesread;
int FILEDES;
hiddev_event *buffer;

buffer=(hiddev_event *)malloc(sizeof(hiddev_event));

FILEDES=open("/dev/usb/hiddev0",O_RDONLY);

bytesread=1;
while(bytesread>0){
bytesread=read(FILEDES,buffer,sizeof(hiddev_event));

if(bytesread!=sizeof(hiddev_event)){
exit(1);
}
printf("Unknown event bytes=%d hid=%d value=%d\n",
bytesread,buffer->hid,buffer->value);
}
}

When I try to write in fd (in order to write to the device) errno return me the value 22(EINVAL) although I open fd in O_WRONLY or O_RDWR...



Please help me.

B.GIRAUD<bastgiraud@wanadoo.fr>

Last edited by bast; 08-17-2004 at 03:17 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
which device in /dev is mapped to an USB device malo_umoran Slackware 4 07-31-2005 01:12 PM
Failed to open device /dev/usb/ttyUSB0: No such device efm Linux - Newbie 2 04-04-2005 08:46 PM
HP Deskjet (USB) & CUPS & Slackware 9.1: Unable to open USB device "usb:/dev/usb/lp0&qu arnostienen Slackware 2 01-29-2004 03:22 PM
write access on usb storage device wincen Linux - Hardware 3 01-20-2004 08:01 AM
/dev location or name of USB device dark_forests Linux - Hardware 3 10-12-2003 11:37 PM


All times are GMT -5. The time now is 08:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration