/// <summary> /// Function to convert the selected provisioning package into chunk and send it over NFC. /// </summary> /// <returns></returns> private async Task InternalTransferHandlerAsync(CancellationToken ct) { rootPage.NotifyUser("Tap device to transfer package.", NotifyType.StatusMessage); if (null == provisioningPackageFile) { rootPage.NotifyUser("Select a package before transferring.", NotifyType.ErrorMessage); return; } IBuffer buffer = await FileIO.ReadBufferAsync(provisioningPackageFile); if (null == buffer) { rootPage.NotifyUser("Something was wrong. Choose another package and retry again.", NotifyType.ErrorMessage); return; } ProximityDevice proximityDevice = ProximityDevice.GetDefault(); if (null == proximityDevice) { rootPage.NotifyUser("You'll need to turn on NFC to transfer the package. Go to NFC settings.", NotifyType.ErrorMessage); return; } // Start to format the provisioning package into chunks, and transfer it to another device to be provisioned. await ConvertToNfcMessageAsync(buffer, proximityDevice, NfcMessageHandlerAsync, ct); rootPage.NotifyUser("Success!", NotifyType.StatusMessage); }
private void btnWriteLauch_Click(object sender, RoutedEventArgs e) { ProximityDevice device = ProximityDevice.GetDefault(); if (device != null) { //var appId = Windows.ApplicationModel.Store.CurrentApp.AppId; var appId = "4bad5210-10de-4ae1-a10d-3bb5ce218d66"; const string launchArgs = "user=default"; string appName = "NFCMessage" + "!" + appId; string launchAppMessage = launchArgs + "\tWindows\t" + appName; var dataWriter = new DataWriter { UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE }; dataWriter.WriteString(launchAppMessage); _launchAppPubId = device.PublishBinaryMessage( "LaunchApp:WriteTag", dataWriter.DetachBuffer(), (proximityDevice, id) => Deployment.Current.Dispatcher.BeginInvoke(() => { device.StopPublishingMessage(_launchAppPubId); MessageBox.Show("Nachricht erfolgreich geschrieben !"); })); } }
public async void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to perform background work // // If you start any asynchronous methods here, prevent the task // from closing prematurely by using BackgroundTaskDeferral as // described in http://aka.ms/backgroundtaskdeferral _deferral = taskInstance.GetDeferral(); await Task.Delay(30000); bs = new RateSensor(); bs.RateSensorInit(); await Task.Delay(1000); bs.RateMonitorON(); deviceWatcher = DeviceInformation.CreateWatcher( "System.ItemNameDisplay:~~\"Adafruit\"", new string[] { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }, DeviceInformationKind.AssociationEndpoint); deviceWatcher.Added += DeviceWatcher_Added; deviceWatcher.Removed += DeviceWatcher_Removed; deviceWatcher.Start(); // NFC proxDevice = ProximityDevice.GetDefault(); if (proxDevice != null) { proxDevice.SubscribeForMessage("NDEF", messagedReceived); } else { Debug.WriteLine("No proximity device found\n"); } this.timer = ThreadPoolTimer.CreateTimer(Timer_Tick, TimeSpan.FromSeconds(2)); try { await Task.Run(async() => { while (true) { await Task.Delay(100000); } }); } catch (Exception ex) { } deviceWatcher.Stop(); }
/** * Start/stop listening on the proximity device for a tag. * * @param input {object} * @param input.stop {bool} True to stop listening. * @param input.gotTag {Function(Buffer)} The callback for when a tag is received. * @return true on success. false if there is no such device. */ public async Task <object> Invoke(dynamic input) { ProximityDevice dev = ProximityDevice.GetDefault(); bool success = false; if (dev != null) { if (input.stop) { // Stop listening. if (subscriptionId >= 0) { dev.StopSubscribingForMessage(subscriptionId); subscriptionId = -1; } gotTagCallback = null; } else if (subscriptionId < 0) { // Start listening. gotTagCallback = input.gotTag; subscriptionId = dev.SubscribeForMessage("NDEF", new MessageReceivedHandler(GotTag)); } success = true; } return(success); }
public bool doInitialise(Int32 cbUIDPtr, Int32 cbStatePtr, out String AMessage) { recordList = new List <NdefRecord>(); proximityDevice = ProximityDevice.GetDefault(); ptr = new IntPtr(cbUIDPtr); callbackUID = (cbUID)Marshal.GetDelegateForFunctionPointer(ptr, typeof(cbUID)); ptr = new IntPtr(cbStatePtr); callbackState = (cbState)Marshal.GetDelegateForFunctionPointer(ptr, typeof(cbState)); if (proximityDevice != null) { proximityDevice.DeviceArrived += ProximityDeviceArrived; proximityDevice.DeviceDeparted += ProximityDeviceDeparted; proximityDevice.SubscribeForMessage("NDEF", MessageReceivedHandler); AMessage = "Proximity device initialized. ID: " + proximityDevice.DeviceId; return(true); } else { AMessage = "Failed to initialize proximity device."; return(false); } }
public WriteLaunchAppTag() { InitializeComponent(); device = ProximityDevice.GetDefault(); writableTagId = device.SubscribeForMessage("WriteableTag", checkWritableTagSize); inputText.Text = appIdNokiaMusic; }
public MainPage() { // Initialize this page's components that were set up via the UI designer. InitializeComponent(); // Set up Corona to automatically start up when the control's Loaded event has been raised. // Note: By default, Corona will run the "main.lua" file in the "Assets\Corona" directory. // You can change the defaults via the CoronaPanel's AutoLaunchSettings property. fCoronaPanel.AutoLaunchEnabled = true; // Set up the CoronaPanel control to render fullscreen via the DrawingSurfaceBackgroundGrid control. // This significantly improves the framerate and is the only means of achieving 60 FPS. fCoronaPanel.BackgroundRenderingEnabled = true; fDrawingSurfaceBackgroundGrid.SetBackgroundContentProvider(fCoronaPanel.BackgroundContentProvider); fDrawingSurfaceBackgroundGrid.SetBackgroundManipulationHandler(fCoronaPanel.BackgroundManipulationHandler); // Add a Corona event handler which detects when the Corona project has been loaded, but not started yet. fCoronaPanel.Runtime.Loaded += OnCoronaRuntimeLoaded; // Add a Corona event handler which detects when the Corona project has been started. fCoronaPanel.Runtime.Started += OnCoronaRuntimeStarted; //For sending and receiving messages _proximityDevice = ProximityDevice.GetDefault(); if (_proximityDevice == null) { // Device failed to load. // TO DO: Add error message } }
public MainPage() { this.InitializeComponent(); Synopsis.Text += "\n\n"; try { proximityDevice = ProximityDevice.GetDefault(); Synopsis.Text += proximityDevice.DeviceId + "\n\n"; } catch (Exception e) { Synopsis.Text += e.ToString() + "\n\n"; } if (proximityDevice != null) { proximityDevice.DeviceArrived += DeviceArrived; proximityDevice.DeviceDeparted += DeviceDeparted; } else { Synopsis.Text += "No proximity device found\n"; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); try { // NFCデバイスがない場合にはnullが返る // NFCデバイスがあり、WMAppManifest.xmlの「機能|ID_CAP_PROXINITY」にチェックがない場合は例外が発生する proximityDevice = ProximityDevice.GetDefault(); if (proximityDevice == null) { throw new Exception("NFCデバイスが見つかりません"); } // デバイスの認識、消失イベント proximityDevice.DeviceArrived += proximityDevice_DeviceArrived; proximityDevice.DeviceDeparted += proximityDevice_DeviceDeparted; TextSendMessage.Text = @"Hello NFC!! From Windows Phone"; } catch (Exception ex) { MessageBox.Show(ex.Message); TextMessage.Text = ex.Message; } }
private void btnWinMime_Click(object sender, RoutedEventArgs e) { ProximityDevice device = ProximityDevice.GetDefault(); if (device != null) { if (_subscriptionId > -1) { device.StopSubscribingForMessage(_subscriptionId); } _subscriptionId = device.SubscribeForMessage( "WindowsMime", (proximityDevice, message) => { var buffer = message.Data.ToArray(); int mimesize = 0; //suchen nach '\0' for (mimesize = 0; mimesize < 256 && buffer[mimesize] != 0; ++mimesize) { } //MimeType bestimmen var mimeType = Encoding.UTF8.GetString(buffer, 0, mimesize).Trim(); if (mimeType == "text/plain") { //convert data to string. This traitement depend on mimetype value. tbMime.Text = Encoding.UTF8.GetString(buffer, 256, buffer.Length - 256); } }); } }
// no args public void registerNdef(string args) { Debug.WriteLine("Registering for NDEF"); proximityDevice = ProximityDevice.GetDefault(); subscribedMessageId = proximityDevice.SubscribeForMessage("NDEF", MessageReceivedHandler); DispatchCommandResult(); }
public bool IsNfcAvailable() { try { return(ProximityDevice.GetDefault() != null); } catch (Exception) { return(false); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { _proximity = ProximityDevice.GetDefault(); if (_proximity != null) { _subscriptionId = _proximity.SubscribeForMessage("NDEF", TagRead); } }
/// <summary> /// Constructor. /// </summary> public MainPage() { InitializeComponent(); recordList = new List <NdefRecord>(); device = ProximityDevice.GetDefault(); device.DeviceArrived += DeviceArrived; device.DeviceDeparted += DeviceDeparted; SubscribeForMessage(); }
public NfcPlugin() { Debug.WriteLine("Nfc Plugin"); proximityDevice = ProximityDevice.GetDefault(); if (proximityDevice == null) // shouldn't happen { Debug.WriteLine("WARNING: proximity device is null"); } }
private void BtnInitNfc_Click(object sender, RoutedEventArgs e) { // Initialize NFC _device = ProximityDevice.GetDefault(); // Update status text for UI SetStatusOutput(_device != null ? AppResources.StatusInitialized : AppResources.StatusInitFailed); // Update enabled / disabled state of buttons in the User Interface UpdateUiForNfcStatus(); }
public RFIDSocket() { this.device = ProximityDevice.GetDefault(); this.subscriptionID = RFIDSocket.NO_SUBSCRIPTION; this.arrivedHandler = null; this.departedHandler = null; this.transmitHandler = null; this.lastMessage = "Nix drin"; }
public MainWindowViewModel() { _proximityDevice = ProximityDevice.GetDefault(); if (_proximityDevice != null) { _proximityDevice.DeviceArrived += _proximityDevice_DeviceArrived; _proximityDevice.DeviceDeparted += _proximityDevice_DeviceDeparted; _MessageType = _proximityDevice.SubscribeForMessage("WindowsUri", MessageReceivedHandler); } }
private void btnUnsubscribe_Click(object sender, RoutedEventArgs e) { ProximityDevice device = ProximityDevice.GetDefault(); // Prüfen ob NFC auf diesem Gerät verfügbar ist if (device != null && _subscriptionId > -1) { device.StopSubscribingForMessage(_subscriptionId); } }
public TagReader() { buzzer = new Buzzer(); proximityDevice = ProximityDevice.GetDefault(); if (proximityDevice != null) { proximityDevice.DeviceArrived += OnDeviceArrived; OnDeviceStatusChanged += buzzer.OnDevicesStatusChanged; proximityDevice.DeviceDeparted += OnDeviceDeparted; } }
private void NdefButton_Click(object sender, RoutedEventArgs e) { if (_device != null) { return; } // Start NDEF subscription _device = ProximityDevice.GetDefault(); _subscribedMessageId = _device.SubscribeForMessage("NDEF", MessageReceivedHandler); SetStatusOutput("Subscribed for NDEF / NFC"); }
void initPageToListenToNFCDevices(object sender, RoutedEventArgs e) { if (NFCDevice == null) { NFCDevice = ProximityDevice.GetDefault(); NFCDevice.DeviceArrived += device_DeviceArrived; NFCDevice.DeviceDeparted += device_DeviceDeparted; //Not used for now... NFCDevice.SubscribeForMessage("WindowsUri", WindowsUriHandler); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.New) { var nfcDevice = ProximityDevice.GetDefault(); if (nfcDevice == null) { MessageBox.Show("NFC nicht unterstützt!"); } } }
public void Init() { UpdateState(); _nfcDevice = ProximityDevice.GetDefault(); if (_nfcDevice == null) { UpdateState(NfcHelperState.NoDeviceFound); return; } UpdateState(NfcHelperState.Ready); }
private void btnStopPublic_Click(object sender, RoutedEventArgs e) { ProximityDevice device = ProximityDevice.GetDefault(); // Prüfen ob NFC auf diesem Gerät verfügbar ist if (device != null && _publishedMessageId > -1) { device.StopPublishingMessage(_publishedMessageId); _publishedMessageId = -1; } }
static void Main(string[] args) { ProximityDevice device = ProximityDevice.GetDefault(); if (device != null) { long messageId = // device.PublishMessage("Windows.message", "yeh"); device.PublishUriMessage(new Uri(args[0])); //Reuse messageId to unpublish that message. Thread.Sleep(Timeout.Infinite); } }
public WriteTask() { try { _proximityDevice = ProximityDevice.GetDefault(); } catch (System.UnauthorizedAccessException) { //You don't have permission to read NFC Mvx.Error("You don't have permission to read NFC. Please update your manifest file"); } }
// Constructor public MainPage() { InitializeComponent(); ProximityDevice device = ProximityDevice.GetDefault(); if (device == null) { MessageBox.Show("Turn on your NFC"); Application.Current.Terminate(); } }
public NfcForms() { nfcTag = new NfcFormsTag(); if (ProximityDevice.GetDefault() != null) { nfcDevice = ProximityDevice.GetDefault(); nfcDevice.SubscribeForMessage("NDEF", MessageReceivedHandler); nfcTag.IsWriteable = false; nfcTag.MaxSize = 0; nfcDevice.DeviceArrived += nfcDevice_DeviceArrived; nfcDevice.DeviceDeparted += nfcDevice_DeviceDeparted; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Handle hardware back button Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed; // Get the nfc device this.device = ProximityDevice.GetDefault(); // Start publishing the default message this.StartPublish(); }