简体   繁体   English

使用Raspberry Pi 3无法在Windows IoT上打开UART端口

[英]Unable to open UART port on Windows IoT with Raspberry Pi 3

I have null in the serial port after I open the SerialDevice in C# on Windows IoT Core 10 running on Raspberry Pi 3. 在Raspberry Pi 3上运行的Windows IoT核心版10上用C#打开SerialDevice后,串行端口中没有null。

Here is the code: 这是代码:

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 is null . serialPortnull

di.Id equals: Id "\\\\\\\\?\\\\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}" string di.Id等于: Id "\\\\\\\\?\\\\ACPI#BCM2836#0#{86e0d1e0-8089-11d0-9ce4-08003e301f73}" string

list.Count equal 1 list.Count等于1

Here are two records from /api/devicemanager/devices GET request related to UART : 这是/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
},

I tried both to short circuit Rx and Tx and to not shortly circuit it, it doesn't works... 我试图将Rx和Tx都短路并且不使其短路,这是行不通的...

UPDATE UPDATE

If I split the given ID, I have Invalid data exception. 如果拆分给定的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; }

The output: 输出:

Exception thrown: 'System.Exception' in mscorlib.ni.dll 引发异常:mscorlib.ni.dll中的“ System.Exception”
The data is invalid. 数据无效。 (Exception from HRESULT: 0x8007000D) (来自HRESULT的异常:0x8007000D)
The data is invalid. 数据无效。 (Exception from HRESULT: 0x8007000D) (来自HRESULT的异常:0x8007000D)
No device 无设备

As Grim said, the solution is here: SerialDevice.FromIdAsync() yields a null serial port 正如Grim所说,解决方案在这里: SerialDevice.FromIdAsync()产生一个空的串行端口

It is necessary to add: 有必要添加:

<DeviceCapability Name="serialcommunication">
  <Device Id="any">
    <Function Type="name:serialPort" />
  </Device>
</DeviceCapability>

in the <Capabilities> tag in Package.appxmanifest file. Package.appxmanifest文件的<Capabilities>标记中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM