Microsofts Nuget Package:“Remote Wiring” “System.AcessViolationException”中的示例结果 [英] Microsofts Nuget Package: "Remote Wiring" Example Results in "System.AcessViolationException"

查看:58
本文介绍了Microsofts Nuget Package:“Remote Wiring” “System.AcessViolationException”中的示例结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力获得Microsoft IoT Nuget Package"Remote Wiring"。使用github中的一个示例工作:  https://github.com/ms-iot/remote-wiring#arduino-setup

I am trying to get the Microsoft IoT Nuget Package "Remote Wiring" working using one of their examples from github: https://github.com/ms-iot/remote-wiring#arduino-setup

我做的唯一修改就是改变了"BluetoothUsbSerial"。到"UsbSerial"同时确保也更新清单文件中的XML块,如底部教程中所述。 

The only modification I made was changing the "BluetoothUsbSerial" to "UsbSerial" while being sure to also update the XML block in the manifest file as mentioned in that tutorial at the bottom. 

但是当我尝试在我的Raspberry Pi 3 B上部署应用程序时,运行Win10 IoT核心(v10.0.17763.107)我从设置Arduino引脚"A0"的行中得到以下错误: as analog:

However when I attempt to deploy the app on my Raspberry Pi 3 B, running Win10 IoT Core (v10.0.17763.107) I get the following error from the line that sets up Arduino pin "A0" as analog:

" System.AccessViolationException:'尝试读取或写入受保护的内存。这通常表明其他内存已损坏。'"

"System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'"

我的主要代码如下:

using Microsoft.Maker.RemoteWiring; using Microsoft.Maker.Serial; using System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace MattRemoteWiringTest0 { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class MainPage : Page { IStream connection; RemoteDevice arduino; public MainPage() { this.InitializeComponent(); SetupRemoteArduino(); Setup(); bool looping = true; while (looping) { ReadAndReport(); } } public void SetupRemoteArduino() { //create a bluetooth connection and pass it to the RemoteDevice //I am using a constructor that accepts a device name or ID. connection = new UsbSerial("MyUsbDevice"); arduino = new RemoteDevice(connection); //add a callback method (delegate) to be invoked when the device is ready, refer to the Events section for more info arduino.DeviceReady += Setup; //always begin your IStream connection.begin(115200, SerialConfig.SERIAL_8N1); } //treat this function like "setup()" in an Arduino sketch. public void Setup() { //set digital pin 13 to OUTPUT arduino.pinMode(13, PinMode.OUTPUT); //set analog pin A0 to ANALOG INPUT arduino.pinMode("A0", PinMode.ANALOG); } //This function will read a value from our ANALOG INPUT pin A0 (range: 0 - 1023) and set pin 13 HIGH if the value is >= 512. public void ReadAndReport() { UInt16 val = arduino.analogRead("A0"); if (val >= 127) { arduino.digitalWrite(13, PinState.HIGH); } else { arduino.digitalWrite(13, PinState.LOW); } }


}

}

} }

寻找帮助解决这个问题。谢谢

Looking for help resolving this. Thanks

推荐答案

Hello  Elite83,

Hello Elite83,

您以错误的方式调用以下代码:

You call the following code in wrong way:

            Setup();

            bool looping = true;
            while (looping)
            {
                ReadAndReport();
            }

正确的方法是在收到指示连接成功建立的DeviceReady事件后调用上面的代码。因此,文档示例在DeviceReady事件中调用这些代码。

The right way is call above code after you received the DeviceReady event that indicate the connection established successfully. So as the document example call these code in in DeviceReady event.

public MainPage()
{
    connection = new BluetoothSerial( "myDevice" );	//use the name directly or use BluetoothSerial.listAvailableDevicesAsync to enumerate all devices and provide one in this constructor
    arduino = new RemoteDevice( connection );
    arduino.DeviceReady += OnDeviceReady();
    connection.begin( 115200, SerialConfig.SERIAL_8N1 ); //using my Bluetooth device's baud rate, StandardFirmata configured to match
}

private void OnDeviceReady()
{
	arduino.pinMode( 9, PinMode.SERVO );
	loop();
}

对于您的代码,您需要从MainPage()中删除  Setup()和  while(循环){}并且代码(编辑的部分)将是这样的:

For your code you need remove Setup() and while (looping){} from MainPage() and the code (edited parts) will like this:

        public MainPage()
        {
            this.InitializeComponent();

            SetupRemoteArduino();
        }


        public void Setup()
        {
            //set digital pin 13 to OUTPUT
            arduino.pinMode(13, PinMode.OUTPUT);

            //set analog pin A0 to ANALOG INPUT
            arduino.pinMode("A0", PinMode.ANALOG);

            bool looping = true;
            while (looping)
            {
                ReadAndReport();
            }
        }

如果有帮助请告诉我。

祝你好运,

Rita


这篇关于Microsofts Nuget Package:“Remote Wiring” “System.AcessViolationException”中的示例结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