Ejemplo n.º 1
0
        /// <summary>
        /// Start this controller and measurements.
        /// </summary>
        public void Start()
        {
            //Save the port, so that next time the connection may be automaticly established
            Backend.Properties.Settings.Default.LastConnectedPort = ArduinoController.SerialPortName;
            Backend.Properties.Settings.Default.Save();

            KeeperOfTime.Restart();

            running = true;

            ArduinoController.SetPinModes(Configuration.AnalogPins.Select(o => o.RealNumber).ToArray <uint> (), Configuration.DigitalPins.Select(o => o.RealNumber).ToArray <uint> ());

            StartTime     = DateTime.Now;
            LastCondition = new ushort[] { 0, 0, 0, 0 };

            SequencesTimer          = new System.Timers.Timer(10);
            SequencesTimer.Elapsed += OnSequenceTimeElapsed;

            MeasurementPreProcessing();


            if (System.Environment.OSVersion.Platform == PlatformID.Unix)
            {
                MeasurementTimer = new System.Threading.Timer(new TimerCallback(OnMeasurementTimerTick), null, 0, 10);
            }
            else
            {
                //because windows sux
                MeasurementTimer = new System.Threading.Timer(new TimerCallback(OnMeasurementTimerTickWindows), null, 0, 1);
            }
            SequencesTimer.Start();

            ConLogger.Log("Controller Started", LogLevel.DEBUG);
            ConLogger.Log("Start took: " + KeeperOfTime.ElapsedMilliseconds + "ms", LogLevel.DEBUG);

            if (OnControllerStarted != null)
            {
                OnControllerStarted.Invoke(this, null);
            }
        }