public Timer5Controller(IDeviceOutput output)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
     _timer = new MicroTimer(1000);
     _timer.MicroTimerElapsed += new MicroTimer.MicroTimerElapsedEventHandler(OnTimerEvent);
 }
 public Timer5Controller(IDeviceOutput output, int baseAddress, int irq)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
     _timer = new MicroTimer(1000);
     _timer.MicroTimerElapsed += new MicroTimer.MicroTimerElapsedEventHandler(OnTimerEvent);
     _baseAddress              = baseAddress * 0x10;
     _irq = (byte)irq;
 }
Exemple #3
0
        static void Main(string[] args)
        {
            var handler1 = new Action(() => { Console.WriteLine("HERE"); });

            var mt    = new MicroTimer();
            var timer = mt.CreateMicro(handler1, 500);

            timer.Start();
        }
        /*----------------------------------------------------------------------------
        *       %%Function:GetOptionsTextValueMappingFromControlId
        *       %%Qualified:ArbWeb.ArbWebControl_Selenium.GetOptionsTextValueMappingFromControlId
        *  ----------------------------------------------------------------------------*/
        public static Dictionary <string, string> GetOptionsTextValueMappingFromControlId(IWebDriver driver, IStatusReporter srpt, string sid)
        {
            MicroTimer timer = new MicroTimer();

            Dictionary <string, string> mp = GetOptionsTextValueMappingFromControl(driver.FindElement(By.Id(sid)), srpt);

            timer.Stop();
            srpt.LogData($"GetOptionsTextValueMappingFromControlId({sid}) elapsed: {timer.MsecFloat}", 1, MSGT.Body);
            return(mp);
        }
Exemple #5
0
 public void StopSound()
 {
     lock (speakerLock) {
         speakerTimer?.Stop();
         speakerTimer = null;
         speakerStream?.Close();
         speakerStream = null;
         speakerData   = null;
         //speakerPrebuffered = null;
     }
 }
        public SimulationTimer(double mainTickInterval, double sideTickInterval)
        {
            if (mainTickInterval >= sideTickInterval)
            {
                throw new Exception("Main tick interval must be lower than side tick");
            }

            sideTickDivider = (int)Math.Round(sideTickInterval / mainTickInterval);

            timer                    = new MicroTimer();
            timer.Interval           = Convert.ToInt64(1000000 * mainTickInterval);
            timer.MicroTimerElapsed += Timer_MicroTimerElapsed;
        }
Exemple #7
0
    protected override void ThreadFunction()
    {
        StartRecordingTime = System.DateTime.Now;

        MicroTimer = new MicroTimer();
        MicroTimer.MicroTimerElapsed += OnTimedEvent;

        MicroTimer.Interval = ThreadSleepTime * 1000;         // Call micro timer every 1000us

        // Can choose to ignore event if late by Xµs (by default will try to catch up)
        MicroTimer.IgnoreEventIfLateBy = 50; // 50µs (0.05ms)

        MicroTimer.Enabled = true;           // Start timer
    }
        void PreTask()
        {
            foreach (BricRoboTask br in _taskList)
            {
                TaskElement ele = new TaskElement(br);
                tasks.Add(ele);
            }

            masterTimer = new MicroTimer(oneMsTick);
            masterTimer.MicroTimerElapsed += new MicroTimer.MicroTimerElapsedEventHandler(
                delegate {
                Tick();
            });
        }
 public FakeCBT(string portName = null)
 {
     _rnd = new Random();
     _timer = new MicroTimer(1000);
     _timer.MicroTimerElapsed += (s, args) => {
         if (CanMessageReceived == null) return;
         // Generate random Can Message
         var msg = new CanMessage {
             Bus = 1,
             Id = _rnd.Next(1, 0xFFF),
             Status = _rnd.Next(0, 3),
             Data = BitConverter.GetBytes(++_counter),
             DateTime = _startTime + _stopwatch.Elapsed
         };
         CanMessageReceived(msg);
     };
 }
Exemple #10
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);
        }
        /*----------------------------------------------------------------------------
        *       %%Function:FNavToPage
        *       %%Qualified:ArbWeb.ArbWebControl_Selenium.FNavToPage
        *
        *  ----------------------------------------------------------------------------*/
        public bool FNavToPage(string sUrl)
        {
            MicroTimer timer = new MicroTimer();

            try
            {
                Driver.Navigate().GoToUrl(sUrl);
            }
            catch (Exception)
            {
                return(false);
            }

            timer.Stop();
            m_iStatusReporter.LogData($"FNavToPage({sUrl}) elapsed: {timer.MsecFloat}", 1, MSGT.Body);
            return(true);
        }
Exemple #12
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();
            }
        }
        static MicroTimer MicroTimer100;                                                 // timer 100hz

        public static void StartTimerServices()
        {
            MicroStopwatch.Start();

            MicroTimer50                    = new MicroTimer();
            MicroTimer50.Interval           = 20000; // In nanoseconds
            MicroTimer50.MicroTimerElapsed += handleTimer50;
            // Can choose to ignore event if late by Xµs (by default will try to catch up)
            // microTimer.IgnoreEventIfLateBy = 500; // 500µs (0.5ms)
            MicroTimer50.Enabled = true; // Start timer


            MicroTimer100                    = new MicroTimer();
            MicroTimer100.Interval           = 10000; // In nanoseconds
            MicroTimer100.MicroTimerElapsed += handleTimer100;
            // Can choose to ignore event if late by Xµs (by default will try to catch up)
            // microTimer.IgnoreEventIfLateBy = 500; // 500µs (0.5ms)
            MicroTimer100.Enabled = true; // Start timer
        }
