Function specifications
The class library is being offered as an
interface for C#.
The driver functions are called from the methods of the class library.
The methods in the class library are defined in the form of removing the
prefix of original functions.
Please call the method with the name that does not contain the prefix of
original function.
For example, when you want to call the CntInit function
Ret = cnt.Init();
* Not compatible with Universal Windows Platform
(UWP)
Function parameters and return value
The contents of the parameters and the return
value of functions are common regardless of the development language.
Please refer to the function reference for details.
Note of using callback function
When notifying an event by using callback
function in Visual C#,
it is required to fix the callback function's memory address.
The following code is the sample to process an count match event.
For details, please refer to the sample programs.
■ Declaring as global variables.
GCHandle gCh;
PCOUNTUPCALLBACK pdelegate_func;
IntPtr pfunc;
■ In the Load method, initializing the delegate for interrupt process, and add a reference to prevent garbage collection from being destroyed.
pdelegate_func = new PCOUNTUPCALLBACK(CallBackProc);
gCh = GCHandle.Alloc(pdelegate_func);
■ In the Close method, releasing the handle.
gCh.Free();
■ Retrieving the fixed function pointer.
pfunc = Marshal.GetFunctionPointerForDelegate(pdelegate_func);
■ Specifying the retrieved fixed pointer by function CntCountUpCallbackProc.
Ret = cnt.CountUpCallbackProc(Id, pfunc, Temp);
Note of using CntSamplingSetBuffer()
In Visual C#, for the buffer used for bus
master transfer, it is required to add process for fixing memory address.
The following code is the sample for this process.
For details, please refer to the sample programs.
■ Declaring as global variables.
const int DATA_NUM
= 1000; //
Buffer size for bus master
public const int CHANNEL_NUM = 4;
uint[,] SamplingData
= new uint[DATA_NUM, CHANNEL_NUM]; // Buffer for bus master
GCHandle gCh;
IntPtr pSamplingData;
■ In the Load method, assigning a handle of Pinned type to the buffer.
if (gCh.IsAllocated == false)
{
gCh = GCHandle.Alloc(SamplingData, GCHandleType.Pinned);
}
■ In the Closed method, releasing the handle.
if (gCh.IsAllocated == true)
{
gCh.Free();
}
■ Retrieving the pointer of fixed object.
pSamplingData = gCh.AddrOfPinnedObject();
■ Specifying the retrieved fixed pointer by function CntSamplingSetBuffer.
ret = cnt.SamplingSetBuffer(Id,
pSamplingData, CHANNEL_NUM, DATA_NUM, (short)CcntConst.CNTS_WRITE_ONCE);