好吧,和往常一样,在你花时间发布问题之后,你会在某个地方找到答案…
未经授权的异常具有严重的误导性,因为缺少的是C中的以下声明:
pin.SetDriveMode(GpioPinDriveMode.Output);
public class TweetController
{
private static IGpioController _gpio = null;
private const int PIN = 17;
public TweetController()
{
_gpio = GpioController.Instance;
}
public void Tweet(int milliseconds){
var pin = _gpio.OpenPin(PIN);
pin.SetDriveMode(GpioPinDriveMode.Output); // open the gpio pin before writing or unauthorizedexception occurs
pin.Write(GpioPinValue.High);
Thread.Sleep(milliseconds);
pin.Write(GpioPinValue.Low);
}
}