相关疑难解决方法(0)

从输入事件中读取条形码(linux,c)

我有一个小程序从/ dev/input/event4读取条形码.这是代码:

#include <sys/file.h>
#include <stdio.h>
#include <string.h>
#include <linux/input.h>

int main (int argc, char *argv[])
{
        struct input_event ev;
        int fd, rd;

        //Open Device
        if ((fd = open ("/dev/input/event4", O_RDONLY|O_NONBLOCK)) == -1){
                printf ("not a vaild device.\n");
                return -1;
        }

        while (1){

                memset((void*)&ev, 0, sizeof(ev));

                rd = read (fd, (void*)&ev, sizeof(ev));

                if (rd <= 0){
                        printf ("rd: %d\n", rd);
                        sleep(1);
                }

                if(rd>0 && ev.value==0 && ev.type==1){
                        printf("type: %d, code: %d, value: %d, rd: %d\n", ev.type, ev.code, ev.value, rd);
                } …
Run Code Online (Sandbox Code Playgroud)

c linux barcode device barcode-scanner

4
推荐指数
1
解决办法
5856
查看次数

标签 统计

barcode ×1

barcode-scanner ×1

c ×1

device ×1

linux ×1