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 LoggerOpenApplication function
Ret = logger.OpenApplication();
* Not compatible with Universal Windows Platform (UWP)
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.
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 the analog input event that
device operation end.
For details, please refer to the sample programs.
■ Declaring as global variables.
GCHandle gCh;
PLOGGEREVENTCALLBACK 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 PLOGGEREVENTCALLBACK(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 LoggerSetNotifyEvent.
Ret = logger.SetNotifyEvent(Id, pfunc, (uint)CLoggerConst.LOGGER_PARAM_EVENT_DATANUM, null);
The fifth(5) argument to LoggerSetChannelSetting()
function, ChannelName, is a Byte array.
Therefore, you can not use a string variable for parameter of ChannelName
directly.
You must convert a string variable to a Byte array before.
The following code example shows how to convert
a string variable to a Byte array.
See the sample program for details.
■Declare a Byte array and an Encoding class.
string ChName;
Encoding Enc;
For more information on Encoding class, see Microsoft Web site.
System.Text.Encoding Text.Encoding Class: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding
■Converts the string "Channel0" to a Byte array, given the code page identifier "Windows-1252".
byte SearchByte = 0;
int Length;
Length = Array.IndexOf(ChannelName, SearchByte);
For more information about the GetEncoding and GetBytes methods, see the Microsoft Web site.
Encoding.GetEncoding Method: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding
Encoding.GetBytes Method: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getbytes
Code page identifiers: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
The fifth(5) argument to LoggerGetChannelSetting()
function, ChannelName, is a Byte array.
Therefore, you can not use ChannelName as a string variable directly.
You must convert a Byte array to a string variable before.
The following code example shows how to convert
a Byte array into a string variable ChName.
See the sample program for details.
■Declare a string variable and an encoding class.
string ChName;
Encoding Enc;
For more information on Encoding class, see Microsoft Web site.
System.Text.Encoding Text.Encoding Class: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding
■Search from the beginning of the ChannelName array to the terminating character "\0" to get Length as well as the number of valid characters.
byte SearchByte = 0;
int Length;
Length = Array.IndexOf(ChannelName, SearchByte);
For more information on Array class andIndexOf method, see Microsoft Web site.
System.Array class: https://learn.microsoft.com/en-us/dotnet/api/system.array
Array.IndexOf method: https://learn.microsoft.com/en-us/dotnet/api/system.array.indexof
■Converts a Byte array ChannelName to a string variable ChName, given the code page identifier "Windows-1252".
Enc = System.Text.Encoding.GetEncoding("Windows-1252");
ChName = Enc.GetString(ChannelName, 0, Length);
For more information about GetEncoding and GetString methods, see Microsoft Web site.
Encoding.GetEncoding Method: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding
Encoding.GetString Method: https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getstring
Code page identifiers: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers