Note of Using Visual C#

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 DioInit function

Ret = dio.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 interrupt or a trigger 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 interrupt.
For details, please refer to the sample programs.

Declaring as global variables.

GCHandle gCh;
PINTCALLBACK 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 PINTCALLBACK(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 DioSetInterruptCallBackProc.

Ret = dio.SetInterruptCallBackProc(Id, pfunc, Temp);

Note of using DioDmSetBuffer()

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_SIZE = 1000; //buffer size for busmaster
GCHandle       gCh;
static uint[]  DataBuff = new uint[DATA_SIZE]; //buffer for busmaster
IntPtr         pDataBuff;

In the Load method, assigning a handle of Pinned type to the buffer.

if (gCh.IsAllocated == false)
{
    gCh = GCHandle.Alloc(DataBuff, GCHandleType.Pinned);
}

In the Closed method, releasing the handle.

if (gCh.IsAllocated == true)
{
    gCh.Free();
}

Retrieving the pointer of fixed object.

pDataBuff = gCh.AddrOfPinnedObject();

Specifying the retrieved fixed pointer by function DioDmSetBuffer.

Ret = dio.DmSetBuffer(m_Id, Direction, pDataBuff, DATA_SIZE, (short)CdioConst.DIODM_WRITE_ONCE);