Initializing the GPIO output pin

Once we have access to the controller, we can try to open exclusive access to the GPIO pin we've connected the relay to:

if (gpio.TryOpenPin(gpioOutputPin, GpioSharingMode.Exclusive, 
   out this.gpioPin, out GpioOpenStatus Status) && 
   Status == GpioOpenStatus.PinOpened) 
   { 
         ... 
   } 
   else 
         Log.Error("Unable to get access to GPIO pin " + 
               gpioOutputPin.ToString()); 

Through the GpioPin object gpioPin, we can now control the pin. The first step is to set the operating mode for the pin. This is done by calling the SetDriveMode() method. There are many different modes a pin can be set to, not all necessarily supported by the underlying firmware and hardware. To check that a mode is supported, call the IsDriveModeSupported() method first:

if (this.gpioPin.IsDriveModeSupported(GpioPinDriveMode.Output)) 
{ 
   This.gpioPin.SetDriveMode(GpioPinDriveMode.Output); 
   ... 
} 
else 
   Log.Error("Output mode not supported for GPIO pin " + 
         gpioOutputPin.ToString()); 
There are various output modes available: Output, OutputOpenDrain, OutputOpenDrainPullUp, OutputOpenSource, and OutputOpenSourcePullDown. The code documentation for each flag describes the particulars of each option.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.100.42