• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • CDPTimerMs
  • 4.11.3

CDPTimerMs Class

The CDPTimerMs is used instead of CDPTimer where the time delay is longer than 1 ms and the resolution is longer than 1 ms. More...

Header: #include <OSAPI/Timer/CDPTimerMs.h>
Inherits: CDP::StudioAPI::CDPNode
  • List of all members, including inherited members

Public Functions

CDPTimerMs(bool editableTimeout = false)
virtual void Create(const char *shortName, CDPBaseObject *pParent)
double Delay()
double DeltaTime()
virtual void Destroy()
double Frequency()
bool IsRunning()
double LastTime()
void Reset(double delay)
void Reset()
void Restart()
void Set()
void SetModel(const std::string &model)
void SetTimeoutDelayCallback(std::function<void( CDP::StudioAPI::CDPVariantValue ) > callback)
virtual void Start()
bool State()
double Time()
double TimeElapsed()
bool TimedOut()

Reimplemented Public Functions

virtual void FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const override
virtual const std::string GetNodeName() const override
virtual std::string GetNodeTypeName() const override
  • 26 public functions inherited from CDP::StudioAPI::CDPNode
  • 22 public functions inherited from CDP::StudioAPI::ICDPNode

Protected Variables

CDPSetting<double> m_currentTime
CDPSetting<std::string> m_model
CDPSetting<double> m_previousTime
CDPSetting<bool> m_running
CDPSetting<double> m_startTime
CDPSetting<double> m_timeElapsed
CDPSetting<bool> m_timedout
CDPSetting<double> m_timeoutDelay
CDPSetting<double> m_timeoutTime

Additional Inherited Members

  • 1 protected function inherited from CDP::StudioAPI::CDPNode

Detailed Description

The CDPTimerMs is used instead of CDPTimer where the time delay is longer than 1 ms and the resolution is longer than 1 ms.

Real-time timer for delay and time monitoring with 1 ms resolution. Provides better performance by reducing the cpu load, but should not be used in threads. May be used as delay timer, does not need to know sample interval.

Note that 1 ms resolution is only true if any components are running at 1000Hz. CDPTimerMs gets its value from globalTime which is updated by CDPEngine scheduler. Resolution may also become better than 1ms, if any components are running faster than 1000Hz.

If the timer is used in a CDPComponent based class, the timer and it's values may show up in CDP Studio under the component's Timers section if Create() is called. In component's Create(), call myTimer.Create("MyTimer",this), and in component's Destroy(), call myTimer.Destroy().

Use as delay timer:

  • Init using Reset(delay in s);
  • Call Start() (or Restart()) to enable timeout checking.
  • Call TimedOut() to check if time has expired.
  • Call Restart() to reset and start new timeout check when time has expired.

Use as stopwatch-timer:

  • Call Start() to Start the timer.
  • Read time elapsed since Start() was called, with TimeElapsed().
  • Call TimedOut() to start timing. Timer initialises automatically on first run.
  • Call TimedOut() again to stop timing.
  • Read time in s between two last TimedOut() calls, with DeltaTime().

See also CDPParameterTimerMs, CDPTimer, CDPParameterTimer, OSAPIPeriodicTimer, OSAPIOneShotTimer, CDPTimerCounting, CDPRampTimer, and CDPComponent::RunInComponentThread.

Member Function Documentation

CDPTimerMs::CDPTimerMs(bool editableTimeout = false)

Constructs a CDPTimerMs instance.

[virtual] void CDPTimerMs::Create(const char *shortName, CDPBaseObject *pParent)

Stores shortName, calls parent's RegisterCDPNode() and sets up callback when m_timeoutDelay changes.

double CDPTimerMs::Delay()

Returns the delay (in seconds) set by Reset(delay).

double CDPTimerMs::DeltaTime()

Returns time (in seconds) between last two TimedOut() calls.

This method allows a CDPTimer to be used as stop-watch. Interval time in sec = delta count / timer counts per sec.

[virtual] void CDPTimerMs::Destroy()

Calls parent's UnRegisterCDPNode().

[override virtual] void CDPTimerMs::FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const

Reimplemented from CDPNode::FillNodeChildren().

Writes its CDPSettings to stream.

double CDPTimerMs::Frequency()

Returns frequency in Hz of time interval between last two TimedOut() calls (equals 1.0/DeltaTime()).

[override virtual] const std::string CDPTimerMs::GetNodeName() const

Reimplemented from ICDPNode::GetNodeName().

Returns m_timerName

[override virtual] std::string CDPTimerMs::GetNodeTypeName() const

Reimplemented from ICDPNode::GetNodeTypeName().

Returns "CDPTimerMs"

bool CDPTimerMs::IsRunning()

Returns true if timer is running.

double CDPTimerMs::LastTime()

Returns time [s] (since application startup), as calculated by the previous TimedOut() call.

void CDPTimerMs::Reset(double delay)

Resets and sets the delay timeout in seconds.

void CDPTimerMs::Reset()

Resets the timeout timer flag and stops the timer.

This method automatically intitialises the timer if necessary. Remember to call Start() to enable the timeout timer after a call to Reset().

void CDPTimerMs::Restart()

Resets and starts the timer.

void CDPTimerMs::Set()

Sets m_timedout to true.

void CDPTimerMs::SetModel(const std::string &model)

Sets m_model of CDPTimer.

void CDPTimerMs::SetTimeoutDelayCallback(std::function<void( CDP::StudioAPI::CDPVariantValue ) > callback)

Sets up callback when m_timeoutDelay changes.

[virtual] void CDPTimerMs::Start()

Starts the timer.

bool CDPTimerMs::State()

Returns the state of the timeout flag as calculated by the previous TimedOut() call.

double CDPTimerMs::Time()

Returns time [s] since application startup.

See also DeltaTime().

double CDPTimerMs::TimeElapsed()

Returns time (in seconds) elapsed since Start() or Restart() was called.

Works irrespective of Reset() or TimedOut() calls.

bool CDPTimerMs::TimedOut()

Returns true if timer has timed out.

Automatic timer system initialisation if Init() has not been called. Remember to Restart() the timer after reaching timeout delay time. It is not necessary to call TimedOut() periodically at an accurate time interval, the timer keeps track of real time internally.

See also DeltaTime() and Time() methods for timing.

Member Variable Documentation

CDPSetting<double> CDPTimerMs::m_currentTime

This variable holds current time [s]. Updated by TimedOut().

CDPSetting<std::string> CDPTimerMs::m_model

This variable holds timer object's modelname ('CDPTimerMs').

CDPSetting<double> CDPTimerMs::m_previousTime

This variable holds previous time [s]. Updated by TimedOut().

CDPSetting<bool> CDPTimerMs::m_running

This variable holds set to true when timer is running.

CDPSetting<double> CDPTimerMs::m_startTime

This variable holds time when Start() was called [s].

CDPSetting<double> CDPTimerMs::m_timeElapsed

This variable holds time elapsed [s] since Start()/Restart(), as calculated by TimedOut() function.

CDPSetting<bool> CDPTimerMs::m_timedout

This variable holds set to true when timer has timed out.

CDPSetting<double> CDPTimerMs::m_timeoutDelay

This variable holds timeout delay [s]. Set in Reset(double delay) and returned in Delay().

CDPSetting<double> CDPTimerMs::m_timeoutTime

This variable holds timeout absolute time [s]. Sum of m_startTime and m_timeoutDelay, set in Start().

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

    © Copyright 2022 CDP Technologies. Privacy and cookie policy.

    Return to top