因爲每次插入刷卡器以後,控制句柄會發生改變。linux
例如此次是/dev/input/event1
,下次是/dev/input/event0
。面對會有多個event
,必須寫個查找程序。git
linux系統裏面的/proc/bus/input/devices
文件存儲了輸入設備的信息,能夠經過讀取該文件判斷輸入設備。該文件信息以下:github
qusir@qusir-HP-dx2818-MT:~$ cat /proc/bus/input/devices I: Bus=0019 Vendor=0000 Product=0001 Version=0000 N: Name="Power Button" P: Phys=PNP0C0C/button/input0 S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input0 U: Uniq= H: Handlers=kbd event0 B: PROP=0 B: EV=3 B: KEY=10000000000000 0 I: Bus=0019 Vendor=0000 Product=0001 Version=0000 N: Name="Power Button" P: Phys=LNXPWRBN/button/input0 S: Sysfs=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input1 U: Uniq= H: Handlers=kbd event1 B: PROP=0 B: EV=3 B: KEY=10000000000000 0 I: Bus=0003 Vendor=413c Product=2106 Version=0110 N: Name="DELL Dell QuietKey Keyboard" P: Phys=usb-0000:00:1d.1-1/input0 S: Sysfs=/devices/pci0000:00/0000:00:1d.1/usb7/7-1/7-1:1.0/0003:413C:2106.0001/input/input5 U: Uniq= H: Handlers=sysrq kbd event2 leds B: PROP=0 B: EV=120013 B: KEY=1000000000007 ff9f207ac14057ff febeffdfffefffff fffffffffffffffe B: MSC=10 B: LED=7 I: Bus=0003 Vendor=093a Product=2510 Version=0111 N: Name="PixArt USB Optical Mouse" P: Phys=usb-0000:00:1d.1-2/input0 S: Sysfs=/devices/pci0000:00/0000:00:1d.1/usb7/7-2/7-2:1.0/0003:093A:2510.0002/input/input6 U: Uniq= H: Handlers=mouse0 event3 B: PROP=0 B: EV=17 B: KEY=70000 0 0 0 0 B: REL=103 B: MSC=10 I: Bus=0003 Vendor=ffff Product=0035 Version=0110 N: Name="Sycreader RFID Technology Co., Ltd SYC ID&IC USB Reader" P: Phys=usb-0000:00:1d.2-1/input0 S: Sysfs=/devices/pci0000:00/0000:00:1d.2/usb8/8-1/8-1:1.0/0003:FFFF:0035.0003/input/input7 U: Uniq=08FF20140315 H: Handlers=sysrq kbd event4 leds B: PROP=0 B: EV=120013 B: KEY=e080ffdf01cfffff fffffffffffffffe B: MSC=10 B: LED=1f I: Bus=0003 Vendor=e806 Product=6001 Version=0040 N: Name="USB 2.0 Camera" P: Phys=usb-0000:00:1d.7-6/button S: Sysfs=/devices/pci0000:00/0000:00:1d.7/usb2/2-6/2-6:1.0/input/input8 U: Uniq= H: Handlers=kbd event5 B: PROP=0 B: EV=3 B: KEY=100000 0 0 0 I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="HDA Intel Front Mic" P: Phys=ALSA S: Sysfs=/devices/pci0000:00/0000:00:1b.0/sound/card0/input9 U: Uniq= H: Handlers=event6 B: PROP=0 B: EV=21 B: SW=10 I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="HDA Intel Rear Mic" P: Phys=ALSA S: Sysfs=/devices/pci0000:00/0000:00:1b.0/sound/card0/input10 U: Uniq= H: Handlers=event7 B: PROP=0 B: EV=21 B: SW=10 I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="HDA Intel Line" P: Phys=ALSA S: Sysfs=/devices/pci0000:00/0000:00:1b.0/sound/card0/input11 U: Uniq= H: Handlers=event8 B: PROP=0 B: EV=21 B: SW=2000 I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="HDA Intel Line Out" P: Phys=ALSA S: Sysfs=/devices/pci0000:00/0000:00:1b.0/sound/card0/input12 U: Uniq= H: Handlers=event9 B: PROP=0 B: EV=21 B: SW=40 I: Bus=0000 Vendor=0000 Product=0000 Version=0000 N: Name="HDA Intel Front Headphone" P: Phys=ALSA S: Sysfs=/devices/pci0000:00/0000:00:1b.0/sound/card0/input13 U: Uniq= H: Handlers=event10 B: PROP=0 B: EV=21 B: SW=4
能夠看到以上信息中有"Sycreader RFID Technology Co., Ltd SYC ID&IC USB Reader"
關鍵字,經過該關鍵字能夠判斷刷卡器的控制句柄爲event4
ui
代碼段查看連接code