__main__.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:nfcpy 作者: nfcpy 项目源码 文件源码
def main(args):
    print("This is the %s version of nfcpy run in Python %s\non %s" %
          (nfc.__version__, platform.python_version(), platform.platform()))
    print("I'm now searching your system for contactless devices")

    found = 0
    for vid, pid, bus, dev in nfc.clf.transport.USB.find("usb"):
        if (vid, pid) in nfc.clf.device.usb_device_map:
            path = "usb:{0:03d}:{1:03d}".format(bus, dev)
            try:
                clf = nfc.ContactlessFrontend(path)
                print("** found %s" % clf.device)
                clf.close()
                found += 1
            except IOError as error:
                if error.errno == errno.EACCES:
                    usb_device_access_denied(bus, dev, vid, pid, path)
                elif error.errno == errno.EBUSY:
                    usb_device_found_is_busy(bus, dev, vid, pid, path)

    if args.search_tty:
        for dev in nfc.clf.transport.TTY.find("tty")[0]:
            path = "tty:{0}".format(dev[8:])
            try:
                clf = nfc.ContactlessFrontend(path)
                print("** found %s" % clf.device)
                clf.close()
                found += 1
            except IOError as error:
                if error.errno == errno.EACCES:
                    print("access denied for device with path %s" % path)
                elif error.errno == errno.EBUSY:
                    print("the device with path %s is busy" % path)
    else:
        print("I'm not trying serial devices because you haven't told me")
        print("-- add the option '--search-tty' to have me looking")
        print("-- but beware that this may break other serial devs")

    if not found:
        print("Sorry, but I couldn't find any contactless device")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号