SubscribeForMessage() public method

public SubscribeForMessage ( [ messageType, [ messageReceivedHandler ) : long
messageType [
messageReceivedHandler [
return long
        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);
        }
Example #2
0
        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();
        }
Example #3
0
 // no args
 public void registerNdef(string args)
 {
     Debug.WriteLine("Registering for NDEF");
     proximityDevice = ProximityDevice.GetDefault();
     subscribedMessageId = proximityDevice.SubscribeForMessage("NDEF", MessageReceivedHandler);
     DispatchCommandResult();
 }
Example #4
0
 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");
 }
Example #5
0
 public void SetProximityDevice(ProximityDevice pdevice)
 {
     if (pdevice != null)
     {
         _proximity = pdevice;
         _subscribedMessageId = _proximity.SubscribeForMessage("NDEF", messageReceived);
         _peerFinderStarted = true;
     }
     else
         this.NotifyUser("NFC Device could not be found...", NotifyType.ErrorMessage);
 }
        /// <summary>
        /// このページがフレームに表示されるときに呼び出されます。
        /// </summary>
        /// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter
        /// プロパティは、通常、ページを構成するために使用します。</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (proximityDevice != null)
            {
                //カード検出(うっとうしいのでコメントアウト)
                //proximityDevice.DeviceArrived += DeviceArrived;
                //proximityDevice.DeviceDeparted += DeviceDeparted;

                //メッセージ受信
                //proximityDevice.SubscribeForMessage("NDEF", messageReceived);         //例外発生
                //proximityDevice.SubscribeForMessage("NDEF:wkt", messageReceived);     //例外発生
                //複数設定は可能なようだ。
                proximityDevice.SubscribeForMessage("NDEF:wkt.T", messageReceived);   //TEXT
                proximityDevice.SubscribeForMessage("NDEF:wkt.U", messageReceived);   //URI
                proximityDevice.SubscribeForMessage("NDEF:wkt.Sp", messageReceived);  //SmartPoster
            }
            else
            {
                MessageDialog dlg = new MessageDialog("NFC R/Wがありません", "No R/W");
            }
        }
Example #7
0
 void ProximityDevice_SubscribeForMessage(object sender, RoutedEventArgs e)
 {
     if (_subscribedMessageId == -1)
     {
         _subscribedMessageId = _proximityDevice.SubscribeForMessage("Windows.SampleMessageType", MessageReceived);
         rootPage.NotifyUser("Subscribed for proximity message, enter proximity to receive.", NotifyType.StatusMessage);
     }
     else
     {
         rootPage.NotifyUser("This sample only supports subscribing for one message at a time.", NotifyType.ErrorMessage);
     }
 }
Example #8
0
 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;
     }
 }
 private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         if (pivot.SelectedIndex == 0)
         {
             deviceId = device.SubscribeForMessage("NDEF", messageReceived);
         }
         else if (pivot.SelectedIndex == 1)
         {
             User user = controller.getUser();
             if (user != null)
             {
                 textBoxName.Text = user.Firstname + " " + user.Lastname;
             }
             device.StopSubscribingForMessage(deviceId);
             if (checkIfAlarmReportIsEmpty())
             {
                 updateAlarmReportDateTime();
             }
         }
         else if (pivot.SelectedIndex == 3)
         {
             device.StopSubscribingForMessage(deviceId);
             int nfcs         = controller.getLocalStorageNFCs();
             int alarmReports = controller.getLocalStorageAlarmReports();
             int customers    = controller.getLocalStorageCustomers();
             textBlockPendingNFCScans.Text     = AppResources.PendingNFC + " " + nfcs;
             textBlockPendingAlarmReports.Text = AppResources.PendingAlarmReports + " " + alarmReports;
             textBlockPendingCustomers.Text    = AppResources.PendingCustomers + " " + customers;
             tempAlarmReportScroll.Children.Clear();
             List <AlarmReport> tempAlarmReports = controller.getLocalStorageTempAlarmReports();
             for (int i = 0; i < tempAlarmReports.Count; i++)
             {
                 TextBlock textBlock = new TextBlock();
                 textBlock.Text     = tempAlarmReports[i].CustomerName + "\r\n" + tempAlarmReports[i].CustomerNumber + "\r\n" + tempAlarmReports[i].Time;
                 textBlock.Tap     += myTextBlock_Tap;
                 textBlock.FontSize = 25;
                 textBlock.Name     = "" + (i + 1);
                 tempAlarmReportScroll.Children.Add(textBlock);
             }
         }
     }
     catch (NullReferenceException)
     {
         MessageBox.Show(AppResources.ReportNFCDisabled);
     }
 }
