Esempio n. 1
0
        public async void TrySending()
        {
            using (var serialPort = new ExtSerialPort("COM4", 115200, Parity.Odd, 8, StopBits.One))
            {
                serialPort.ReadTimeout  = 10000;
                serialPort.WriteTimeout = 10000;
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen);
                var arduino = Arduino.IsArduino(serialPort, new Random(4));

                Assert.IsNotNull(arduino);

                for (int i = 0; i < 10; i++)
                {
                    Assert.IsTrue(await arduino.SendAsync(new Note()
                    {
                        NoteLength   = 1,
                        Pin          = 8,
                        RepeatLength = 1,
                        Step         = 1
                    }));
                }

                serialPort.Close();
            }
        }
Esempio n. 2
0
        public async void LoadTests()
        {
            using (var serialPort = new ExtSerialPort("COM4", 115200, Parity.Odd, 8, StopBits.One))
            {
                serialPort.ReadTimeout  = 100;
                serialPort.WriteTimeout = 100;
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen);
                var rand    = new Random(7);
                var arduino = Arduino.IsArduino(serialPort, rand);

                Assert.IsNotNull(arduino);

                const int BUFFER_SIZE      = 10;
                var       readBufferRatio  = new double[BUFFER_SIZE];
                var       writeBufferRatio = new double[BUFFER_SIZE];
                for (int i = 0; i < 100000; i++)
                {
                    Assert.IsTrue(await arduino.SendAsync(new Note()
                    {
                        NoteLength   = 1,
                        Pin          = 8,
                        RepeatLength = 1,
                        Step         = (byte)rand.Next(i % 64)
                    }));


                    Console.WriteLine("WriteBufferSize = {0}, ReadBufferSize = {1}, BytesToWrite = {2}, BytesToRead = {3}", serialPort.WriteBufferSize, serialPort.ReadBufferSize, serialPort.BytesToWrite, serialPort.BytesToRead);

                    //Assert.IsFalse(serialPort.BytesToRead > 100);
                }

                serialPort.Close();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Orchestrates the communication between the Leap Motion and the Arduino.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            using (var serialPort = new ExtSerialPort("COM4", 115200, System.IO.Ports.Parity.Odd, 8, System.IO.Ports.StopBits.One))
            {
                serialPort.ReadTimeout  = 1000;
                serialPort.WriteTimeout = 1000;
                serialPort.Open();
                var arduino = APS.Arduino.Arduino.IsArduino(serialPort);

                if (arduino != null)
                {
                    Console.WriteLine("ARDUINO FOUND!");

                    // Create a sample listener and controller
                    var listener   = new LeapListener(new LinearDistanceMotionToNotes(), arduino);
                    var controller = new Controller();

                    // Have the sample listener receive events from the controller
                    controller.AddListener(listener);

                    // Keep this process running until Enter is pressed
                    Console.WriteLine("Press Enter to quit...");
                    Console.ReadLine();

                    // Remove the sample listener when done
                    controller.RemoveListener(listener);
                    controller.Dispose();
                }
                else
                {
                    Console.WriteLine("ARDUINO NOT FOUND!");

                    Console.WriteLine("Press Enter to quit...");
                    Console.ReadLine();
                }

                serialPort.Close();
            }
        }
Esempio n. 4
0
        public void TryIdentify()
        {
            using (var serialPort = new ExtSerialPort("COM4", 115200, Parity.Odd, 8, StopBits.One))
            {
                serialPort.ReadTimeout  = 10000;
                serialPort.WriteTimeout = 10000;
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen);
                Assert.IsNotNull(Arduino.IsArduino(serialPort, new Random(1)));
                serialPort.Close();
            }

            using (var serialPort = new ExtSerialPort("COM4", 115200, Parity.Odd, 8, StopBits.One))
            {
                serialPort.ReadTimeout  = 10000;
                serialPort.WriteTimeout = 10000;
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen);
                Assert.IsNotNull(Arduino.IsArduino(serialPort, new Random(3)));
                serialPort.Close();
            }
        }