Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of NFC using Windows Proximity class
"""
Example of NFC using Windows Proximity class.
Tested using Sony RC-S380 (make sure you enable NFP in the driver).
Requires Windows 10 and Python 3.7+ (for WinRT/Python).
"""
import sys
import time
import winrt.windows.networking.proximity as proximity
import winrt.windows.storage.streams as streams
def main():
device = proximity.ProximityDevice.get_default()
if device is None:
print('ERROR: No ProximityDevice found', file=sys.stderr)
sys.exit(1)
msg = 'https://dcoles.net'.encode('utf-8')
# Manually construct a NDEF message
# (Though it's better to let ProximityDevice.PublishUriMessage do this for you)
writer = streams.DataWriter()
writer.write_byte(0b11010011) # Absolute URI
writer.write_byte(len(msg))
writer.write_byte(0)
writer.write_bytes(list(msg))
device.publish_binary_message("NDEF", writer.detach_buffer())
while True:
time.sleep(3600)
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment