我想要实现的是扫描我的本地网络,寻找连接的设备。我了解到我需要构造一个选择器并将其传递给函数。
DeviceInformation.FindAllAsync()例如。然而,问题是所有这些都需要System.Devices名称空间,例如
System.Devices.InterfaceClassGuid:="{2eef81be-33fa-4800-9670-1cd474972c3f}"我得到这样一个错误:"Error CS0234类型或命名空间名称'Devices‘在命名空间'System’中不存在(您是否缺少程序集引用?)“。
我怀疑这是因为我不知何故错过了库。我尝试使用System.Devices,但名称空间中同样不存在名称空间。我也尝试在引用管理器中添加它,但也没有这样的库。我在网上找不到图书馆。
此外,我也不是很确定如何构造AQS字符串。
DeviceInformationCollection collection = await DeviceInformation.FindAllAsync(DeviceClass.ImageScanner);这是可以的,但只显示本地设备。
var selector = System.Device.Aep.ProtocolId:= "{37aba761-2124-454c-8d82-c42962c2de2b}";这会产生错误,一个具有名称空间和更多语法约束的错误。
我希望将选择器传递给函数,但我遗漏了名称空间,System.Devices和AQS字符串不起作用。
发布于 2019-02-15 16:11:50
看起来这不是一个命名空间。它们是窗口属性,请检查窗口属性。
System.Devices不是命名空间。他们是。如果您想枚举设备,则需要使用DeviceWatcher来捕获匹配条件设备。
DeviceWatcher deviceWatcher = DeviceInformation.CreateWatcher(
"", // AQS Filter string
null, // requested properties
deviceInfoKind);这是你可以参考的official code sample。
发布于 2021-05-29 09:31:06
"DeviceWatcher“听起来很棒--它说:
“构建示例
Start Visual Studio and select File > Open > Project/Solution.
Go to the directory to which you unzipped the sample. Then go to the subdirectory containing the sample in the language you desire - either C++, C#, or JavaScript. Double-click the Visual Studio Solution (.sln) file.
Select the appropriate target: x86, x64, ARM. Press Ctrl+Shift+B, or select Build > Build Solution.啊,但是问题来了:
“找不到类型或命名空间'System‘。”
它在所有标题行中都提供了"using System;“,但要求"using Windows;”,并拒绝了所有其他行。
想一想-
https://stackoverflow.com/questions/54691501
复制相似问题