[英]Unable to open UART port on Windows IoT with Raspberry Pi 3
在Raspberry Pi 3上運行的Windows IoT核心版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都短路並且不使其短路,這是行不通的...
UPDATE
如果拆分給定的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)
無設備
正如Grim所說,解決方案在這里: SerialDevice.FromIdAsync()產生一個空的串行端口
有必要添加:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
在Package.appxmanifest
文件的<Capabilities>
標記中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.