Enable NI-TClk Support for an NI Modular Instruments.NET Source Code Wrapper API

Updated Aug 2, 2023

Environment

Driver

  • NI-FGEN
  • NI-DCPower
  • NI-HSDIO
  • NI-DMM
  • NI-RFSA
  • NI-RFSG

I am writing an application using a modular instruments .NET source code wrapper API, and I would like to use NI-TClk technology to synchronize some modular instruments devices. I've noticed that the NI-TClk class library operates on objects which implement the ITClockSynchronizableDevice interface, but the source code wrapper I'm using does not implement it, even though it controls devices compatible with NI-TClk.

How do I implement the ITClockSynchronizableDevice interface for the modular instruments .NET source code wrapper API I am using?

To implement the ITClockSynchronizableDevice interface in the .NET source code wrapper API, complete the following steps:
 

1. In your project, add a reference to the NationalInstruments.ModularInstruments.Common assembly. Right-click References in Solution Explorer, select Add Reference, and in the Extensions tab of the Reference Manager window, choose the version of NationalInstruments.ModularInstruments.Common for the version of the .NET framework you are using.

Note: The NationalInstruments.ModularInstruments.Common assembly installs with the NI native .NET APIs for modular instruments devices. You can find where to download a .NET native API in the NI .NET Driver Support document.

2. Add the following line to the top of the source code wrapper:
using NationalInstruments.ModularInstruments;
 

3. Modify the driver class definition to implement the ITClockSynchronizableDevice interface. This looks like the following for an example driver called niMyDriver:
class niMyDriver: object, System.IDisposable, ITClockSynchronizableDevice {    // ... }
 

4. Implement the ITClockSynchronizableDevice interface on the driver class. The ITClockSynchronizableDevice interface requires that you implement a read-only property which returns a reference to the underlying modular instrument session handle.

To start, right-click ITClockSynchronizableDevice and select Implement Interface»Implement Interface. This generates the following code that you will modify to implement the interface, which defines only a single property:
public HandleRef Handle {    get { throw new NotImplementedException(); } }

The .NET source code wrapper you are modifying should contain a field called _handle which is used to identify the driver session when calling methods on the PInvoke class. The _handle field is implemented either as a System.IntPtr or HandleRef type. To implement the Handle property for the ITClockSynchronizableDevice interface if _handle is of type System.IntPtr, return a new HandleRef for the _handle field in the get accessor for the Handle property, as follows:
public HandleRef Handle {    get    {       return new HandleRef( this, this._handle );    } }

To implement the Handle property for the ITClockSynchronizableDevice interface if _handle is of type HandleRef, return the _handle field in the get accessor for the Handle property, as follows:

public HandleRef Handle {    get { return this._handle; } }
 

Once you have implemented the ITClockSynchronizableDevice interface, you can use the NI-TClk library, NationalInstruments.ModularInstruments.TClock, to synchronize your instruments. To obtain the NI-TClk library, install an NI native .NET API for hardware that supports NI-TClk synchronization (e.g., NI-SCOPE). The NI native .NET API installer installs examples which demonstrate the use of NI-TClk and documentation which describes how to use it.