[错误] WinRT信息:无法打开设备的句柄。当试图打开LED的Pin时 [英] [ERROR] WinRT information: Failed to open a handle to the device. when trying to open a Pin for a LED
问题描述
您好
当我尝试使用以下代码打开PIN时,我在通用应用程序中收到以下异常
I'm getting the following exception in an Universal App when I try open a PIN with the following code
GpioPin _pinD4;
var gpio = GpioController.GetDefault();
_pinD4 = gpio.OpenPin(8);
异常消息是这个
任何想法?
其他一切似乎在通用应用中运行良好,我可以使用鼠标控制应用程序,等等。
Everything else seems to works fine in a Universal App, I get control over the app using the mouse, etc.
问候
/ El Bruno
/El Bruno
MVP ALM(@ elbruno)http://twitter.com/elbruno htt p://www.elbruno.com
MVP ALM (@elbruno) http://twitter.com/elbruno http://www.elbruno.com
推荐答案
如果你运行与blinky示例中相似的代码,那么它是否适合你&NBSP?;在您的代码中,您没有在尝试获取默认值后检查gpio是否为null,因此可能是问题。
If you run the similar code as is in the blinky sample, does that work for you? In your code you're not checking if gpio is null after trying to get the default, so that could be the issue.
using Windows.Devices.Gpio;
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
pin = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
pin = gpio.OpenPin(LED_PIN);
// Show an error if the pin wasn't initialized properly
if (pin == null)
{
GpioStatus.Text = "There were problems initializing the GPIO pin.";
return;
}
pin.Write(GpioPinValue.High);
pin.SetDriveMode(GpioPinDriveMode.Output);
GpioStatus.Text = "GPIO pin initialized correctly.";
}
这篇关于[错误] WinRT信息:无法打开设备的句柄。当试图打开LED的Pin时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!