Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net NET中GattDeviceServicesResult的正确库或运行时_.net_Bluetooth Lowenergy_Lib - Fatal编程技术网

.net NET中GattDeviceServicesResult的正确库或运行时

.net NET中GattDeviceServicesResult的正确库或运行时,.net,bluetooth-lowenergy,lib,.net,Bluetooth Lowenergy,Lib,更新 我现在有理由相信你不能在企业LTSB上使用Windows Creator,因为版本不够高,无法更新!如果有人能证实这一点,并说明我应该如何着手开发一个蓝牙应用程序,鉴于我可以使用Creator,我将不胜感激 “找不到Windows运行时类型'Windows.Devices.Bluetooth.GenerictTributeProfile.GattDeviceServicesResult'” 我在我的开发人员机器上开发了一些示例代码,以便通过C#/.Net中的BLE(蓝牙低能)进行通信。当我

更新 我现在有理由相信你不能在企业LTSB上使用Windows Creator,因为版本不够高,无法更新!如果有人能证实这一点,并说明我应该如何着手开发一个蓝牙应用程序,鉴于我可以使用Creator,我将不胜感激

“找不到Windows运行时类型'Windows.Devices.Bluetooth.GenerictTributeProfile.GattDeviceServicesResult'”

我在我的开发人员机器上开发了一些示例代码,以便通过C#/.Net中的BLE(蓝牙低能)进行通信。当我将这个发行版文件夹转移到另一台机器上并运行程序时,当我尝试启动BLE通信时,会收到上面的消息。我猜我丢失了一些关键库/dll(或.NETCore或.netframework),但是什么呢?我搜索过了,找不到答案

一个可能有用的线索(或可能无关)是,在我的项目中,我在目录C:\Program Files(x86)\reference Assemblys\Microsoft\Framework.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll中引用了System.Runtime.WindowsRuntime 另一台机器没有v4.5.1,只有v4.5。然而,当我尝试安装v4.5.1时,我被告知我已经有了一个更新的版本!也许有人能告诉我如何在机器上获取.netcore v4.5.1

谢谢, 戴夫

更多信息。在原始项目中,有一个路径为C:\Program Files(x86)\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd的参考“Windows” 如果使用对象浏览器,您将看到Windows.Devices.Bluetooth.GenerictTributeProfile.GattDeviceServicesResult 这个相同的文件(相同的版本)也在我试图运行代码的系统上。不确定为什么它在运行时没有“看到”它

显然,其他人也有这个问题。见:

但更多的信息基于研究
我在生产机器上安装了VisualStudio,认为这将消除我的开发人员机器和生产机器之间的一个差异。还是不走运。然而,我要指出,剩下的一个区别是,我的开发人员机器有Windows10Pro。生产机器(平板电脑)具有Windows 10 Enterprise 2016 LTSB

似乎Windows 10 Enterprise不支持
Windows.Devices.Bluetooth
命名空间中的许多方法。我找到的解决方案要求Windows 10 Enterprise用户将他们的设备配对。这允许我们使用过时的
BluetoothLEDevice.GattServices
属性。我们捕获
TypeLoadException
,然后返回到windows10enterprise中支持的方法

    private async Task<IReadOnlyCollection<GattDeviceService>> GetGattService(BluetoothLEDevice device, Guid uuid)
    {
        try
        {
            // Try to get the services async first
            return await GetGattServicesAsync(device, uuid);
        }
        catch(TypeLoadException e)
        {
            // Not supported in version of windows. Fall back to old way
            return GetGattDeviceServices(device, uuid);
        }
    }

    private async Task<IReadOnlyList<GattDeviceService>> GetGattServicesAsync(BluetoothLEDevice device, Guid uuid)
    {
        var result = await Device.GetGattServicesForUuidAsync(uuid);
        if(result.Status == GattCommunicationStatus.Success)
        {
            return result.Services;
        }
        return null;
    }

    private IReadOnlyList<GattDeviceService> GetGattDeviceServices(BluetoothLEDevice device, Guid uuid)
    {
        var result = device.GattServices.Where(s => s.Uuid == uuid);
        if(result != null)
        {
            return result.ToList().AsReadOnly();
        }
        return null;
    }
专用异步任务GetGattService(蓝牙设备,Guid uuid)
{
尝试
{
//首先尝试使服务异步
返回等待GetGattServicesAsync(设备,uuid);
}
catch(TypeLoadException e)
{
//windows版本不支持。请返回到旧方式
返回GetGattDeviceServices(设备,uuid);
}
}
专用异步任务GetGattServicesAsync(蓝牙设备,Guid uuid)
{
var result=wait Device.getgattservicesfouruidasync(uuid);
if(result.Status==GattCommunicationStatus.Success)
{
返回结果。服务;
}
返回null;
}
专用IReadOnlyList GetGattDeviceServices(蓝牙设备,Guid uuid)
{
var result=device.GattServices.Where(s=>s.Uuid==Uuid);
如果(结果!=null)
{
返回result.ToList().AsReadOnly();
}
返回null;
}

在尝试从服务中获取特征时,我们也需要这样做。我们不调用
GattDeviceService.getcharacteristicsfouidasync
而是调用
GattDeviceService.GetAllCharacteristics()
。我还发现一些PC不支持任何
BluetoothLEDevice.GetDeviceSelector()
方法的情况,这导致创建观察程序时出现问题。必须配对设备有点不方便。不幸的是,我没有找到任何关于这方面的文档。除了几段视频,他们讨论不再需要对BLE设备进行配对,这让我相信LTSB不支持它。

似乎您正在尝试在.NET Framework应用程序中使用UWP命名空间,您应该只在UWP应用程序中使用它,如示例项目Lex。你说得对。我正在WPF应用程序中使用一些UWP的东西。然而,我已经在我的开发机器上成功地完成了它。我只需要让应用程序在生产机器上运行。我听说你可以使用通用应用程序库来创建一个普通的WPF应用程序。如果需要的话,我会找到推荐人的。谢谢你的关注!我不知道你能找到什么样的推荐信。显然,微软只计划授予对.NET Core 3.0和.NET Framework 4.8中完整Windows 10 API的访问权。除非微软表示支持,否则我不会相信任何其他API。你链接的答案是“请注意,#2版本取决于你正在使用的.NET版本”。在UWP中,GAC(或者现在可能将其与exe捆绑在一起?)处理查找特定安装的兼容dll(在prod机器上),在您的情况下,如果它要工作,您需要明确知道该位置。您可以将其复制到
/lib/
文件夹中,并从那里更可靠地导入,但这也可能会导致问题