首先用 cat /proc/bus/input/devices 确定读卡器设备在系统里的注册信息
| cat /proc/bus/input/devices |
I: Bus=0019 Vendor=0001 Product=0001 Version=0100 N: Name="gpio-keys" P: Phys=gpio-keys/input0 S: Sysfs=/devices/platform/gpio-keys/input/input0 U: Uniq= H: Handlers=kbd event0 B: PROP=0 B: EV=3 B: KEY=1680 0 0 10000002 I: Bus=0019 Vendor=0001 Product=0001 Version=0001 N: Name="s3c-keypad" P: Phys=s3c-keypad/input0 S: Sysfs=/devices/virtual/input/input1 U: Uniq= H: Handlers=kbd event1 B: PROP=0 B: EV=100003 B: KEY=1680 0 0 10004ffc I: Bus=0013 Vendor=dead Product=beef Version=0101 N: Name="S3C TouchScreen" P: Phys=input(ts) S: Sysfs=/devices/virtual/input/input2 U: Uniq= H: Handlers=mouse0 event2 B: PROP=0 B: EV=b B: KEY=400 0 0 0 0 0 0 0 0 0 0 B: ABS=1000003 I: Bus=0003 Vendor=08ff Product=0009 Version=0110 N: Name="USB Reader With Keyboard" P: Phys=usb-s3c24xx-1/input0 S: Sysfs=/devices/platform/s3c2410-ohci/usb1/1-1/1-1:1.0/input/input3 U: Uniq= H: Handlers=sysrq kbd event3 B: PROP=0 B: EV=120013 B: KEY=e080ffdf 1cfffff ffffffff fffffffe B: MSC=10 B: LED=1f |

系统input_event事件定义
struct input_event {
struct timeval time; //事件触发的时间
__u16 type; //事件类型
__u16 code; //代码,如果是键盘则是按键代码
__s32 value; //如果是键盘则value = KeyDown 或者 KeyUP
};
(1)详细的type定义
#define EV_SYN 0x00 #define EV_KEY 0x01 //按键 #define EV_REL 0x02 //相对坐标(轨迹球) #define EV_ABS 0x03 //绝对坐标 #define EV_MSC 0x04 //其他 #define EV_SW 0x05 #define EV_LED 0x11 //LED #define EV_SND 0x12//声音 #define EV_REP 0x14//repeat #define EV_FF 0x15 #define EV_PWR 0x16 #define EV_FF_STATUS 0x17 #define EV_MAX 0x1f #define EV_CNT (EV_MAX+1) |
(2)value定义
当按键按下时值为1,松开时值为0
用 ls /dev/input 查看

完整的测试代码如下:
#include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #include <linux/input.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { int fd; struct input_event ev; int nBytes; fd = open("/dev/input/event3", O_RDONLY); if (fd < 0) { perror("can not open device\r\n"); exit(1); } while (1) { nBytes = read(fd, (char *) &ev, sizeof(struct input_event)); if (nBytes > 0) { if (ev.type == 1) { //按键值 if (ev.value == 0) { //放开的按键值 printf("nBytes=[%d] type =[%d] code=[%d] value=[%d] \n", nBytes, ev.type, ev.code, ev.value); } } } } }
|

运行的结果如下:

以上程序在:
飞凌OK6410开发板上运行通过。
IC卡读卡器为:USB Reader With Keyboard (淘宝上买的56元钱,不知道是什么品牌的)
PC 开发环境为:
Ubuntu 11.10 + Eclipse + JRE7 + arm-linux-gcc 4.3.3
最后要感谢飞凌的工程师提供了技术支持!