Exemple #1
0
 private static async void testSerialPorts(RexDevice rex)
 {
     try {
         while (true)
         {
             foreach (SerialPort serial in rex.SerialPorts)
             {
                 using (Stream stream = serial.Open()) {
                     byte[] buffer = Encoding.ASCII.GetBytes("Foo Bar 123\n");
                     stream.Write(buffer, 0, buffer.Length);
                     stream.Dispose();
                 }
                 await Task.Delay(500);
             }
         }
     } catch (ObjectDisposedException) {
         Console.WriteLine("Rex has disconnected, stopping testSerialPorts()");
     }
 }
Exemple #2
0
        private static async void toggleRandomStuff(RexDevice rex)
        {
            try {
                List <DigitalOutput> pins = new List <DigitalOutput> ();
                pins.AddRange(rex.Leds);
                pins.AddRange(rex.Relays);
                pins.Add(rex.Buzzer);
                pins.Add(rex.Display.Backlight);

                while (true)
                {
                    foreach (DigitalOutput pin in pins)
                    {
                        pin.Hold(600);
                        await Task.Delay(400);
                    }
                }
            } catch (ObjectDisposedException) {
                Console.WriteLine("Rex has disconnected, stopping toggleRandomStuff()");
            }
        }
Exemple #3
0
        private static async void closeAfter(RexDevice rex, int secs)
        {
            await Task.Delay(secs * 1000);

            rex.Dispose();
        }