Install the HID driver we needed:

opkg update 
opkg install kmod-usb-hid
...
Configuring kmod-input-core.
Configuring kmod-input-evdev.
Configuring kmod-hid.
Configuring kmod-usb-hid.
...
ls -l /dev/input/
crw-r--r--    1 root     root       13,  64 Jan  1  1970 event0
crw-r--r--    1 root     root       13,  65 Oct 18 06:27 event1

The barcode scanner is at "/dev/input/event1"

Now we need compile c program "barcode"

nano /mnt/sda1/barcode.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#define KEY_PRESS 1
#define KEY_KEEPING_PRESSED 2
int main (int argc, char *argv[])
{
struct input_event ev[64];
int fd, rd,size = sizeof (struct input_event);
char name[256] = "Unknown",i;
char *device = NULL;
char decode_scancode[]={0,0,1,2,3,4,5,6,7,8,9,0};
if (argv[1] == NULL){
printf("Please enter path to device\n");
return 1;
}
if ((getuid ()) != 0)
printf ("You must be as root for correct work!\n");
if (argc > 1)
device = argv[1];
if ((fd = open (device, O_RDONLY)) == -1){
printf ("Open error of device %s\n", device);
return 1;
}
ioctl (fd, EVIOCGNAME (sizeof (name)), name);
printf ("Reading From : %s (%s)\n", device, name);
while (1){
if ((rd = read (fd, ev, size * 64)) < size){
perror ("Read error");
return 1;
}
for (i=0; i< ((int)(rd/size)); i++) {
if (ev[i].type == EV_KEY) {
if ((ev[i].value == KEY_PRESS) || (ev[i].value == KEY_KEEPING_PRESSED)) {
if (ev[i].code < 12) {
printf ("%d", (decode_scancode[ev[i].code]));
}
else if (ev[i].code == 28) {
printf ("\n");
}
}
}
}
}
return 0;
}
gcc -o barcode barcode.c

barcode excutable for Yun:

https://www.dropbox.com/s/1a2860gei4ugiqk/barcode?dl=0
/mnt/sda1/barcode  /dev/input/event1
Reading From : /dev/input/event1 (WIT Electron Company WIT 122-UFS V2.03)
8901260131579638577
610214633880
000000610214633880
357510050163655
610214633880
^C

Comments powered by CComment