Note of Using Visual Basic .NET

Function specifications

Win32API format
* 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 Basic .NET, 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.

Dim gCh As GCHandle
Dim pdelegate_func As PLOGGEREVENTCALLBACK
Dim pfunc As IntPtr

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(AddressOf 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 = LoggerSetNotifyEvent(Id, pfunc, CType(LOGGER_PARAM_EVENT_DATANUM, UInteger), Nothing)

 

Convert a string variable to a Byte array

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.

Dim ChannelName(255) As Byte
Dim Enc As Encoding

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".

Enc = System.Text.Encoding.GetEncoding("Windows-1252")
ChannelName = Enc.GetBytes("Channel 0")

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

 

Convert a Byte array to a string variable

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.

Dim ChName As String
Dim Enc As Encoding

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.

Dim SearchByte As Byte = 0
Dim Length As Integer

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