private static int RunRemote() { string host = "localhost"; int port = 8888; if (optHost.HasValue()) { host = optHost.Value(); } if (optPort.HasValue()) { if (!int.TryParse(optPort.Value(), out port)) { Console.Error.WriteLine("Invalid port value"); return(-1); } } Console.WriteLine($"Connecting to {host}:{port}"); using (var pigpio = new PigsClient(host, port)) { pigpio.ConnectAsync().Wait(); return(Run(pigpio)); } }
static void Main(string[] args) { //Config int ledGpio = 2; int buttonGpio = 18; string piAddress = "192.168.20.11"; int port = 8888; //Default port //Create a client using (PigsClient client = new PigsClient(piAddress, port)) { //Define callbacks client.AddCallback(buttonGpio, Edge.Rise, buttonRise); client.AddCallback(buttonGpio, Edge.Fall, buttonFall); //Connect client.ConnectAsync().Wait(); Console.WriteLine("connected"); var ver = client.HardwareRevision(); Console.WriteLine("Hardware : {0} => {1}", ver, client.HardwareName()); Console.WriteLine("PiGPIO version : {0}", client.PIGPV()); //Set ports client.SetMode(ledGpio, Mode.Output); client.SetMode(buttonGpio, Mode.Input); client.SetPullUpDown(buttonGpio, PullUpDown.Up); Console.WriteLine("ready"); //While the user has not pressed Ctrl+C bool run = true; Console.TreatControlCAsInput = true; while (run) { if (Console.KeyAvailable) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control) { run = false; Console.TreatControlCAsInput = false; } } } } }
static void Main(string[] args) { //Config int gpioNum = 2; string piAddress = "192.168.20.22"; int port = 8888; //Default port int msDelay = 500; //Create a client using (PigsClient client = new PigsClient(piAddress, port)) { //Connect client.ConnectAsync().Wait(); Console.Write("connected"); //Set port as output client.SetMode(gpioNum, Mode.Output); //Value to write bool value = false; //While the user has not pressed Ctrl+C bool run = true; Console.TreatControlCAsInput = true; while (run) { if (Console.KeyAvailable) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control) { run = false; Console.TreatControlCAsInput = false; } } //Blink the LED Console.Title = string.Format("Blink [{0}]", value ? "+" : "."); client.Write(gpioNum, value); value = !value; Thread.Sleep(msDelay); } } }
static void Main(string[] args) { //Config int ledGpio = 2; int buttonGpio = 18; string piAddress = "192.168.20.11"; int port = 8888; //Default port //Create a client using (PigsClient client = new PigsClient(piAddress, port)) { //Connect client.ConnectAsync().Wait(); Console.WriteLine("connected"); //Set ports client.SetMode(ledGpio, Mode.Output); client.SetMode(buttonGpio, Mode.Input); client.SetPullUpDown(buttonGpio, PullUpDown.Up); Console.WriteLine("ready"); //While the user has not pressed Ctrl+C bool run = true; Console.TreatControlCAsInput = true; while (run) { if (Console.KeyAvailable) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control) { run = false; Console.TreatControlCAsInput = false; } } var value = client.Read(buttonGpio); client.Write(ledGpio, !value); } } }