Example #10
0
 public NFCTest()
 {
     this.InitializeComponent();
     proxDevice = ProximityDevice.GetDefault();
     if (proxDevice != null)
     {
         proxDevice.DeviceArrived  += DeviceArrived;
         proxDevice.DeviceDeparted += DeviceDeparted;
         proxDevice.SubscribeForMessage("NDEF", messagedReceived);
     }
     else
     {
         WriteMessageText("No proximity device found\n");
         WriteMessageText("No proximity device found\n");
     }
 }
        public void InitializeProximityDevice()
        {
            proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

            if (proximityDevice != null)
            {
                proximityDevice.DeviceArrived += ProximityDeviceArrived;
                proximityDevice.DeviceDeparted += ProximityDeviceDeparted;
                proximityDevice.SubscribeForMessage("NDEF", messageReceivedHandler);
                WriteMessageText("Proximity device initialized.\n");
            }
            else
            {
                WriteMessageText("Failed to initialized proximity device.\n");
            }
        }
Example #12
0
        private void SubscribeForMessageButton_Click(object sender, RoutedEventArgs e)
        {
            if (proximityDevice == null)
            {
                proximityDevice = ProximityDevice.GetDefault();
            }

            // Make sure NFC is supported
            if (proximityDevice != null)
            {
                // Only subscribe for the message one time.
                if (subscribedMessageId == -1)
                {
                    subscribedMessageId =
                        proximityDevice.SubscribeForMessage("Windows.JumpstartMessageType", messageReceived);
                }
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string beers = "";

            if (NavigationContext.QueryString.TryGetValue("beers", out beers))
            {

                beersTextBox.Text = beers;
            }

            System.Diagnostics.Debug.WriteLine("initializing");

            device = ProximityDevice.GetDefault();

            long subscribedMessageId = device.SubscribeForMessage("NDEF", messageReceivedHandler);
        }
        private void SetupNfcButton_Click(object sender, RoutedEventArgs e)
        {
            CanvasBorder.Visibility = System.Windows.Visibility.Collapsed;

            SceneViewModel svm = (scenesMainListBox.SelectedItem as SceneViewModel);
            if (svm != null)
            {
                if (App.SupportsNFC)
                {
                    if (_proximityDevice == null)
                    {
                        _proximityDevice = ProximityDevice.GetDefault();
                        if (_proximityDevice != null)
                            subid = _proximityDevice.SubscribeForMessage("WriteableTag", OnWriteableTagArrived);

                        MessageBox.Show("Place the writeable tag near your device, then hit ok.");
                    }

                }
                else
                {
                    MessageBox.Show("I could not detect a NFC sensor on this device");
                }

            }
        }
Example #15
0
        private void initNFC()
        {
            // Initialize NFC
            _proximitiyDevice = ProximityDevice.GetDefault();

            if (_proximitiyDevice == null)
            {
                Debug.WriteLine("It seems this is not NFC-available device");
                MessageBox.Show(AppResources.Error_NFC_NotSupported, AppResources.Title_error, MessageBoxButton.OK);
                return;
            }

            _subscriptionIdNdef = _proximitiyDevice.SubscribeForMessage("NDEF", NFCMessageReceivedHandler);
        }
Example #16
0
        private void InitializeProximityDevice()
        {
            _device = Windows.Networking.Proximity.ProximityDevice.GetDefault();
            if (_device != null)
            {
                _subscriptionIdNdef = _device.SubscribeForMessage("NDEF", MessageReceivedHandler);

            }
<<<<<<< HEAD

        }
Example #17
0
 private void scanButton_Click(object sender, RoutedEventArgs e)
 {
     device.SubscribeForMessage("NDEF", messageReceived);
     //  Debug.WriteLine("Published Message. ID is {0}", Id);
 }
Example #18
0
 private NFCHelper()
 {
     // Initialize NFC
       _device = ProximityDevice.GetDefault();
       _device.SubscribeForMessage("NDEF", MessageReceivedHandler);
 }