栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

linux下接扫描枪问题

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux下接扫描枪问题

使用斑马扫描枪扫描条形码:6935205322654

在windows 扫描出 :6935205322654

在linux下 读出:
type:1 code:7 value:0
type:1 code:10 value:0
type:1 code:4 value:0
type:1 code:6 value:0
type:1 code:3 value:0
type:1 code:11 value:0
type:1 code:6 value:0
type:1 code:4 value:0
type:1 code:3 value:0
type:1 code:3 value:0
type:1 code:7 value:0
type:1 code:6 value:0
type:1 code:5 value:0
type:1 code:28 value:0  

linux 下读取代码:

#include
#include
#include
#include

#define SCANNER_DEV "/dev/input/event2"

struct input_event event; 
int fd; 
int read_nu;

int main(int argc, char *argv[])
{
    fd = open(SCANNER_DEV, O_RDONLY);//打开usb扫描枪设备
    if (fd < 0)
    { 
        perror("can not open device usbscanner!"); 
        exit(1); 
    } 
    int i = 0;
    printf("--fd:%d--n",fd);
    while(1)
    {
        if(read(fd,&event,sizeof(struct input_event))>0)
        {
            switch (event.type)
            {  
                case EV_KEY: 
               printf("type:%d code:%d value:%dn",event.type,event.code,event.value); 
            }
        }
        
    }
    close(fd); 
    return 1;
}
 

原因: Linux下键盘键值对应input event下的code值表 不一样。

比如    #define KEY_6            7   此时表示code值为7 对应的键盘值 实际为 6  

对应关系 参考链接  Linux下键盘键值对应input event下的code值表_cyf15238622067的博客-CSDN博客_linux键值

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/612487.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号