SimpleSample.py
# coding: utf-8
import sys
import os
sys.path.append(os.path.dirname(__file__) + '/nfcpy')
import nfc
#Function to execute when the card is touched
def hello(tag):
print 'hello'
clf = nfc.ContactlessFrontend('usb') #Specify only that it is a USB device
#clf = nfc.ContactlessFrontend('usb:054c:06c3') #Specify vendor ID(Sony's PaSoRi Vendor ID)
#clf = nfc.ContactlessFrontend('usb:001') #Specify the bus number. Choose the first one on this bus
#clf = nfc.ContactlessFrontend('usb:001:011') #Specify bus number and device number
rdwr = {'on-connect':hello}
print 'start'
clf.connect(rdwr=rdwr)
print 'end'
Connect to the card reader with clf = nfc.ContactlessFrontend ()
, but there are several types of arguments.
argument | Example | meaning |
---|---|---|
'usb' | 'usb' | Connect to the device found (first?) |
'usb:Vendor ID' | 'usb:054c:06c3' | 指定のVendor IDのデバイスの中から(一番初めに?)見つかったものに接続 |
'usb:Bus number' | 'usb:001' | 指定のBus numberのデバイスの中から一番初めに見つかったものに接続 |
'usb:Bus number:Device number' | 'usb:001:011' | 指定のBus numberとDevice numberのデバイスに接続 |
You can find the vendor ID, bus number, and device number with the lsusb
command.
$ lsusb
Bus 001 Device 010: ID 054c:06c3 Sony Corp.
Bus 001 Device 011: ID 054c:06c3 Sony Corp.
# Bus [Bus number] Device [Device number]: ID [Vendor ID] [Manufacturer's name]
Recommended Posts