LJM_INTERVAL_CLOCK_TYPE | LabJack
 
« Close

Datasheets and User Guides

App Notes

Software & Driver

 
Saturday/Sunday, March 28th&29th, 2020
Support: LabJack engineers available through email and chat.
Shipping: We are processing and shipping all orders.
Stock: 55/56 products in stock.
Supply Chain: Some disruptions.

LJM_INTERVAL_CLOCK_TYPE

Theoretical API

LJM_INTERVAL_CLOCK_TYPE is a suggested API. It is in the process of evaluation. It will likely be included in LJM 1.21.

Summary

Sets which type of clock LJM_StartInterval initializes for a given IntervalHandle. LJM_WaitForNextInterval will then use the given clock type for that IntervalHandle.

LJM_INTERVAL_CLOCK_TYPE_STEADY = 1 (default)

  • The time between ticks of the steady clock is constant.
  • Steady clock is not affected by Network Time Protocol (NTP) updates or updates the system clock.
  • This clock is appropriate for consistent timing performed on a single computer.
  • LJM_INTERVAL_CLOCK_TYPE_STEADY is implemented in C++ via std::chrono::steady_clock, or via std::chrono::high_resolution_clock if high_resolution_clock is a steady clock.

LJM_INTERVAL_CLOCK_TYPE_SYSTEM = 2

  • The system clock is also known as the wall clock.
  • It can jump forward or backward. This can happen due to NTP updates or due to manually setting the system clock.
  • This clock can be appropriate for a shared interval across multiple computers over long times. Because NTP prevents clock drift (relative to the NTP time), multiple computers getting NTP updates to the system time will perform the same number of iterations when performing intervals based on the system clock.
  • LJM_INTERVAL_CLOCK_TYPE_SYSTEM is implemented in C++ via std::chrono::system_clock, or via std::chrono::high_resolution_clock if high_resolution_clock is not a steady clock.

The constant LJM_INTERVAL_CLOCK_TYPE can be used interchangeably with the string "LJM_INTERVAL_CLOCK_TYPE".

Remarks

LJM_INTERVAL_CLOCK_TYPE does not affect any previously initialized IntervalHandle.

Relevant Functions

To read LJM_INTERVAL_CLOCK_TYPE, use LJM_ReadLibraryConfigS.

To write LJM_INTERVAL_CLOCK_TYPE, use LJM_WriteLibraryConfigS or LJM_LoadConfigurationFile.

Example

[C/C++] Set the LJM_INTERVAL_CLOCK_TYPE mode to LJM_INTERVAL_CLOCK_TYPE_SYSTEM:

int LJMError = 0;
LJMError = LJM_WriteLibraryConfigS(
     LJM_INTERVAL_CLOCK_TYPE,
     LJM_INTERVAL_CLOCK_TYPE_SYSTEM
);
ErrorCheck(LJMError, "LJM_WriteLibraryConfigS");

int SkippedIntervals;
const int INTERVAL_HANDLE = 1;
const int ONE_SECOND = 1000 * 1000; // One second in microseconds
LJMError = LJM_StartInterval(INTERVAL_HANDLE, ONE_SECOND);
ErrorCheck(LJMError, "LJM_StartInterval");

for (int loop = 0; loop < 100; loop++) {
    ReadAndOutput(handle, "AIN0");

    LJMError = LJM_WaitForNextInterval(INTERVAL_HANDLE, &SkippedIntervals);
    ErrorCheck(LJMError, "LJM_WaitForNextInterval");
    if (SkippedIntervals > 0) {
        printf("SkippedIntervals: %d\n", SkippedIntervals);
    }
}

For more LJM configurations, see Library Configuration Functions.