Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WindowsIotCore Raspberry Pi UWP串行端口访问问题(System.AccessViolationException)_C#_Uwp_Raspberry Pi_Windows 10 Iot Core - Fatal编程技术网

C# WindowsIotCore Raspberry Pi UWP串行端口访问问题(System.AccessViolationException)

C# WindowsIotCore Raspberry Pi UWP串行端口访问问题(System.AccessViolationException),c#,uwp,raspberry-pi,windows-10-iot-core,C#,Uwp,Raspberry Pi,Windows 10 Iot Core,我正在尝试使用Raspberry Pi 3的串行pin作为WindowsIotCore平台上UWP应用程序的输入。我一直得到这样的例外: System.AccessViolationException HResult=0x80004003 Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 发生此异常的代码是: Serial

我正在尝试使用Raspberry Pi 3的串行pin作为WindowsIotCore平台上UWP应用程序的输入。我一直得到这样的例外:

System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an 
indication that other memory is corrupt.
发生此异常的代码是:

SerialDevice serialPort = null;
string aqs = SerialDevice.GetDeviceSelector();
var dis = await DeviceInformation.FindAllAsync(aqs);
serialPort = await SerialDevice.FromIdAsync(dis[0].Id);
serialPort.WriteTimeout = TimeSpan.FromMilliseconds(500);
serialPort.ReadTimeout = TimeSpan.FromMilliseconds(200);
serialPort.BaudRate = 9600;
serialPort.Parity = SerialParity.None;
serialPort.StopBits = SerialStopBitCount.One;
serialPort.DataBits = 8;
serialPort.Handshake = SerialHandshake.None;
更新:
我创建了一个新的UWP项目,使用相同的代码,在相同的平台上,在相同的Raspberry Pi上,使用相同的开发PC,代码运行良好。

我通过使用记事本编辑package.appxmanifest文件来解决这个问题++
我已经通过visual studio 2017编辑了package.appxmanifest文件,但是我再次检查,由于某些原因,通过visual studio 2017对该文件所做的任何编辑都不会被保存。使用外部编辑器编辑文件后,我发现代码没有问题。问题现在解决了。

检查那些
wait
ed函数调用的返回值——非常确定您得到的是
TResult
,而不是您期望的实际类型调试后,我发现每当调用并设置serialPort变量的属性时,代码都会出现异常,serialPort=wait SerialDevice.FromIdAsync(dis[0].Id);此命令应将serialPort变量设置为所选的串行设备,但该变量保持为空。我在同一平台上的新项目中也使用了此变量,它工作得非常好then@daniyalselani如果SerialDevice.FromIdAsync(dis[0].Id)重新运行null,则需要检查设备功能(
)是否已添加到package.appxmanifest。@RitaHan MSFT,我已经通过visual studio编辑了package.appxmanifest文件,但是我再次检查,由于某些原因,通过visual studio对该文件所做的任何编辑都未保存。在使用外部编辑器编辑该文件后,我发现代码没有问题。问题现在已解决。谢谢你好,daniyal,问题已经解决,您可以接受您的解决方案作为答案。如何获取您可以参考的答案。这是一个:“Visual Studio 2017在清单设计器中存在影响串行通信功能的已知错误。如果您的appxmanifest添加了串行通信功能,则使用设计器修改appxmanifest将损坏您的appxmanifest(设备xml子项将丢失)。您可以通过在appxmanifest上单击鼠标右键并从关联菜单中选择“查看代码”手动编辑appxmanifest来解决此问题。“