Esempio n. 1
0
            private void FlexorTest(int samples, int flexors, String folderName, String fileName)
            {
                // Keep listening to the InputStream whit a StreamReader until an exception occurs
                string      line;
                int         counter   = 0;
                List <long> latencies = new List <long>();

                IO.CSV csvWriter = new IO.CSV(folderName, fileName);

                Debug.WriteLine(csvWriter.ToString());

                Stopwatch stopWatch = new Stopwatch(); // for capture elapsed time
                TimeSpan  ts;

                while (true)
                {
                    try
                    {
                        Debug.WriteLine("Counter: " + counter);
                        stopWatch = new Stopwatch();
                        stopWatch.Start();
                        line = AnalogRead(mFlexorPins[0]);
                        stopWatch.Stop();
                        ts = stopWatch.Elapsed;

                        if (counter < samples)
                        {
                            latencies.Add(ts.Ticks * 100); // nanoseconds https://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx
                            if ((counter + 1) % 100 == 0)
                            {
                                Debug.WriteLine("Counter: " + counter);
                            }
                        }
                        else
                        {
                            break;
                        }
                        counter++;

                        if (line != null)
                        {
                            //Raise the event to UI thread, that need stay subscriber to this publisher thread
                            //Send the current thread id and send Message
                            OnBluetootDataReceived(this.Id, line);
                        }
                        else
                        {
                            Debug.WriteLine($"BluetoothSocket is Disconnected");
                            mmSocket.Connect();
                        }
                    }
                    catch (Java.IO.IOException e)
                    {
                        Debug.WriteLine($"CONNECTED THREAD {this.Id}: {e.Message}");
                    }
                }

                csvWriter.Write(latencies, "latencies-ns");
                Debug.WriteLine(csvWriter.ToString());
            }
Esempio n. 2
0
            private void MotorTest(int samples, int motors, string folderName, string fileName)
            {
                string        message;
                int           counter   = 0;
                List <long>   latencies = new List <long>();
                List <int>    pins      = new List <int>(OpenGloveAppPage.mPins.GetRange(0, motors * 2));
                List <string> valuesON  = new List <string>(OpenGloveAppPage.mValuesON.GetRange(0, motors * 2));
                List <string> valuesOFF = new List <string>(OpenGloveAppPage.mValuesOFF.GetRange(0, motors * 2));

                IO.CSV csvWriter = new IO.CSV(folderName, fileName);

                Debug.WriteLine(csvWriter.ToString());

                Stopwatch stopWatch = new Stopwatch(); // for capture elapsed time
                TimeSpan  ts;

                while (true)
                {
                    if (counter < samples)
                    {
                        try
                        {
                            stopWatch = new Stopwatch();
                            stopWatch.Start();

                            message = mMessageGenerator.ActivateMotor(pins, valuesON);
                            this.Write(message); // Activate the motors

                            message = mMessageGenerator.ActivateMotor(pins, valuesOFF);
                            this.Write(message); // Disable the motors

                            stopWatch.Stop();
                            ts = stopWatch.Elapsed;

                            latencies.Add(ts.Ticks * 100);
                            if ((counter + 1) % 100 == 0)
                            {
                                Debug.WriteLine("Counter: " + counter);
                            }
                        }
                        catch (Java.IO.IOException e)
                        {
                            e.PrintStackTrace();
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                    counter++;
                }

                csvWriter.Write(latencies, "latencies-ns");
                Debug.WriteLine(csvWriter.ToString());
            }