Exemple #14
0
        private void Initialization()
        {
            Logger.Info(TraceMessage.Execute(this, "Celestial map control - Initialization"));

            _screenParameters = new ScreenParameters(Width, Height, _centerScreenPosition.X, _centerScreenPosition.Y);

            if (DebugTools.IsInDesignMode())
            {
                return;
            }

            crlRefreshMap = new MicroTimer();
            crlRefreshMap.MicroTimerElapsed += Event_Refresh;

            var intervalMilliseconds = 50;

            crlRefreshMap.Interval = 1000 * intervalMilliseconds; // 1000 = 1ms

            crlRefreshMap.Enabled = true;

            _screenParameters.DrawInterval = 1000 / intervalMilliseconds;
        }
        /*----------------------------------------------------------------------------
        *       %%Function:WaitForPageLoad
        *       %%Qualified:ArbWeb.ArbWebControl_Selenium.WaitForPageLoad
        *  ----------------------------------------------------------------------------*/
        public static void WaitForPageLoad(IStatusReporter srpt, IWebDriver driver, int maxWaitTimeInSeconds)
        {
            MicroTimer timer = new MicroTimer();

            string state = string.Empty;

            try
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(maxWaitTimeInSeconds));

                //Checks every 500 ms whether predicate returns true if returns exit otherwise keep trying till it returns ture
                wait.Until(d => {
                    // use d instead of driver below?

                    try
                    {
                        state = ((IJavaScriptExecutor)driver).ExecuteScript(@"return document.readyState").ToString();
                    }
                    catch (InvalidOperationException)
                    {
                        //Ignore
                    }
                    catch (NoSuchWindowException)
                    {
                        //when popup is closed, switch to last windows
                        driver.SwitchTo().Window(driver.WindowHandles[driver.WindowHandles.Count - 1]);
                    }
                    //In IE7 there are chances we may get state as loaded instead of complete
                    return(state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) ||
                           state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase));
                });
            }
            catch (TimeoutException)
            {
                //sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls
                if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase))
                {
                    throw;
                }
            }
            catch (NullReferenceException)
            {
                //sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls
                if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase))
                {
                    throw;
                }
            }
            catch (WebDriverException)
            {
                if (driver.WindowHandles.Count == 1)
                {
                    driver.SwitchTo().Window(driver.WindowHandles[0]);
                }
                state = ((IJavaScriptExecutor)driver).ExecuteScript(@"return document.readyState").ToString();
                if (!(state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) || state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase)))
                {
                    throw;
                }
            }

            timer.Stop();
            srpt.LogData($"WaitForPageLoad elapsed: {timer.MsecFloat}", 1, MSGT.Body);
        }
Exemple #16
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;
            }
        }
        public bool slowInit(string comportnumber, int ecuaddr, int baudrate)
        {
            clear();

            _ecuaddr  = ecuaddr;
            _baudrate = baudrate;

            try
            {
                if (!_initIsDone)
                {
                    _timer          = new System.Timers.Timer(10);
                    _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);

                    //micro timer is used for precise events such as the 5baud init
                    //sleep is not accurate enough with all computers even with MM period set to 1ms
                    _microTimer = new MicroTimer(BIT_INTERVAL_5B * 1000);
                    _microTimer.MicroTimerElapsed += new MicroLibrary.MicroTimer.MicroTimerElapsedEventHandler(microTimerEvent);

                    if (_port.IsOpen)
                    {
                        _port.Close();
                    }
                    _port.Encoding = Encoding.GetEncoding("ISO-8859-1");
                    _port.BaudRate = 5;
                    _port.PortName = comportnumber;
                    _port.ReceivedBytesThreshold = 1;
                    _port.DataReceived          += new SerialDataReceivedEventHandler(_port_DataReceived);
                    _port.Open();
                    try
                    {
                        _port.Handshake  = Handshake.None;
                        _port.RtsEnable  = true;
                        _port.BreakState = false;
                        _port.DtrEnable  = true;
                    }
                    catch (Exception E)
                    {
                        //AddToLog("Failed to set pins: " + E.Message);
                    }
                    //no need for this anymore
                    //MM_BeginPeriod(1);
                    //Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; // high prio thread
                    _initIsDone = true;
                }
                else
                {
                    //MM_BeginPeriod(1);
                    if (_port.IsOpen)
                    {
                        _port.Close();
                    }
                    _port.BaudRate = _baudrate;
                    _port.PortName = comportnumber;
                    _port.Open();
                }

                _timer.Enabled      = true;
                _microTimer.Enabled = true;
                return(true);
            }
            catch (Exception E)
            {
                _ecustate = ICommunication.ECUState.NotInitialized;
                CastInfoEvent("Failed to initialize: " + E.Message, 0);
                Console.WriteLine("Failed to initialize: " + E.Message);
            }
            return(false);
        }