コード例 #1
0
 /// <summary>
 /// Open connection and access bus
 /// </summary>
 /// <returns>true if success, false if error</returns>
 public bool Connect()
 {
     if (PHY.Connect())
     {
         // Start the link thread if connection was successful
         LinkThread.Start();
         FramingTimer.Start();
         return(true);
     }
     return(false);
 }
コード例 #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     //Start/stop the timer
     if (button2.Text == "Start")
     {
         //Change button to stop
         button2.Text = "Stop";
         //Progress used to update UI
         if (update == null)
         {
             update = new Progress <int>();
             //also uses the UpdateUI function
             update.ProgressChanged += UpdateUI;
             //Assign the Progress object to the MicroTimer
             msTimer.Updater = update;
         }
         //Start the timer
         msTimer.Start();
     }
     else
     {
         //Stop the timer
         msTimer.Stop();
         //Change button to start
         button2.Text = "Start";
     }
 }
コード例 #3
0
        private void PlayBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_doAudioOperations == null || _audioObject == null)
            {
                PlayEnabled(true);
                MessageBox.Show("Session has ended \n To continue either reload the session again \n or switch between the modes", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                throw new NullReferenceException("The Audio Object is not Intialized yet!!!!");
            }

            if (!_isPlaying)
            {
                _microTimer.Start();
            }

            if (PlayBtn.Content == (Image)FindResource("PlayEnabled"))
            {
                var image = (Image)FindResource("PauseEnabled");
                image.Height    = 50;
                PlayBtn.Content = image;
                PlayClickedAudio(_mushraButtonIndex);
            }
            else if (PlayBtn.Content == (Image)FindResource("PauseEnabled"))
            {
                PauseAudio();
                PlayEnabled(true);
            }
        }
コード例 #4
0
        public void OnExampleEnter()
        {
            // Manages the state of example on enter
            // Reset();
            // _startDelegate = TimedMethod.Invoke(this.Start).After(500).Go();

            using (oscilloscopeChart.SuspendUpdates())
            {
                Channel1Series = (FastLineRenderableSeries)oscilloscopeChart.RenderableSeries[0];

                // Create three DataSeries
                Ch1Series = new XyDataSeries <double, float>();
                Ch1Series.FifoCapacity = 100000;//10 sec

                Channel1Series.DataSeries = Ch1Series;

#if MILI
                // _timer = new Timer(TimerIntervalmili);
                // _timer.Elapsed += OnTickMili;
                // _timer.AutoReset = true;
                //  _timer.Start();
#else
                _timerMicro.MicroTimerElapsed += OnTickMicro;
                _timerMicro.Start();
#endif
            }
        }
コード例 #5
0
        void Run()
        {
            masterTimer.Start();

            while (!_stop)
            {
                Thread.Sleep(1000);
            }

            masterTimer.Stop();

            foreach (TaskElement ele in tasks)
            {
                ele.threadTimer.Abort();
            }
        }
コード例 #6
0
        public void MicroTimer_ClockTicksAreCloseToThreadTimerTicks(int sleepSeconds, long interval, long ignoreIfLateBy, int msThreshold)
        {
            var ticks = 0;
            var clock = new MicroTimer(interval);

            clock.IgnoreEventIfLateBy = ignoreIfLateBy;
            clock.MicroTimerElapsed  += (sender, args) => ticks++;
            clock.Start();

            Thread.Sleep(sleepSeconds * 1000);
            //=== Manual Step : Check CPU to see processor efficiency.

            clock.Stop();
            Console.WriteLine(ticks);

            Assert.That(Math.Abs(ticks - (sleepSeconds * 1000000 / interval)) <= msThreshold);
        }
