/// <summary> /// Does the test - this is main function that is executed as the handler. /// </summary> /// <param name="error">The _minmaxavg_error counter</param> /// <param name="OperationSpan">The _minmaxavg_opertime counter.</param> /// <param name="cycleTime">The _minmaxavg_scanrate counter.</param> /// <returns></returns> public void DoTest(ref MinMaxAvr error, ref MinMaxAvr operationSpan, ref MinMaxAvr cycleTime) { m_OperationSpanStopwatch.Reset(); m_OperationSpanStopwatch.Start(); m_CycleTimeStopwatch.Stop(); cycleTime.Add = m_CycleTimeStopwatch.ElapsedMilliseconds; m_CycleTimeStopwatch.Reset(); m_CycleTimeStopwatch.Start(); m_CurrentTime = m_RunTimeStopwatch.Elapsed; double _currentError; if (m_AutoReset) { _currentError = (Math.Abs(m_CurrentTime.TotalMilliseconds - m_ExpectedTime.TotalMilliseconds) / m_CycleSpan.TotalMilliseconds) * 100.0; m_ExpectedTime = m_RunTimeStopwatch.Elapsed + m_CycleSpan; System.Threading.Thread.Sleep(Convert.ToInt32(m_OperationDuration.TotalMilliseconds)); } else { _currentError = (Math.Abs(m_CurrentTime.TotalMilliseconds - m_ExpectedTime.TotalMilliseconds) / (m_CycleSpan + m_OperationDuration).TotalMilliseconds) * 100.0; System.Threading.Thread.Sleep(Convert.ToInt32(m_OperationDuration.TotalMilliseconds)); this.ResetCounter(); m_ExpectedTime = m_RunTimeStopwatch.Elapsed + m_CycleSpan; } error.Add = (long)_currentError; m_OperationSpanStopwatch.Stop(); operationSpan.Add = m_OperationSpanStopwatch.ElapsedMilliseconds; }
/// <summary> /// Initializes a new instance of the <see cref="Protocol" /> class. /// </summary> /// <param name="protocolPar">The protocol parameters.</param> /// <param name="Name">The name.</param> /// <param name="ID">The ID.</param> /// <param name="protocolPar_humanreadable">The protocol human readable description.</param> /// <param name="settingsBase">The settings base.</param> protected Protocol(string protocolPar, string Name, long ID, string protocolPar_humanreadable, ISettingsBase settingsBase) { m_SettingsBase = settingsBase ?? throw new ArgumentNullException("Settings provider must not be empty"); m_Descriptor = new ProtocolDsc(protocolPar, Name, ID, protocolPar_humanreadable); ProtocolList.Add(ID, this); m_TimeSlaveResponseDelay = new MinMaxAvr((ushort)m_SettingsBase["MinAvgMax_FrameResponse_management"]); m_TimeMaxResponseDelay = new MinMaxAvr((ushort)m_SettingsBase["MinAvgMax_FrameResponse_management"]); m_TimeCharGap = new MinMaxAvr((ushort)m_SettingsBase["MinAvgMax_CharacterGap_management"]); m_TimeMaxResponseDelay.MarkNewVal += new MinMaxAvr.newVal(TimeMaxResponseDelayEvHndlr); m_TimeCharGap.MarkNewVal += new MinMaxAvr.newVal(TimeCharGapEvHndlr); }
public void MinMaxAvrTestMethod() { MinMaxAvr _testVar = new MinMaxAvr(10); Assert.AreEqual(_testVar.Max, 0); Assert.AreEqual(_testVar.Min, 0); Assert.AreEqual(_testVar.Avr, 0); bool _result = false; _testVar.MarkNewVal += (x, z, y) => _result = (x == 10) && (y == 14) && (z == 19); for (int i = 10; i <= 20; i++) { _testVar.Add = i; } Assert.IsTrue(_result, "MinMaxAvr doesn't work as expected"); Assert.AreEqual(_testVar.Max, 19); Assert.AreEqual(_testVar.Min, 10); Assert.AreEqual(_testVar.Avr, 14); }