Collaboration diagram for C# Gpio API:
Modules | |
DTO | |
Enumerations | |
Events related with Gpio Service | |
Classes | |
class | GpioManager |
Implementation of IGpioManager. Start point for interacting with Deepsy Gpio service More... | |
interface | IGpio |
Intarface for Gpio Service More... | |
interface | IGpioManager |
Interaface for managing device Gpios More... | |
Detailed Description
To work with Deepsy Gpio Manager service it is necessary to use GpioManager located in GMV.ITS.HAL.DEEPSY.Gpio.Facade for getting the initial GpioManager object.
GpioManager has an optional parameter indicating the ip address of remote service. For instance:
GpioManager GpioManager = new GpioManager("172.22.198.103");
GpioManager implements IDisposable. It can hold resources (such as socket handles) until it is disposed. The Dispose method is automatically called when existing a using or try / catch block, for which the object has been declared. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.
- * GpioManager GpioManager= null;try{GpioManager = new GpioManager("172.22.198.103");List<IGpio> gpios = GpioManager.GetGpios().ToList();} catch (Exception e) {throw e;}GpioManager.Dispose();
Examples
-
Get Gpios
using System;using System.Collections.Generic;using System.Linq;using System.Text;{public class GetGpios{static void Main(string[] args){string deepsyServerIp = args.Length == 0 ? "192.168.0.144" : args[0];using (GpioManager gpioManager = new GpioManager(deepsyServerIp)){List<IGpio> gpios = gpioManager.GetGpios().ToList();Console.WriteLine($"There are {gpios.Count()} GPIOS");foreach (IGpio gpio in gpios){Console.WriteLine($"Gpio id : {gpio.Id}");Console.WriteLine($"{"Alias",20} : {gpio.Configuration.Alias}");Console.WriteLine($"{"Address",20} : {gpio.Information.Address}");Console.WriteLine($"{"Direction ",20} : {gpio.Information.Direction}");Console.WriteLine($"{"Default Value",20} : {gpio.Configuration.DefaultValue}");Console.WriteLine($"{"Active Low",20} : {gpio.Configuration.ActiveLow}");Console.WriteLine($"{"Edge type",20} : {gpio.Configuration.EdgeType}");Console.WriteLine($"{"Publish",20} : {gpio.Configuration.Publish}");Console.WriteLine($"{"Bouncing Time",20} : {gpio.Configuration.BouncingTime}");}}}}}
-
Get Gpio Value
using System;using System.Collections.Generic;using System.Linq;using System.Text;{class GetGpiosValue{static void Main(string[] args){string deepsyServerIp = args.Length == 0 ? "192.168.0.144" : args[0];using (GpioManager gpioManager = new GpioManager(deepsyServerIp)){List<IGpio> gpios = gpioManager.GetGpios().ToList();Console.WriteLine($"There are {gpios.Count()} GPIOS");foreach (IGpio gpio in gpios){if(gpio.Information.Direction == DEEPSY.Gpio.Interface.Enum.GpioDirection.Direction.INPUT){Console.WriteLine($"Gpio id : {gpio.Id}");IGpioStatus status = gpio.GetStatus();Console.WriteLine($"{"Value",20} : {status.Value}");Console.WriteLine($"{"Counter",20} : {status.Counter}");}}}}}}
-
Subscrive to Gpio events
using System;using System.Collections.Generic;using System.Linq;using System.Text;{class SubscribeGpioEvents{static void Main(string[] args){string deepsyServerIp = args.Length == 0 ? "192.168.0.144" : args[0];using (GpioManager gpioManager = new GpioManager(deepsyServerIp)){List<IGpio> gpios = gpioManager.GetGpios().ToList();Console.WriteLine($"There are {gpios.Count()} GPIOS");foreach (IGpio gpio in gpios){gpio.ConfigurationEvent += Gpio_ConfigurationEvent;gpio.StatusEvent += Gpio_StatusEvent;}Console.WriteLine("Press any key for exit");Console.ReadKey();}}private static void Gpio_StatusEvent(object sender, IGpioStatusEvent e){Console.WriteLine($"Status Event. Gpio {e.Id}. Value {e.Status.Value} Conter {e.Status.Counter}");}private static void Gpio_ConfigurationEvent(object sender, IGpioConfigurationEvent e){Console.WriteLine($"Configuration Event. Gpio {e.Id}.");Console.WriteLine($"{"New Alias",20} : {e.Configuration.Alias}");Console.WriteLine($"{"New Default Value",20} : {e.Configuration.DefaultValue}");Console.WriteLine($"{"New Active Low",20} : {e.Configuration.ActiveLow}");Console.WriteLine($"{"New Edge type",20} : {e.Configuration.EdgeType}");Console.WriteLine($"{"New Publish",20} : {e.Configuration.Publish}");Console.WriteLine($"{"New Bouncing Time",20} : {e.Configuration.BouncingTime}");}}}
-
Set Gpio Configuration
using System;using System.Collections.Generic;using System.Linq;using System.Text;{class SetGpioConfiguration{static void Main(string[] args){string deepsyServerIp = args.Length == 0 ? "192.168.0.144" : args[0];using (GpioManager gpioManager = new GpioManager(deepsyServerIp)){List<IGpio> gpios = gpioManager.GetGpios().ToList();Console.WriteLine($"There are {gpios.Count()} GPIOS");IGpio gpio = gpios.FirstOrDefault(g => g.Information.Direction == DEEPSY.Gpio.Interface.Enum.GpioDirection.Direction.OUTPUT);if (gpio != null){IGpioConfiguration currentConfiguration = gpio.Configuration;Console.WriteLine($"{"Alias",20} : {gpio.Configuration.Alias}");Console.WriteLine($"{"Default Value",20} : {gpio.Configuration.DefaultValue}");Console.WriteLine($"{"Bouncing Time",20} : {gpio.Configuration.BouncingTime}");IGpioConfiguration configuration = gpio.Configuration;configuration.Alias = "New alias";configuration.DefaultValue = 1;configuration.BouncingTime = 10;gpio.SetConfiguration(configuration);IGpio gpio2 = gpioManager.GetGpios().ToList().FirstOrDefault(g => g.Id == gpio.Id);Console.WriteLine($"{"Alias",20} : {gpio2.Configuration.Alias}");Console.WriteLine($"{"Default Value",20} : {gpio2.Configuration.DefaultValue}");Console.WriteLine($"{"Bouncing Time",20} : {gpio2.Configuration.BouncingTime}");//Set configuration as it wasgpio.SetConfiguration(currentConfiguration);}}}}}