【问题标题】:Read USB Magstripe reader through ssh通过 ssh 读取 USB 磁条阅读器
【发布时间】:2017-09-12 14:32:16
【问题描述】:

我为我的 pi 制作了一个 python 程序,它检测来自我的 USB 读卡器的字符串(它就像一个 USB 键盘)并将它们写入一个文件。我意识到,如果我 ssh 进入程序运行它,程序将无法运行。我的猜测是,因为我的程序接受输入到控制台的原始输入,所以如果我通过 ssh 打开它,它将无法工作。谁可以帮我这个事?

下面是我的程序:

import datetime
import time

card = raw_input()
t = datetime.datetime.now()
while True:
    f = open("Laptop Sign Out" + '.txt', 'a')
    f.write("Card Number: " + card[1:10] + " Time: " + t.strftime("%m-%d-%Y $
    f.write('\n')
    f.write(';')
    f.write('\n')
    f.close()
    time.sleep(5)

【问题讨论】:

    标签: python ssh keyboard raspberry-pi


    【解决方案1】:

    您可以使用evdev 库,它允许将内核中生成的事件直接重定向到用户代码。

    看这个例子:

    >>> from evdev import InputDevice, categorize, ecodes
    >>> dev = InputDevice('/dev/input/event1')
    
    >>> print(dev)
    device /dev/input/event1, name "Dell Dell USB Keyboard", phys "usb-0000:00:12.1-2/input0"
    
    >>> for event in dev.read_loop():
    ...     if event.type == ecodes.EV_KEY:
    ...         print(categorize(event))
    ... # pressing 'a' and holding 'space'
    key event at 1337016188.396030, 30 (KEY_A), down
    key event at 1337016188.492033, 30 (KEY_A), up
    key event at 1337016189.772129, 57 (KEY_SPACE), down
    key event at 1337016190.275396, 57 (KEY_SPACE), hold
    key event at 1337016190.284160, 57 (KEY_SPACE), up
    

    补充阅读是here

    描述here的方式有点不同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-07
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多