2021-08-16
NFC, Python, Raspberrypi, Sensor
nfc raspberrypi read tag on-release, on-connect
on-release
ximport nfc
import time
def released (tag):
print(tag)
print('released!!')
time.sleep(1)
clf = nfc.ContactlessFrontend('usb')
while True:
print('waiting...')
result = clf.connect(rdwr={'on-release':released})
print('----------------------')
print(result)
print('scaned')
をやると, felicaを離した時に,
xxxxxxxxxx
waiting...
Type3Tag ID=01010501b00ac30b PMM=03014b024f4993ff SYS=1234
released!!
とでる.
"scaned"が出ないけど, felicaをつけて離してつけて離して...を繰り返すと
xxxxxxxxxx
waiting...
Type3Tag ID=01010501b00ac30b PMM=03014b024f4993ff SYS=1234
released!!
waiting...
Type3Tag ID=01010501b00ac30b PMM=03014b024f4993ff SYS=1234
released!!
waiting...
Type3Tag ID=01010501b00ac30b PMM=03014b024f4993ff SYS=1234
released!!
waiting...
Type3Tag ID=01010501b00ac30b PMM=03014b024f4993ff SYS=1234
released!!
となるので, while trueは効いてる模様. ふむ...
on-connect, on-release
xxxxxxxxxx
import nfc
import time
def connected (tag):
print('connected!!')
time.sleep(1)
def released (tag):
print('released!!')
time.sleep(1)
clf = nfc.ContactlessFrontend('usb')
rdwr_options={
'on-connect':connected,
'on-release':released,
}
while True:
print('waiting...')
#clf.connect(rdwr={'on-connect':connected, 'on-release':released})
clf.connect(rdwr=rdwr_options)
print('scaned')
のようにon-connectとon-releaseを両方使用してみたが, つけて離してつけて離して...を繰り返しても
xxxxxxxxxx
waiting...
connected!!
scaned
waiting...
connected!!
scaned
waiting...
connected!!
となるだけで, on-releaseが効かず....
rdwr_optionsを使用せずに,
xxxxxxxxxx
import nfc
import time
def connected (tag):
print('connected!!')
time.sleep(1)
def released (tag):
print('released!!')
time.sleep(1)
clf = nfc.ContactlessFrontend('usb')
while True:
print('waiting...')
clf.connect(rdwr={'on-connect':connected, 'on-release':released})
print('scaned')
とやっても結果は同じ. ふむ....