Microsoft Band SDK与Windows运行时组件一起使用 [英] Microsoft Band SDK use with Windows Runtime Component

查看:75
本文介绍了Microsoft Band SDK与Windows运行时组件一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Windows运行时组件中使用Microsoft Band SDK? GetBandsAsync可以使用,但是在使用以下命令进行连接时失败:

Is it possible to use the Microsoft Band SDK from within a Windows Runtime Component? GetBandsAsync works, but it fails when connecting using:

IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0])

我正在使用Microsoft Band SDK 1.3.10518.我已将rfcomm功能添加到应用程序包清单中,但出现以下异常:

I am using Microsoft Band SDK 1.3.10518. I have added rfcomm capabilities to the app package manifest and I get a the following exception:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.Band.MarshalUtils.GetBytes[T](T& structure, Byte[] resultArray, Int32 offset)
   at Microsoft.Band.BandClient.CheckFirmwareSdkBit(FirmwareSdkCheckPlatform platform, Byte reserved)
   at Microsoft.Band.BandClientManager.<ConnectAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at BandController.Band.<StartRemoteControlAsync>d__5.MoveNext()} System.Exception {System.IO.FileNotFoundException}

要重现该错误,这是我所做的:

To reproduce the error, this is what I have done:

  1. 在Visual Studio中创建一个新的空白应用程序(Windows Phone Silverlight)
  2. 在应用程序中添加一个按钮(假设为测试乐队"),并为Tap事件添加处理程序
  3. 在解决方案中添加Windows运行时组件(Windows Phone),将其命名为BandTest,命名空间BandWrapper
  4. 将Microsoft Band SDK添加到BandWrapper项目中
  5. 在Silverlight项目的Package.appxmanifext中添加rfcomm和邻近功能(对于BandWrapper rfcomm由Microsoft Band SDK安装程序添加)
  6. 实施测试按钮处理程序,如下所示:

  1. In Visual Studio create a new Blank App (Windows Phone Silverlight)
  2. Add a button to the app (let's say "Test band") and add a handler for Tap event
  3. Add a Windows Runtime Component (Windows Phone) to the solution, call it BandTest, the namespace BandWrapper
  4. Add Microsoft Band SDK to the BandWrapper project
  5. Add rfcomm and proximity capabilities in the Package.appxmanifext of the Silverlight project (for the BandWrapper rfcomm is added by Microsoft Band SDK installer)
  6. Implement the test button handler as follows:

私有无效Button_Tap(对象发送者,System.Windows.Input.GestureEventArgs e) { BandWrapper.BandTest包装器=新的BandWrapper.BandTest(); wrapper.TestBand(); }

private void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e) { BandWrapper.BandTest wrapper = new BandWrapper.BandTest(); wrapper.TestBand(); }

,并且在public async void TestBand()方法中,SDK示例的运行时组件副本中的内容如下:

And in the runtime component copy from the SDK sample the following, in the public async void TestBand() method:

        try
        {
            // Get the list of Microsoft Bands paired to the phone/tablet/PC.
            IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
            if (pairedBands.Length < 1)
            {
                //this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                return;
            }

            // Connect to Microsoft Band.
            using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
            {
                // We'll create a Tile that looks like this:
                // +--------------------+
                // | MY CARD            | 
                // | |||||||||||||||||  | 
                // | 123456789          |
                // +--------------------+

                // First, we'll prepare the layout for the Tile page described above.
                TextBlock myCardTextBlock = new TextBlock()
                {
                    Color = Colors.Blue.ToBandColor(),
                    ElementId = 1, // the Id of the TextBlock element; we'll use it later to set its text to "MY CARD"
                    Rect = new PageRect(0, 0, 200, 25)
                };

...

如果在上面的步骤1中,我创建了Windows Phone应用(不是Silverlight),则测试方法的执行将上升到

If at the step 1. above, I create an Windows Phone app (not Silverlight) the execution of the test method goes up to

await bandClient.TileManager.AddTileAsync(myTile);

并以以下方式失败:

System.TypeLoadException: Could not find Windows Runtime type 'Windows.Foundation'.
   at System.StubHelpers.WinRTTypeNameConverter.GetTypeFromWinRTTypeName(String typeName, Boolean& isPrimitive)
   at System.StubHelpers.SystemTypeMarshaler.ConvertToManaged(TypeNameNative* pNativeType, Type& managedType)
   at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
   at Microsoft.Band.StoreApplicationPlatformProvider`2.<>c__DisplayClassd`1.<GetConsentAsync>b__a()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Band.StoreApplicationPlatformProvider`2.<GetConsentAsync>d__f`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Band.BandClient.<>c__DisplayClass6f.<<AddTileAsync>b__6c>d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at BandWrapper.BandTest.<TestBand>d__5.MoveNext()}   System.Exception {System.TypeLoadException}

推荐答案

是的,有可能! 您必须确保,当您在Windows运行时组件(通过后台任务)中测试连接时,您以前从未从正在运行的主应用程序中连接Band.即使您从Using-Statement中打开连接,并且应该释放所有资源,但Band仍在使用某些端口.在这种情况下,从Windows运行时组件连接Band将会失败.

Yes, it is possible! You have to make sure, that when you test the connection in the Windows Runtime Component (from a Background Task), you have not previously connected the Band from the running main app. Even when you open a connection from within a Using-Statement and all resources should be released, there still is some port in use with the Band. In that case, connecting the Band from the Windows Runtime Component will fail.

这篇关于Microsoft Band SDK与Windows运行时组件一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