我在Raspberry Pi 3上运行的Windows IoT Core 10上以C#打开SerialDevice后,串行端口中有null。
这是代码:
string aqs = SerialDevice.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqs);
List<DeviceInformation> list = devices.ToList();
DeviceInformation di = list.First();
serialPort = await SerialDevice.FromIdAsync(di.Id);
serialPort
是null
.
di.Id
等于:Id "\\?\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}" string
list.Count
等1
以下是/api/devicemanager/devices
GET
请求中与UART
相关的两条记录:
{
"Class": "Ports",
"Description": "BCM283x Mini UART Serial Device",
"ID": "ACPI\BCM2836\0",
"Manufacturer": "Microsoft",
"ParentID": "ACPI_HAL\PNP0C08\0",
"ProblemCode": 0,
"StatusCode": 25182218
},
{
"Class": "System",
"Description": "ARM PL011 UART Device Driver",
"ID": "ACPI\BCM2837\4",
"Manufacturer": "Microsoft",
"ParentID": "ACPI_HAL\PNP0C08\0",
"ProblemCode": 0,
"StatusCode": 25165834
},
我尝试短路 Rx 和 Tx,但不要短路它,它不起作用......
更新
如果我拆分给定的 ID,我Invalid data
例外。
string aqs = SerialDevice.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqs);
List<DeviceInformation> list = devices.ToList();
DeviceInformation di = list.First();
string id = "{86e0d1e0-8089-11d0-9ce4-08003e301f73}";
try { serialPort = await SerialDevice.FromIdAsync(id); } catch(Exception e) { Debug.WriteLine(e.Message); }
id = "\\?\ACPI#BCM2836#0#";
try { serialPort = await SerialDevice.FromIdAsync(id); } catch(Exception e) { Debug.WriteLine(e.Message); }
id = di.Id;
try { serialPort = await SerialDevice.FromIdAsync(id); } catch(Exception e) { Debug.WriteLine(e.Message); }
if (serialPort == null) { Debug.WriteLine("No device"); return; }
输出:
引发的异常:mscorlib.ni 中的"System.Exception".dll数据
无效。(HRESULT的例外:0x8007000D)
数据无效。(HRESULT的例外:0x8007000D)
无设备
正如Grim所说,解决方案在这里:SerialDevice.FromIdAsync()产生一个空串行端口
有必要补充:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
在Package.appxmanifest
文件中的<Capabilities>
标记中。