public bool TryOpenPin(Int32 pinNumber, GpioSharingMode sharingMode, GpioPin pin, GpioOpenStatus openStatus) { return(false); }
public PinViewModel(string name, GpioOpenStatus status, GpioPin pin) { Name = name; Status = status.ToString(); this.pin = pin; Number = pin.PinNumber; }
int AS7000_GPIO_Init() { var gpio = GpioController.GetDefault(); if (gpio == null) { return(-1); } try { GpioOpenStatus openStatus = 0; gpio.TryOpenPin(AS7000_GPIO_POWER_PIN, GpioSharingMode.Exclusive, out PwrPin, out openStatus); PwrPin.SetDriveMode(GpioPinDriveMode.Output); gpio.TryOpenPin(AS7000_GPIO_INT_PIN, GpioSharingMode.Exclusive, out IntPin, out openStatus); IntPin.SetDriveMode(GpioPinDriveMode.Input); //// EV3 New gpio.TryOpenPin(AS7000_GPIO_LEDEN_PIN, GpioSharingMode.Exclusive, out LedEnPin, out openStatus); LedEnPin.SetDriveMode(GpioPinDriveMode.Output); } catch (Exception ex) { return(-1); } return(1); }
public void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to perform background work // // If you start any asynchronous methods here, prevent the task // from closing prematurely by using BackgroundTaskDeferral as // described in http://aka.ms/backgroundtaskdeferral // //Take a service deferral so the service isn't terminated try { serviceDeferral = taskInstance.GetDeferral(); taskInstance.Canceled += OnTaskCanceled; _taskInstance = taskInstance; pinStatus = GpioOpenStatus.UnknownError; gpioController = GpioController.GetDefault(); var details = taskInstance.TriggerDetails as AppServiceTriggerDetails; if (details != null) { connection = details.AppServiceConnection; //Listen for incoming app service requests connection.RequestReceived += OnRequestReceived; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private Boolean InitGPIO() { var gpio = GpioController.GetDefault(); if (gpio == null) { return(false); } GpioOpenStatus status = new GpioOpenStatus(); var open = gpio.TryOpenPin(ad5360_GPIO_Pins.ad5360_LDAC, GpioSharingMode.Exclusive, out GPIO_LDAC, out status); if (open == true) { GPIO_LDAC.Write(GpioPinValue.Low); GPIO_LDAC.SetDriveMode(GpioPinDriveMode.Output); } open = gpio.TryOpenPin(ad5360_GPIO_Pins.ad5360_BUSY, GpioSharingMode.Exclusive, out GPIO_Busy, out status); if (open == true) { GPIO_Busy.SetDriveMode(GpioPinDriveMode.Input); GpioPinValue tmp = GPIO_Busy.Read(); if (tmp == GpioPinValue.Low) { System.Diagnostics.Debug.WriteLine("BUSY LOW "); } else { System.Diagnostics.Debug.WriteLine("BUSY HIGH "); } } open = gpio.TryOpenPin(ad5360_GPIO_Pins.ad5360_RESET, GpioSharingMode.Exclusive, out GPIO_Reset, out status); if (open == true) { GPIO_Reset.Write(GpioPinValue.High); GPIO_Reset.SetDriveMode(GpioPinDriveMode.Output); } open = gpio.TryOpenPin(ad5360_GPIO_Pins.ad5360_CLR, GpioSharingMode.Exclusive, out GPIO_Clear, out status); if (open == true) { GPIO_Clear.Write(GpioPinValue.High); GPIO_Clear.SetDriveMode(GpioPinDriveMode.Output); } return(true); }
/// <summary> /// Opens the specified general-purpose I/O (GPIO) pin in the specified mode, and gets a status value that can /// be used to handle a failure to open the pin programmatically. /// </summary> /// <param name="pinNumber">The pin number of the GPIO pin that you want to open. Some pins may not be available /// in user mode. For information about how the pin numbers correspond to physical pins, see the /// documentation for your circuit board.</param> /// <param name="sharingMode">The mode in which you want to open the GPIO pin, which determines whether other /// connections to the pin can be opened while you have the pin open.</param> /// <param name="pin">The opened GPIO pin if the open status is GpioOpenStatus.Success; otherwise null.</param> /// <param name="openStatus">An enumeration value that indicates either that the attempt to open the GPIO pin /// succeeded, or the reason that the attempt to open the GPIO pin failed.</param> /// <returns>True if the pin could be opened; otherwise false.</returns> public bool TryOpenPin(int pinNumber, GpioSharingMode sharingMode, out GpioPin pin, out GpioOpenStatus openStatus) { GpioPin newPin = new GpioPin(); if (!newPin.Init(pinNumber)) { pin = null; openStatus = GpioOpenStatus.PinUnavailable; return true; } pin = newPin; openStatus = GpioOpenStatus.PinOpened; return true; }
protected string GetStatusMessage(GpioOpenStatus Status) { switch (Status) { case GpioOpenStatus.MuxingConflict: return("The pin is currently opened for a different function, such as **I2c**, **Spi**, or **UART**. Ensure the pin is not in use by another function."); case GpioOpenStatus.PinOpened: return("The GPIO pin was successfully opened."); case GpioOpenStatus.PinUnavailable: return("The pin is reserved by the system and is not available to apps that run in user mode."); case GpioOpenStatus.SharingViolation: return("The pin is currently open in an incompatible sharing mode."); case GpioOpenStatus.UnknownError: default: return("The pin could not be opened."); } }
private void Init_Enable() { GpioOpenStatus status = new GpioOpenStatus(); var gpio = GpioController.GetDefault(); if (gpio == null) { return; } var open = gpio.TryOpenPin(ENABLE_PIN, GpioSharingMode.Exclusive, out _enable_Timer, out status); if (open == true) { _enable_Timer.SetDriveMode(GpioPinDriveMode.Output); _enable_Timer.Write(GpioPinValue.Low); } }
public AD5360_Controller(SpiMode spi_Mode, int clkFreq, int ChipSelectLine, string spiDeviceSelection) { ad5360_Board = new ad5360(spi_Mode, clkFreq, ChipSelectLine, spiDeviceSelection); playBack = true; GpioOpenStatus status = new GpioOpenStatus(); var gpio = GpioController.GetDefault(); if (gpio == null) { return; } var open = gpio.TryOpenPin(arduinoTimer, GpioSharingMode.Exclusive, out GPIO_Timer, out status); if (open == true) { GPIO_Timer.SetDriveMode(GpioPinDriveMode.Input); } }
void InitialiseGpioPin() { GpioController gpioController = null; try { gpioController = GpioController.GetDefault(); } catch (FileNotFoundException) { }; if (gpioController != null) { GpioPin localPin = null; GpioOpenStatus openStatus = GpioOpenStatus.PinUnavailable; if (gpioController.TryOpenPin( this.GpioPinNumber, GpioSharingMode.Exclusive, out localPin, out openStatus)) { this.gpioPin = localPin; this.gpioPin.SetDriveMode(GpioPinDriveMode.Output); } } }
public bool Initialize(int buttonDebounce, IDictionary <int, InputAction> buttonPins) { this.actionButtons = new Dictionary <InputAction, GpioPin>(); this.buttonPins = buttonPins; var gpio = GpioController.GetDefault(); if (null == gpio) { Debug.WriteLine("GpioInterfaceManager: No GPIO controller found"); return(false); } foreach (var pinSetting in buttonPins) { GpioPin button; GpioOpenStatus status = GpioOpenStatus.PinUnavailable; try { if (gpio.TryOpenPin(pinSetting.Key, GpioSharingMode.Exclusive, out button, out status)) { if (status == GpioOpenStatus.PinOpened) { button.DebounceTimeout = new TimeSpan(buttonDebounce); button.SetDriveMode(GpioPinDriveMode.Input); button.ValueChanged += handleButton; Debug.WriteLine("Button on pin " + pinSetting.Value + " successfully bound for action: " + pinSetting.Key.ToString()); actionButtons.Add(pinSetting.Value, button); button = null; continue; } } } catch (System.ArgumentException) { //tryopen should never have failed when pin is out of range } Debug.WriteLine("Error: Button on pin " + pinSetting.Value + " was unable to be bound because: " + status.ToString()); } return(true); }
private void InitGPIO() { SendMessage.Text = "GPIO Init"; var gpio = GpioController.GetDefault(); SendMessage.Text = "GPIO is " + gpio.ToString(); if (gpio == null) { myPin = null; bGpioStatus = false; SendMessage.Text = "There is no GPIO controller on this device."; return; } GpioOpenStatus openStatus = new GpioOpenStatus(); gpio.TryOpenPin(27, GpioSharingMode.Exclusive, out myPin, out openStatus); if (myPin == null) { bGpioStatus = false; SendMessage.Text = "There were problems initializing the GPIO pin."; return; } myPin.Write(GpioPinValue.High); myPin.SetDriveMode(GpioPinDriveMode.Output); pinValue = GpioPinValue.Low; myPin.Write(pinValue); SendMessage.Text = "GPIO pin initialized correctly."; bGpioStatus = true; }
private bool OpenGpioPin(int pinNumber, out GpioPin pin) { GpioOpenStatus openStat = GpioOpenStatus.PinUnavailable; if (_controller.TryOpenPin(pinNumber, GpioSharingMode.Exclusive, out pin, out openStat)) { switch (openStat) { case GpioOpenStatus.PinOpened: Debug.WriteLine("Pin Successfully opened - Pin Number - {0}!!", pinNumber); break; case GpioOpenStatus.PinUnavailable: Debug.WriteLine("Pin Unavailable. Pin Number - {0}", pinNumber); break; case GpioOpenStatus.SharingViolation: Debug.WriteLine("Sharing violation to open pin on pin number - {0}", pinNumber); break; } } return(openStat == GpioOpenStatus.PinOpened); }
/// <summary> /// Crete new (I/O) pin. /// </summary> /// <param name="index">position on board.</param> /// <param name="pin">Pin instance <see cref="GpioPin"/>.</param> /// <param name="status">Describe pin status. <see cref="GpioOpenStatus"/>.</param> public Pin(int index, GpioPin pin, GpioOpenStatus status) { this.position = index; this.pin = pin; this.status = status; }
/// <summary> /// Opens the specified general-purpose I/O (GPIO) pin in the specified mode, and gets a status value that can /// be used to handle a failure to open the pin programmatically. /// </summary> /// <param name="pinNumber">The pin number of the GPIO pin that you want to open. Some pins may not be available /// in user mode. For information about how the pin numbers correspond to physical pins, see the /// documentation for your circuit board.</param> /// <param name="sharingMode">The mode in which you want to open the GPIO pin, which determines whether other /// connections to the pin can be opened while you have the pin open.</param> /// <param name="pin">The opened GPIO pin if the open status is GpioOpenStatus.Success; otherwise null.</param> /// <param name="openStatus">An enumeration value that indicates either that the attempt to open the GPIO pin /// succeeded, or the reason that the attempt to open the GPIO pin failed.</param> /// <returns>True if the pin could be opened; otherwise false.</returns> public bool TryOpenPin(int pinNumber, GpioSharingMode sharingMode, out GpioPin pin, out GpioOpenStatus openStatus) { GpioPin newPin = new GpioPin(); if (!newPin.Init(pinNumber)) { pin = null; openStatus = GpioOpenStatus.PinUnavailable; return(true); } pin = newPin; openStatus = GpioOpenStatus.PinOpened; return(true); }
public bool TryOpenPin(int pinNumber, GpioSharingMode sharingMode, out GpioPin pin, out GpioOpenStatus openStatus) { return(Controller.TryOpenPin(pinNumber, sharingMode, out pin, out openStatus)); }
public bool TryOpenPin(int pinNumber, GpioSharingMode sharingMode, out IGpioPin pin, out GpioOpenStatus openStatus) { pin = null; if ((pinNumber < 0) || (pinNumber > PinCount - 1)) { openStatus = GpioOpenStatus.UnknownError; return(false); } if ((_gpioPin[pinNumber] == null) || (this._gpioPin[pinNumber].IsDisposed)) { this._gpioPin[pinNumber] = new MCP23017GpioPin(this, pinNumber, sharingMode); } else if ((sharingMode == GpioSharingMode.Exclusive) || (this._gpioPin[pinNumber].SharingMode == GpioSharingMode.Exclusive)) { openStatus = GpioOpenStatus.SharingViolation; return(false); } pin = this._gpioPin[pinNumber]; openStatus = GpioOpenStatus.PinOpened; return(true); }