public void PingAdversary(ProximityDevice device, NotifyNfcReady notify) { if (subscribeId != -1) { proximityDevice.StopSubscribingForMessage(subscribeId); subscribeId = -1; } if (publishId != -1) { proximityDevice.StopPublishingMessage(publishId); publishId = -1; } if (state == NfcManager.ProtoState.Busy) { return; } state = NfcManager.ProtoState.NotReady; notifyReady = notify; initialMessage.devicetime = random.NextDouble(); MemoryStream stream = new MemoryStream(); DataContractSerializer serializer = new DataContractSerializer(initialMessage.GetType()); serializer.WriteObject(stream, initialMessage); stream.Position = 0; var dataWriter = new DataWriter(); dataWriter.WriteBytes(stream.GetBuffer()); proximityDevice = device; publishId = proximityDevice.PublishBinaryMessage("Windows.CarTrumps", dataWriter.DetachBuffer()); subscribeId = proximityDevice.SubscribeForMessage("Windows.CarTrumps", OnMessageReceived); }
/// <summary> /// Stops all, publishing and subscribing. /// </summary> public void StopAll() { if (_publishedMsgId != -1) { _proximityDevice.StopPublishingMessage(_publishedMsgId); _publishedMsgId = -1; } if (_subscribedMsgId != -1) { _proximityDevice.StopSubscribingForMessage(_subscribedMsgId); _subscribedMsgId = -1; } }
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); } }); } }
/// <summary> /// Unsubsctibe from reading certain types of NFC messages /// </summary> /// <param name="type"></param> public void UnsubscribeForMessage(string type) { if ((pDevice != null) && (subscriptionIds.ContainsKey(type))) { pDevice.StopSubscribingForMessage(subscriptionIds[type]); } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { if (_subscriptionId > 0) { _proximity.StopSubscribingForMessage(_subscriptionId); } }
/** * 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); }
private void OnDeviceDeparted(ProximityDevice sender) { var stopwatch = (Stopwatch)null; if (Debug) { stopwatch = new Stopwatch(); stopwatch.Start(); } if (subscriptionIdNdef != 0) { sender.StopSubscribingForMessage(subscriptionIdNdef); subscriptionIdNdef = 0; } var args = new DeviceStatusChangedEventArgs() { DeviceStatus = StatusEnum.DeviceDeparted }; if (Debug) { stopwatch.Stop(); args.ExecutionTime = stopwatch.Elapsed; args.MethodName = "TagReader.OnDeviceDeparted"; } OnDeviceStatusChanged(this, args); }
public void UnsubscribeForNfcMessage() { if (proximityDevice != null) { proximityDevice.StopSubscribingForMessage(messageId); messageId = -1; } }
private void StopProximityDevice() { if (_ProximityDevice != null) { _ProximityDevice.StopSubscribingForMessage(ProximitySubscribeId); _ProximityDevice = null; } }
private void Unsubscribe() { if (subscriptionReference != 0) { proximityDevice.StopSubscribingForMessage(subscriptionReference); subscriptionReference = 0; } }
private void StopSubscribingForMessage() { if (subscribeId != -1) { proximityDevice.StopSubscribingForMessage(subscribeId); subscribeId = -1; } }
private void UnsubscribeNFC(long subscritpionId) { if (nfcDevice == null) { return; } nfcDevice.StopSubscribingForMessage(subscritpionId); subscritpionId = 0; }
private async void WritableTagDetectedHandler(ProximityDevice device, ProximityMessage message) { device.StopSubscribingForMessage(detectWriteableTagId); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { WriteTag.IsEnabled = true; }); }
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); } }
private async void MessageReceivedHandler(ProximityDevice device, ProximityMessage message) { device.StopSubscribingForMessage(subscribedMessageId); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { // Data: byte array stored in the NFC tag var dialog = new MessageDialog("NFC Data: " + message.DataAsString); await dialog.ShowAsync(); }); }
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedFrom(e); #if WP8 if (proximityDevice != null) { proximityDevice.StopSubscribingForMessage(nfcSubsId); } #endif LuaEngine.Instance.OnGuiEvent(this, LuaEngine.GuiEvents.GUI_EVENT_PAUSE, luaContext); }
/// <summary> /// Stops tags detection /// </summary> public void StopListening() { _defaultDevice.DeviceArrived -= OnDeviceArrived; _defaultDevice.DeviceDeparted -= OnDeviceDeparted; if (_ndefSubscriptionId != -1) { _defaultDevice.StopSubscribingForMessage(_ndefSubscriptionId); _ndefSubscriptionId = -1; } }
/// <summary> /// Stops tags detection /// </summary> public void StopListening() { _defaultDevice.DeviceArrived -= OnDeviceArrived; _defaultDevice.DeviceDeparted -= OnDeviceDeparted; if (_ndefSubscriptionId != -1) { _defaultDevice.StopSubscribingForMessage(_ndefSubscriptionId); _ndefSubscriptionId = -1; } OnTagListeningStatusChanged?.Invoke(false); }
/// <summary> /// Gets called when a message is received. Updates the UI by adding /// the details into the log and scrolling the log if necessary. /// Note that subscription for messages needs to be redone. /// </summary> /// <param name="sender">ProximityDevice instance</param> /// <param name="message">A message to be handled.</param> private void MessageReceived(ProximityDevice sender, ProximityMessage message) { Dispatcher.BeginInvoke(() => { if (device != null) { device.StopSubscribingForMessage(subscriptionId); } logText = logText + ParseNDEF(message); ScrollViewer.UpdateLayout(); ScrollViewer.ScrollToVerticalOffset(0); SubscribeForMessage(); }); }
private void StopSubscription(bool writeToStatusOutput) { if (_subscriptionIdNdef != 0 && _device != null) { // Ask the proximity device to stop subscribing for NDEF messages _device.StopSubscribingForMessage(_subscriptionIdNdef); _subscriptionIdNdef = 0; // Update enabled / disabled state of buttons in the User Interface UpdateUiForNfcStatus(); // Update status text for UI - only if activated if (writeToStatusOutput) { SetStatusOutput(AppResources.StatusSubscriptionStopped); } } }
private void btnSubscribeWritable_Click(object sender, RoutedEventArgs e) { ProximityDevice device = ProximityDevice.GetDefault(); // Prüfen ob NFC auf diesem Gerät verfügbar ist if (device != null) { if (_subscriptionId > -1) { device.StopSubscribingForMessage(_subscriptionId); } _subscriptionId = device.SubscribeForMessage("WriteableTag", (proximityDevice, message) => { var size = System.BitConverter.ToInt32(message.Data.ToArray(), 0); Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show(string.Format("Beschreibbarer Tag, Größe:{0}Bytes", size)); }); }); } }
/// <summary> /// When the stop subscribing button is pressed, stop listening for other devices. /// </summary> /// <param name="sender">The CoronaRuntimeEnvironment that dispatched the event.</param> /// <param name="e">Provides the Lua event table's fields/properties.</param> private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnStopSubscribeAndPublish( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { if (_subscribedMessageID != -1) { _proximityDevice.StopSubscribingForMessage(_subscribedMessageID); _subscribedMessageID = -1; } if (_publishedMessageID != -1) { _proximityDevice.StopPublishingMessage(_publishedMessageID); _publishedMessageID = -1; } // Return a success message to Lua. return(CoronaLabs.Corona.WinRT.CoronaBoxedString.From("Stopped subscribing and publishing")); }
private void MessageReceived(ProximityDevice sender, ProximityMessage message) { Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (device != null) { device.StopSubscribingForMessage(_subscriptionId); } var ndefRead = ParseNdef(message); _logText = _logText + ndefRead; ScrollViewer.UpdateLayout(); ScrollViewer.ScrollToVerticalOffset(0); SubscribeForMessage(); if (!Frame.Navigate(typeof(NfcTagDetailsPage), ndefRead)) { throw new Exception("Ooops."); } }); }
private void btnSubscribe_Click(object sender, RoutedEventArgs e) { ProximityDevice device = ProximityDevice.GetDefault(); // Prüfen ob NFC auf diesem Gerät verfügbar ist if (device != null) { if (_subscriptionId > -1) { device.StopSubscribingForMessage(_subscriptionId); } _subscriptionId = device.SubscribeForMessage( "Windows.WindowsDeveloper.MessageType", (proximityDevice, message) => Dispatcher.BeginInvoke(() => MessageBox.Show( "Nachricht empfangen " + message.DataAsString + " von " + proximityDevice.DeviceId) )); } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); proxDevice.StopSubscribingForMessage(subscriptionID); }