IAsyncOperation<SerialDevice> FromIdAsync(string deviceId) returns 空
IAsyncOperation<SerialDevice> FromIdAsync(string deviceId) returns null
我有 Windows IoT Core 10 17744 运行 超过 Raspberry Pi 3.
我尝试使用以下代码从 UWP 应用程序初始化 COM 端口:
string aqs = SerialDevice.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqs);
List<DeviceInformation> list = devices.ToList();
DeviceInformation di = list.First();
_serial_port = await SerialDevice.FromIdAsync(di.Id);
我有 di.Id
-> \?\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
di
变量的完整表示如下:
- di {Windows.Devices.Enumeration.DeviceInformation} Windows.Devices.Enumeration.DeviceInformation
EnclosureLocation null Windows.Devices.Enumeration.EnclosureLocation
Id "\\?\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}" string
IsDefault false bool
IsEnabled true bool
Kind DeviceInterface Windows.Devices.Enumeration.DeviceInformationKind
Name "MINWINPC" string
- Pairing {Windows.Devices.Enumeration.DeviceInformationPairing} Windows.Devices.Enumeration.DeviceInformationPairing
CanPair false bool
+ Custom {Windows.Devices.Enumeration.DeviceInformationCustomPairing} Windows.Devices.Enumeration.DeviceInformationCustomPairing
IsPaired false bool
ProtectionLevel None Windows.Devices.Enumeration.DevicePairingProtectionLevel
Native View To inspect the native object, enable native code debugging.
+ Properties {System.__ComObject} System.Collections.Generic.IReadOnlyDictionary<string, object> {System.__ComObject}
Native View To inspect the native object, enable native code debugging.
但是在 await
操作后我在 _serial_port
.
中有 null
更新
即使我将Raspberry UART接口连接到工作节点也是null
:
第 8 个引脚作为 TX 到配对的 RX 线。
第 10 个引脚作为 RX 到配对的 TX 线。
更新
我在清单中有 DeviceCapability
:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
您需要在Package.appxmanifest中添加串行设备功能:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
It is null even if I connect Raspberry UART interface to working node:
8th pin as TX to paired RX line. 10th pin as RX to paired TX line.
这不是 SerialDevice.FromIdAsync() 成功所必需的。即使您不连接这些引脚,如果代码和设置正确,SerialDevice.FromIdAsync() 也可以获得有效设备。可以参考Serial UART Sample.
我有 Windows IoT Core 10 17744 运行 超过 Raspberry Pi 3.
我尝试使用以下代码从 UWP 应用程序初始化 COM 端口:
string aqs = SerialDevice.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqs);
List<DeviceInformation> list = devices.ToList();
DeviceInformation di = list.First();
_serial_port = await SerialDevice.FromIdAsync(di.Id);
我有 di.Id
-> \?\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
di
变量的完整表示如下:
- di {Windows.Devices.Enumeration.DeviceInformation} Windows.Devices.Enumeration.DeviceInformation
EnclosureLocation null Windows.Devices.Enumeration.EnclosureLocation
Id "\\?\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}" string
IsDefault false bool
IsEnabled true bool
Kind DeviceInterface Windows.Devices.Enumeration.DeviceInformationKind
Name "MINWINPC" string
- Pairing {Windows.Devices.Enumeration.DeviceInformationPairing} Windows.Devices.Enumeration.DeviceInformationPairing
CanPair false bool
+ Custom {Windows.Devices.Enumeration.DeviceInformationCustomPairing} Windows.Devices.Enumeration.DeviceInformationCustomPairing
IsPaired false bool
ProtectionLevel None Windows.Devices.Enumeration.DevicePairingProtectionLevel
Native View To inspect the native object, enable native code debugging.
+ Properties {System.__ComObject} System.Collections.Generic.IReadOnlyDictionary<string, object> {System.__ComObject}
Native View To inspect the native object, enable native code debugging.
但是在 await
操作后我在 _serial_port
.
更新
即使我将Raspberry UART接口连接到工作节点也是null
:
第 8 个引脚作为 TX 到配对的 RX 线。
第 10 个引脚作为 RX 到配对的 TX 线。
更新
我在清单中有 DeviceCapability
:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
您需要在Package.appxmanifest中添加串行设备功能:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
It is null even if I connect Raspberry UART interface to working node: 8th pin as TX to paired RX line. 10th pin as RX to paired TX line.
这不是 SerialDevice.FromIdAsync() 成功所必需的。即使您不连接这些引脚,如果代码和设置正确,SerialDevice.FromIdAsync() 也可以获得有效设备。可以参考Serial UART Sample.