コード例 #7
0
        public void PlaySound(byte[] data)
        {
            lock (speakerLock) {
                if (disposed)
                {
                    return;
                }
                speakerTimer?.Stop();

                /*var config = new SpeakerConfiguration(SpeakerFormat.PCM) {
                 *      Volume = .1f,
                 *      SampleRate = 4000,
                 * };
                 * EnableSpeaker(config);*/
                speakerTimer = new MicroTimer(speakerConfig.MicrosecondsPerReport);
                speakerTimer.MicroTimerElapsed += OnSpeakerTimerEllapsed;
                Debug.WriteLine("Milliseconds Per Report: " + speakerConfig.MillisecondsPerReport);
                //speakerTimer2 = new ATimer(3, speakerConfig.MillisecondsPerReport, OnSpeakerTimer2Ellapsed);
                //}

                //string path = @"C:\Users\Onii-chan\My Projects\C#\WiimoteController\WiimoteController\Resources\Oracle_Secret2Raw.wav";

                /*string path = @"C:\Users\Onii-chan\My Projects\C#\WiimoteController\WiimoteController\Resources\Oracle_Secret4.wav";
                 * using (FileStream stream = File.OpenRead(path)) {
                 *      BinaryReader reader = new BinaryReader(stream);
                 *      int length = reader.ReadInt32();
                 *      speakerData = reader.ReadBytes(length);
                 * }*/
                //speakerPrebuffered = data;
                speakerData = data;
                //speakerData = new byte[20000000];
                speakerIndex = 0;
                NextSpeakerReport();

                /*for (int i = 0; i < 2000; i++) {
                 *      OnSpeakerTimer2Ellapsed();
                 * }*/
                //Console.WriteLine("DONE");

                speakerTimer.Start();
                //speakerTimer2.Start();
                //speakerWatch = Stopwatch.StartNew();
            }
        }
コード例 #8
0
        private void PlayBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_sessCreatedFlag == false)
            {
                return;
            }
            if (!_isPlaying)
            {
                _microTimer.Start();
            }

            if (PlayBtn.Content == (Image)FindResource("PlayEnabled"))
            {
                var image = (Image)FindResource("PauseEnabled");
                image.Height    = 50;
                PlayBtn.Content = image;
                PlayClickedAudio(_clickedButton);
            }
            else if (PlayBtn.Content == (Image)FindResource("PauseEnabled"))
            {
                PauseAudio();
                PlayEnabled(true);
            }
        }
コード例 #9
0
 public void Start()
 {
     cancellationPending.Set(false);
     timer.Start();
     Debug.WriteLine("Timer started");
 }
コード例 #10
0
        public void NextCommand(string cmd, List <int> paras)
        {
            switch (cmd)
            {
            case "lf":
            {
                int timeSpan  = paras[2];
                int speedSpan = paras[1] - paras[0];
                speedIncrement           = speedSpan * 1.0 / timeSpan; //speed increment in 1 millis
                duration                 = timeSpan * 1000;            //Timer count in micros
                timer                    = new MicroTimer();
                timer.MicroTimerElapsed += timer_TimerTick;
                timer.Interval           = 1000;
                currentMotorSpeed        = paras[0];
                timerFlag                = 0;
                timer.Start();
            }
            break;

            case "lr":
            {
                int timeSpan  = paras[2];
                int speedSpan = paras[1] - paras[0];
                speedIncrement           = speedSpan * 1.0 / timeSpan; //speed increment in 1 millis
                duration                 = timeSpan * 1000;            //Timer count in micros
                timer                    = new MicroTimer();
                timer.MicroTimerElapsed += timer_TimerTick;
                timer.Interval           = 1000;
                currentMotorSpeed        = paras[0];
                timerFlag                = 1;
                timer.Start();
            }
            break;

            case "fw":
                theBridge.SendMotorSpeed(paras[0]);
                if (paras.Count > 1)
                {
                    timer = new MicroTimer();
                    timer.MicroTimerElapsed += timer_TimerTick;
                    timer.Interval           = paras[1] * 1000;
                    timerFlag = 2;
                    timer.Start();
                }
                else
                {
                    CommandFinished();
                }
                break;

            case "rv":
                theBridge.SendMotorSpeed(-paras[0]);
                if (paras.Count > 1)
                {
                    timer = new MicroTimer();
                    timer.MicroTimerElapsed += timer_TimerTick;
                    timer.Interval           = paras[1] * 1000;
                    timerFlag = 2;
                    timer.Start();
                }
                else
                {
                    CommandFinished();
                }
                break;

            case "st":
                theBridge.SendMotorSpeed(0);
                if (paras.Count > 0)
                {
                    timer = new MicroTimer();
                    timer.MicroTimerElapsed += timer_TimerTick;
                    timer.Interval           = paras[0] * 1000;
                    timerFlag = 2;
                    timer.Start();
                }
                else
                {
                    CommandFinished();
                }
                break;

            case "wt":
                timer = new MicroTimer();
                timer.MicroTimerElapsed += timer_TimerTick;
                timer.Interval           = paras[0] * 1000;
                timerFlag = 2;
                duration  = paras[0] * 1000;
                timer.Start();
                break;

            case "tr":
                theBridge.SendTare();
                CommandFinished();
                break;

            default:
                break;
            }
        }