【发布时间】:2019-07-06 01:28:57
【问题描述】:
在运行在 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/devicesGET请求的记录与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.dll 中的“System.Exception”
数据无效。 (来自 HRESULT 的异常:0x8007000D)
数据无效。 (来自 HRESULT 的异常:0x8007000D)
没有设备
【问题讨论】:
-
很明显,您找到的 di.Id 字符串比存储在设备记录中的 ID 更长,即末尾包含 GUID。也许它找不到您要它查找的 ID?
-
你错了,看我的更新。
-
我怎么错了?! "ACPI\\BCM2836\\0" != "\\\\?\\ACPI#BCM2836#0#"...大声笑
标签: c# raspberry-pi uart windows-iot-core-10