read from a USB Barcode-Reader

Hi all , I'm trying to read from a USB Barcode-Reader "LX-250" (on Unix) ,
I've written the following code ...
But the program always failes on : ioctl call

Please if anyone has any ideas on what causes it to fail ?
Or how should I try to access the Barcode Device ?

Your help is very much appreciated !
Thanks

#include <sys/stream.h>
#include <sys/kbio.h>
#include <sys/kbd.h>
#include <sys/types.h>
#include <sys/stropts.h>
#include <sys/vuid_event.h>
#include <time.h>
#include <stdio.h> /* Standard input/output definitions /
#include <string.h> /
String function definitions /
#include <stdlib.h>
#include <unistd.h> /
UNIX standard function definitions /
#include <fcntl.h> /
File control definitions /
#include <errno.h> /
Error number definitions /
#include <termios.h> /
POSIX terminal control definitions */

main( int argc, char *argv[]){
int fd,rval;
char c;
Firm_event fe;

fd = open("/dev/usb/hid0" , O_RDWR);
if (fd < 0 ) {
exit (1);
}

printf\("open /dev/usb/hid0     O.K\\n"\); 

if ((rval = ioctl(fd, I_PUSH,"usbkbm")) < 0 ) {
perror("ioctl failed");
exit (2);
}
while (read(fd, &fe, sizeof(fe))) {
printf("\n");
printf("%d", fe.id);
printf("%d", fe.value);
}
}

The output is :

open /dev/usb/hid0 O.K
ioctl failed: Invalid argument

Please If anyone has any suggestions.... or know any other way
to retrive a barcode scan

Thanks again
Yuval

1 Like

It would help if you would tell us which unix you are using. The only usbkvm manpage I find is here, and when I read the man page, I see:

open("/dev/kbd", O_RDWR)

and I would expect this module to be autopushed anyway. Be sure that you're open the right device. And run autopush on that device to be sure that the module really needs an explicit push.

I sorta doubt that a keyboard module will handle a bar code reader anyway. But I've never worked with this stuff, so who knows...

Typically the bar code reader will do all the interperation of the barcode and will return the value string. To a keyboard module it would look like someone typed "1234567890"