﻿Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices

Public Class Form1
    '----------------------------------------
    ' Macro definition
    '----------------------------------------
    Public Const MAX_AI_RANGE_NUM As Integer = 32                             ' Maximum number of elements in analog output range array
    Public Const DISPLAY_SAMPLING_COUNT As Integer = 1000                     ' Maximum sampling count of sampling data displayed in listbox

    '----------------------------------------
    ' Declaration of global variables
    '----------------------------------------
    Dim g_master_id As Short                                                  ' [Master] ID for device access
    Dim g_slave_id As Short                                                   ' [Slave]  ID for device access
    Dim g_master_sampling_count As Long                                       ' [Master] Total sampling count
    Dim g_slave_sampling_count As Long                                        ' [Slave]  Total sampling count
    Dim g_master_sampling_data() As Single = Nothing                          ' [Master] Pointer to sampling data storage area
    Dim g_slave_sampling_data() As Single = Nothing                           ' [Slave]  Pointer to sampling data storage area
    Dim gCh_master_sampling_data As GCHandle                                  ' GCHandle for g_master_sampling_data array
    Dim gCh_slave_sampling_data As GCHandle                                   ' GCHandle for g_slave_sampling_data array
    Dim g_ai_range() As Short = New Short(MAX_AI_RANGE_NUM - 1) {PM10,        ' +/-10V
                                                                 PM5,         ' +/-5V
                                                                 PM25,        ' +/-2.5V
                                                                 PM125,       ' +/-1.25V
                                                                 PM1,         ' +/-1V
                                                                 PM0625,      ' +/-0.625V
                                                                 PM05,        ' +/-0.5V
                                                                 PM03125,     ' +/-0.3125V
                                                                 PM025,       ' +/-0.25V
                                                                 PM0125,      ' +/-0.125V
                                                                 PM01,        ' +/-0.1V
                                                                 PM005,       ' +/-0.05V
                                                                 PM0025,      ' +/-0.025V
                                                                 PM00125,     ' +/-0.0125V
                                                                 PM001,       ' +/-0.01V
                                                                 P10,         ' 0 ~ 10V
                                                                 P5,          ' 0 ~ 5V
                                                                 P4095,       ' 0 ~ 4.095V
                                                                 P25,         ' 0 ~ 2.5V
                                                                 P125,        ' 0 ~ 1.25V
                                                                 P1,          ' 0 ~ 1V
                                                                 P05,         ' 0 ~ 0.5V
                                                                 P025,        ' 0 ~ 0.25V
                                                                 P01,         ' 0 ~ 0.1V
                                                                 P005,        ' 0 ~ 0.05V
                                                                 P0025,       ' 0 ~ 0.025V
                                                                 P00125,      ' 0 ~ 0.0125V
                                                                 P001,        ' 0 ~ 0.01V
                                                                 P20MA,       ' 0 ~ 20mA
                                                                 P4TO20MA,    ' 4 ~ 20mA
                                                                 PM20MA,      ' +/-20mA
                                                                 P1TO5}       ' 1 ~ 5V

    Private Sub SyncBusSampling_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '----------------------------------------
        ' Set the default button
        '----------------------------------------
        AcceptButton = Button_Close
        '----------------------------------------
        ' [Master] Update the initial display of device name
        '----------------------------------------
        TextBox_MasterDeviceName.Text = "AIO000"
        '----------------------------------------
        ' [Master] Update the initial display of number of channels for analog input
        '----------------------------------------
        TextBox_MasterAiChNum.Text = "1"
        '----------------------------------------
        ' [Master] Update the initial display of sampling clock
        '----------------------------------------
        TextBox_MasterInternalClock.Text = "1000"
        '----------------------------------------
        ' [Master] Update the initial display of sampling stop times
        '----------------------------------------
        TextBox_MasterStopTimes.Text = "1000"
        '----------------------------------------
        ' [Master] Create the combobox for analog input method
        '----------------------------------------
        ComboBox_MasterAiInpMethod.Items.Add("Single-end input")
        ComboBox_MasterAiInpMethod.Items.Add("Differential input")
        '----------------------------------------
        ' [Master] Change the selection of analog input method combobox to 0
        '----------------------------------------
        ComboBox_MasterAiInpMethod.SelectedIndex = 0
        '----------------------------------------
        ' [Master] Create the combobox for analog input range
        '----------------------------------------
        ComboBox_MasterAiRangeValue.Items.Add("-10 - +10V")
        ComboBox_MasterAiRangeValue.Items.Add("-5 - +5V")
        ComboBox_MasterAiRangeValue.Items.Add("-2.5 - +2.5V")
        ComboBox_MasterAiRangeValue.Items.Add("-1.25 - +1.25V")
        ComboBox_MasterAiRangeValue.Items.Add("-1 - +1V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.625 - +0.625V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.5 - +0.5V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.3125 - +0.3125V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.25 - +0.25V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.125 - +0.125V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.1 - +0.1V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.05 - +0.05V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.025 - +0.025V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.0125 - +0.0125V")
        ComboBox_MasterAiRangeValue.Items.Add("-0.01 - +0.01V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +10V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +5V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +4.095V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +2.5V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +1.25V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +1V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +0.5V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +0.25V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +0.1V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +0.05V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +0.025V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +0.0125V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +0.01V")
        ComboBox_MasterAiRangeValue.Items.Add("0 - +20mA")
        ComboBox_MasterAiRangeValue.Items.Add("4 - +20mA")
        ComboBox_MasterAiRangeValue.Items.Add("-20mA - +20mA")
        ComboBox_MasterAiRangeValue.Items.Add("1 - +5V")
        '----------------------------------------
        ' [Master] Change the selection of analog input range combobox to 0
        '----------------------------------------
        ComboBox_MasterAiRangeValue.SelectedIndex = 0
        '----------------------------------------
        ' [Slave]  Update the initial display of device name
        '----------------------------------------
        TextBox_SlaveDeviceName.Text = "AIO001"
        '----------------------------------------
        ' [Slave]  Update the initial display of number of channels for analog input
        '----------------------------------------
        TextBox_SlaveAiChNum.Text = "1"
        '----------------------------------------
        ' [Slave]  Create the combobox for analog input method
        '----------------------------------------
        ComboBox_SlaveAiInpMethod.Items.Add("Single-end input")
        ComboBox_SlaveAiInpMethod.Items.Add("Differential input")
        '----------------------------------------
        ' [Slave]  Change the selection of analog input method combobox to 0
        '----------------------------------------
        ComboBox_SlaveAiInpMethod.SelectedIndex = 0
        '----------------------------------------
        ' [Slave]  Create the combobox for analog input range
        '----------------------------------------
        ComboBox_SlaveAiRangeValue.Items.Add("-10 - +10V")
        ComboBox_SlaveAiRangeValue.Items.Add("-5 - +5V")
        ComboBox_SlaveAiRangeValue.Items.Add("-2.5 - +2.5V")
        ComboBox_SlaveAiRangeValue.Items.Add("-1.25 - +1.25V")
        ComboBox_SlaveAiRangeValue.Items.Add("-1 - +1V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.625 - +0.625V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.5 - +0.5V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.3125 - +0.3125V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.25 - +0.25V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.125 - +0.125V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.1 - +0.1V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.05 - +0.05V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.025 - +0.025V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.0125 - +0.0125V")
        ComboBox_SlaveAiRangeValue.Items.Add("-0.01 - +0.01V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +10V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +5V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +4.095V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +2.5V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +1.25V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +1V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +0.5V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +0.25V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +0.1V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +0.05V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +0.025V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +0.0125V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +0.01V")
        ComboBox_SlaveAiRangeValue.Items.Add("0 - +20mA")
        ComboBox_SlaveAiRangeValue.Items.Add("4 - +20mA")
        ComboBox_SlaveAiRangeValue.Items.Add("-20mA - +20mA")
        ComboBox_SlaveAiRangeValue.Items.Add("1 - +5V")
        '----------------------------------------
        ' [Slave]  Change the selection of analog input range combobox to 0
        '----------------------------------------
        ComboBox_SlaveAiRangeValue.SelectedIndex = 0
        '----------------------------------------
        ' Initialize global variables
        '----------------------------------------
        g_master_id = 0
        g_slave_id = 0
        g_master_sampling_count = 0
        g_slave_sampling_count = 0
    End Sub

    '================================================================================
    ' It is the process when the AioInit button is clicked
    ' Initialize the device
    '================================================================================
    Private Sub Button_AioInit_Click(sender As Object, e As EventArgs) Handles Button_AioInit.Click
        Dim device_name As String                         ' Device name
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' [Master] Get device name from textbox
        '----------------------------------------
        device_name = TextBox_MasterDeviceName.Text
        '----------------------------------------
        ' [Master] Device initialization
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioInit(device_name, g_master_id)
        '----------------------------------------
        ' [Master] Get error string
        '----------------------------------------
        AioGetErrorString(ret, error_string)
        '----------------------------------------
        ' [Master] Display message
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "AioInit = " & ret & " : " & error_string.ToString()
        '----------------------------------------
        ' [Slave]  Get device name from textbox
        '----------------------------------------
        device_name = TextBox_SlaveDeviceName.Text
        '----------------------------------------
        ' [Slave]  Device initialization
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioInit(device_name, g_slave_id)
        '----------------------------------------
        ' [Slave]  Get error string
        '----------------------------------------
        AioGetErrorString(ret, error_string)
        '----------------------------------------
        ' [Slave]  Display message
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "AioInit = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' It is the process when the AioResetDevice button is clicked
    ' Reset the device
    '================================================================================
    Private Sub Button_AioResetDevice_Click(sender As Object, e As EventArgs) Handles Button_AioResetDevice.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' [Master] Reset device
        '----------------------------------------
        ret = AioResetDevice(g_master_id)
        '----------------------------------------
        ' [Master] Get error string
        '----------------------------------------
        AioGetErrorString(ret, error_string)
        '----------------------------------------
        ' [Master] Display message
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "AioResetDevice = " & ret & " : " & error_string.ToString()
        '----------------------------------------
        ' [Slave]  Reset device
        '----------------------------------------
        ret = AioResetDevice(g_slave_id)
        '----------------------------------------
        ' [Slave]  Get error string
        '----------------------------------------
        AioGetErrorString(ret, error_string)
        '----------------------------------------
        ' [Slave]  Display message
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "AioResetDevice = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' It is the process when the Analog Input Set button is clicked
    ' Set the analog input settings
    '================================================================================
    Private Sub Button_AiSetting_Click(sender As Object, e As EventArgs) Handles Button_AiSetting.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim index As Integer                              ' Index of combobox
        Dim input_method As Short                         ' Input method

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' [Master] Get the index of analog input range setting value from combobox
        '----------------------------------------
        index = ComboBox_MasterAiRangeValue.SelectedIndex
        '----------------------------------------
        ' [Master] Set the analog input range (all channels)
        '----------------------------------------
        ret = AioSetAiRangeAll(g_master_id, g_ai_range(index))
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Analog Input Set: AioSetAiRangeAll = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Get the index of input method setting value from combobox
        '----------------------------------------
        input_method = ComboBox_MasterAiInpMethod.SelectedIndex
        '----------------------------------------
        ' [Master] Set the analog input method
        '----------------------------------------
        ret = AioSetAiInputMethod(g_master_id, input_method)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Analog Input Set: AioSetAiInputMethod = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Display the message that analog input settings is completed
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "Analog Input Set: Successful completion"
        '----------------------------------------
        ' [Slave]  Get the index of analog input range setting value from combobox
        '----------------------------------------
        index = ComboBox_SlaveAiRangeValue.SelectedIndex
        '----------------------------------------
        ' [Slave]  Set the analog input range (all channels)
        '----------------------------------------
        ret = AioSetAiRangeAll(g_slave_id, g_ai_range(index))
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Analog Input Set: AioSetAiRangeAll = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Get the index of input method setting value from combobox
        '----------------------------------------
        input_method = ComboBox_SlaveAiInpMethod.SelectedIndex
        '----------------------------------------
        ' [Slave]  Set the analog input method
        '----------------------------------------
        ret = AioSetAiInputMethod(g_slave_id, input_method)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Analog Input Set: AioSetAiInputMethod = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Display the message that analog input settings is completed
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "Analog Input Set: Successful completion"
    End Sub

    '================================================================================
    ' It is the process when the Sampling Set button is clicked
    ' Set the sampling settings
    '================================================================================
    Private Sub Button_SamplingSetting_Click(sender As Object, e As EventArgs) Handles Button_SamplingSetting.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code
        Dim ai_channels As Short                          ' Number of analog input channels
        Dim sampling_clock As Single                      ' Internal clock conversion speed
        Dim stop_times As Integer                         ' Sampling stop times

        '----------------------------------------
        ' [Slave]  Get the number of channels from textbox
        '----------------------------------------
        If (Short.TryParse(TextBox_SlaveAiChNum.Text, ai_channels) = False) Then
            ai_channels = 1
        End If
        '----------------------------------------
        ' [Slave]  Set the number of analog input channels used for conversion
        '----------------------------------------
        ret = AioSetAiChannels(g_slave_id, ai_channels)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Set: AioSetAiChannels = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Set the analog input conversion data transfer mode to device buffer mode
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiTransferMode(g_slave_id, 0)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Set: AioSetAiTransferMode = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Set the data storage memory type to FIFO
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiMemoryType(g_slave_id, 0)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Set: AioSetAiMemoryType = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Set the sampling start condition to Event controller output
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiStartTrigger(g_slave_id, 10)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Set: AioSetAiStartTrigger = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Set the clock type to Event controller output
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiClockType(g_slave_id, 10)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Set: AioSetAiClockType = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Set the sampling stop condition to Event controller output
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiStopTrigger(g_slave_id, 10)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Set: AioSetAiStopTrigger = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Set the event factor to 'Event that AD conversion start', 'Event that device operation end', 'Event that overflow', 
        ' 'Event that sampling clock error', and 'Event that AD conversion error'
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiEvent(g_slave_id, Handle, AIE_START Or AIE_END Or AIE_OFERR Or AIE_SCERR Or AIE_ADERR)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Set: AioSetAiEvent = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Display the message that sampling settings is completed
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "Sampling Set: Successful completion"
        '----------------------------------------
        ' [Master] Get the number of channels from textbox
        '----------------------------------------
        If (Short.TryParse(TextBox_MasterAiChNum.Text, ai_channels) = False) Then
            ai_channels = 1
        End If
        '----------------------------------------
        ' [Master] Set the number of analog input channels used for conversion
        '----------------------------------------
        ret = AioSetAiChannels(g_master_id, ai_channels)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiChannels = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Set the analog input conversion data transfer mode to device buffer mode
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiTransferMode(g_master_id, 0)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiTransferMode = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Set the data storage memory type to FIFO
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiMemoryType(g_master_id, 0)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiMemoryType = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Set the sampling start condition to Software
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiStartTrigger(g_master_id, 0)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiStartTrigger = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Set the clock type to Internal Clock
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiClockType(g_master_id, 0)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiClockType = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Get the internal clock conversion speed from textbox
        '----------------------------------------
        If (Single.TryParse(TextBox_MasterInternalClock.Text, sampling_clock) = False) Then
            sampling_clock = 1000
        End If
        '----------------------------------------
        ' [Master] Set the internal clock conversion speed
        '----------------------------------------
        ret = AioSetAiSamplingClock(g_master_id, sampling_clock)
        '----------------------------------------
        ' Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiSamplingClock = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Set the sampling stop condition to Stop conversion by the specified times
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiStopTrigger(g_master_id, 0)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiStopTrigger = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Get the sampling stop times from textbox
        '----------------------------------------
        If (Integer.TryParse(TextBox_MasterStopTimes.Text, stop_times) = False) Then
            stop_times = 1000
        End If
        '----------------------------------------
        ' [Master] Set the sampling stop times
        '----------------------------------------
        ret = AioSetAiStopTimes(g_master_id, stop_times)
        '----------------------------------------
        ' Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiStopTimes = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Set the event factor to 'Event that device operation end', 'Event that overflow', 
        ' 'Event that sampling clock error', and 'Event that AD conversion error'
        ' Caution for modify this function (if modified, the application may not work)
        '----------------------------------------
        ret = AioSetAiEvent(g_master_id, Handle, AIE_END Or AIE_OFERR Or AIE_SCERR Or AIE_ADERR)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Set: AioSetAiEvent = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Display the message that sampling settings is completed
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "Sampling Set: Successful completion"
    End Sub

    '================================================================================
    ' It is the process when the Sync Operation Set button is clicked
    ' Set the synchronous operation settings
    '================================================================================
    Private Sub Button_SyncSetting_Click(sender As Object, e As EventArgs) Handles Button_SyncSetting.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' [Master] Event Controller Setting: Connect Analog input internal clock signal to Synchronization bus master signal 1
        '----------------------------------------
        ret = AioSetEcuSignal(g_master_id, AIOECU_DEST_MASTER1, AIOECU_SRC_AI_CLK)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        '--------------------
        ' Exit the process if not completed successfully
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sync Operation Set: AioSetEcuSignal = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Event Controller Setting: Connect Ai software start signal to Synchronization bus master signal 2
        '----------------------------------------
        ret = AioSetEcuSignal(g_master_id, AIOECU_DEST_MASTER2, AIOECU_SRC_START)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        '--------------------
        ' Exit the process if not completed successfully
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sync Operation Set: AioSetEcuSignal = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Event Controller Setting: Connect Analog input signal that data of the specified sampling times have been converted (No delay) to Synchronization bus master signal 3
        '----------------------------------------
        ret = AioSetEcuSignal(g_master_id, AIOECU_DEST_MASTER3, AIOECU_SRC_AI_STOP)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        '--------------------
        ' Exit the process if not completed successfully
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sync Operation Set: AioSetEcuSignal = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Display the message that synchronous operation settings is completed
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "Sync Operation Set: Successful completion"
        '----------------------------------------
        ' [Slave]  Event Controller Setting: Connect Synchronization bus slave signal 1 to Analog input sampling clock
        '----------------------------------------
        ret = AioSetEcuSignal(g_slave_id, AIOECU_DEST_AI_CLK, AIOECU_SRC_SLAVE1)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        '--------------------
        ' Exit the process if not completed successfully
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sync Operation Set: AioSetEcuSignal = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Event Controller Setting: Connect Synchronization bus slave signal 2 to Analog input converting start signal
        '----------------------------------------
        ret = AioSetEcuSignal(g_slave_id, AIOECU_DEST_AI_START, AIOECU_SRC_SLAVE2)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        '--------------------
        ' Exit the process if not completed successfully
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sync Operation Set: AioSetEcuSignal = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Event Controller Setting: Connect Synchronization bus slave signal 3 to Analog input converting stop signal
        '----------------------------------------
        ret = AioSetEcuSignal(g_slave_id, AIOECU_DEST_AI_STOP, AIOECU_SRC_SLAVE3)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        '--------------------
        ' Exit the process if not completed successfully
        '--------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sync Operation Set: AioSetEcuSignal = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Display the message that synchronous operation settings is completed
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "Sync Operation Set: Successful completion"
    End Sub

    '================================================================================
    ' It is the process when the Sampling Start button is clicked
    ' After clearing the memory and status, start sampling
    '================================================================================
    Private Sub Button_SampingStart_Click(sender As Object, e As EventArgs) Handles Button_SampingStart.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim text_string As String                         ' For updating the textbox
        Dim ai_status As Integer                          ' Analog input status
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' [Slave]  Clear memory
        '----------------------------------------
        ret = AioResetAiMemory(g_slave_id)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Start: AioResetAiMemory = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Clear status
        '----------------------------------------
        ret = AioResetAiStatus(g_slave_id)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Start: AioResetAiStatus = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Initialize the total sampling count
        '----------------------------------------
        g_slave_sampling_count = 0
        '----------------------------------------
        ' [Slave]  Start sampling
        '----------------------------------------
        ret = AioStartAi(g_slave_id)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Start: AioStartAi = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Get status
        '----------------------------------------
        ret = AioGetAiStatus(g_slave_id, ai_status)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Start: AioGetAiStatus = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Display status
        '----------------------------------------
        text_string = String.Format("{0:x8}H (", ai_status)
        '--------------------
        ' When status 'Device is running' is ON
        '--------------------
        If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
            text_string += "Operating"
        '--------------------
        ' When status 'Device is running' is OFF
        '--------------------
        Else
            text_string += "Stop"
        End If
        '--------------------
        ' When status 'Wait the start trigger' is ON
        '--------------------
        If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
            text_string += ", Wait the start trigger"
        End If
        '--------------------
        ' When status 'The specified number of data are stored' is ON
        '--------------------
        If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
            text_string += ", The specified number of data are stored"
        End If
        '--------------------
        ' When status 'Overflow' is ON
        '--------------------
        If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
            text_string += ", Overflow"
        End If
        '--------------------
        ' When status 'Sampling clock error' is ON
        '--------------------
        If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
            text_string += ", Sampling clock error"
        End If
        '--------------------
        ' When status 'AD conversion error' is ON
        '--------------------
        If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
            text_string += ", AD conversion error"
        End If
        '--------------------
        ' When status 'Driver spec error' is ON
        '--------------------
        If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
            text_string += ", Driver spec error"
        End If
        text_string += ")"
        TextBox_SlaveAiStatus.Text = text_string
        '----------------------------------------
        ' [Slave]  Update the sampling count
        '----------------------------------------
        TextBox_SlaveAiSamplingCount.Text = "0"
        '----------------------------------------
        ' [Slave]  Clear the listbox for sampling data display
        '----------------------------------------
        ListBox_SlaveAiSamplingData.Items.Clear()
        '----------------------------------------
        ' [Slave]  Display the message that sampling start is completed
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "Sampling Start: Successful completion"
        '----------------------------------------
        ' [Master] Clear memory
        '----------------------------------------
        ret = AioResetAiMemory(g_master_id)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Start: AioResetAiMemory = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Clear status
        '----------------------------------------
        ret = AioResetAiStatus(g_master_id)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Start: AioResetAiStatus = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Initialize the total sampling count
        '----------------------------------------
        g_master_sampling_count = 0
        '----------------------------------------
        ' [Master] Start sampling
        '----------------------------------------
        ret = AioStartAi(g_master_id)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Start: AioStartAi = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Get status
        '----------------------------------------
        ret = AioGetAiStatus(g_master_id, ai_status)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Start: AioGetAiStatus = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Display status
        text_string = String.Format("{0:x8}H (", ai_status)
        '--------------------
        ' When status 'Device is running' is ON
        '--------------------
        If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
            text_string += "Operating"
        '--------------------
        ' When status 'Device is running' is OFF
        '--------------------
        Else
            text_string += "Stop"
        End If
        '--------------------
        ' When status 'Wait the start trigger' is ON
        '--------------------
        If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
            text_string += ", Wait the start trigger"
        End If
        '--------------------
        ' When status 'The specified number of data are stored' is ON
        '--------------------
        If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
            text_string += ", The specified number of data are stored"
        End If
        '--------------------
        ' When status 'Overflow' is ON
        '--------------------
        If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
            text_string += ", Overflow"
        End If
        '--------------------
        ' When status 'Sampling clock error' is ON
        '--------------------
        If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
            text_string += ", Sampling clock error"
        End If
        '--------------------
        ' When status 'AD conversion error' is ON
        '--------------------
        If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
            text_string += ", AD conversion error"
        End If
        '--------------------
        ' When status 'Driver spec error' is ON
        '--------------------
        If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
            text_string += ", Driver spec error"
        End If
        text_string += ")"
        TextBox_MasterAiStatus.Text = text_string
        '----------------------------------------
        ' [Master] Update the sampling count
        '----------------------------------------
        TextBox_MasterAiSamplingCount.Text = "0"
        '----------------------------------------
        ' [Master] Clear the listbox for sampling data display
        '----------------------------------------
        ListBox_MasterAiSamplingData.Items.Clear()
        '----------------------------------------
        ' [Master] Display the message that sampling start is completed
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "Sampling Start: Successful completion"
    End Sub

    '================================================================================
    ' It is the process when the Get Status button is clicked
    ' Get the count and status of sampling and display it on the dialog
    '================================================================================
    Private Sub Button_GetStatus_Click(sender As Object, e As EventArgs) Handles Button_GetStatus.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim text_string As String                         ' For updating the textbox
        Dim ai_sampling_count As Integer                  ' Sampling count
        Dim ai_status As Integer                          ' Sampling status
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' [Slave]  Get the sampling count
        '----------------------------------------
        ret = AioGetAiSamplingCount(g_slave_id, ai_sampling_count)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Get Status: AioGetAiSamplingCount = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Update the sampling count
        '----------------------------------------
        TextBox_SlaveAiSamplingCount.Text = ai_sampling_count.ToString()
        '----------------------------------------
        ' [Slave]  Get status
        '----------------------------------------
        ret = AioGetAiStatus(g_slave_id, ai_status)
        '----------------------------------------
        ' [Slave]  Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Get Status: AioGetAiStatus = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Display status
        '----------------------------------------
        text_string = String.Format("{0:x8}H (", ai_status)
        '--------------------
        ' When status 'Device is running' is ON
        '--------------------
        If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
            text_string += "Operating"
        '--------------------
        ' When status 'Device is running' is OFF
        '--------------------
        Else
            text_string += "Stop"
        End If
        '--------------------
        ' When status 'Wait the start trigger' is ON
        '--------------------
        If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
            text_string += ", Wait the start trigger"
        End If
        '--------------------
        ' When status 'The specified number of data are stored' is ON
        '--------------------
        If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
            text_string += ", The specified number of data are stored"
        End If
        '--------------------
        ' When status 'Overflow' is ON
        '--------------------
        If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
            text_string += ", Overflow"
        End If
        '--------------------
        ' When status 'Sampling clock error' is ON
        '--------------------
        If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
            text_string += ", Sampling clock error"
        End If
        '--------------------
        ' When status 'AD conversion error' is ON
        '--------------------
        If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
            text_string += ", AD conversion error"
        End If
        '--------------------
        ' When status 'Driver spec error' is ON
        '--------------------
        If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
            text_string += ", Driver spec error"
        End If
        text_string += ")"
        TextBox_SlaveAiStatus.Text = text_string
        '----------------------------------------
        ' [Slave]  Display the message that get status is completed
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "Get Status: Successful completion"
        '----------------------------------------
        ' [Master] Get the sampling count
        '----------------------------------------
        ret = AioGetAiSamplingCount(g_master_id, ai_sampling_count)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Get Status: AioGetAiSamplingCount = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Update the sampling count
        '----------------------------------------
        TextBox_MasterAiSamplingCount.Text = ai_sampling_count.ToString()
        '----------------------------------------
        ' [Master] Get status
        '----------------------------------------
        ret = AioGetAiStatus(g_master_id, ai_status)
        '----------------------------------------
        ' [Master] Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Get Status: AioGetAiStatus = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Display status
        '----------------------------------------
        text_string = String.Format("{0:x8}H (", ai_status)
        '--------------------
        ' When status 'Device is running' is ON
        '--------------------
        If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
            text_string += "Operating"
        '--------------------
        ' When status 'Device is running' is OFF
        '--------------------
        Else
            text_string += "Stop"
        End If
        '--------------------
        ' When status 'Wait the start trigger' is ON
        '--------------------
        If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
            text_string += ", Wait the start trigger"
        End If
        '--------------------
        ' When status 'The specified number of data are stored' is ON
        '--------------------
        If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
            text_string += ", The specified number of data are stored"
        End If
        '--------------------
        ' When status 'Overflow' is ON
        '--------------------
        If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
            text_string += ", Overflow"
        End If
        '--------------------
        ' When status 'Sampling clock error' is ON
        '--------------------
        If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
            text_string += ", Sampling clock error"
        End If
        '--------------------
        ' When status 'AD conversion error' is ON
        '--------------------
        If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
            text_string += ", AD conversion error"
        End If
        '--------------------
        ' When status 'Driver spec error' is ON
        '--------------------
        If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
            text_string += ", Driver spec error"
        End If
        text_string += ")"
        TextBox_MasterAiStatus.Text = text_string
        '----------------------------------------
        ' [Master] Display the message that get status is completed
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "Get Status: Successful completion"
    End Sub

    '================================================================================
    ' It is the process when the Sampling Stop button is clicked
    ' Stop sampling
    '================================================================================
    Private Sub Button_SamplingStop_Click(sender As Object, e As EventArgs) Handles Button_SamplingStop.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' [Master] Stop sampling
        '----------------------------------------
        ret = AioStopAi(g_master_id)
        '----------------------------------------
        ' Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Sampling Stop: AioStopAi = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Master] Display the message that sampling stop is completed
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "Sampling Stop: Successful completion"
        '----------------------------------------
        ' [Slave]  Stop sampling
        '----------------------------------------
        ret = AioStopAi(g_slave_id)
        '----------------------------------------
        ' Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Sampling Stop: AioStopAi = " & ret & " : " & error_string.ToString()
            Exit Sub
        End If
        '----------------------------------------
        ' [Slave]  Display the message that sampling stop is completed
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "Sampling Stop: Successful completion"
    End Sub

    '================================================================================
    ' It is the process when the Master Device Output Acquired Data to File button is clicked
    ' Output the globally held sampling data to a CSV file
    '================================================================================
    Private Sub Button_MasterOutputSamplingData_Click(sender As Object, e As EventArgs) Handles Button_MasterOutputSamplingData.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim file_name = "MasterSamplingData.csv"          ' Sampling data output file name
        Dim text_string As String                         ' For updating the textbox
        Dim fp As StreamWriter                            ' File pointer
        Dim i, j As Long                                  ' Loop count
        Dim ret As Integer                                ' For return code
        Dim ai_channels As Short                          ' Number of channels

        '----------------------------------------
        ' Open file
        '----------------------------------------
        Try
            fp = File.CreateText(file_name)
        Catch
            TextBox_MasterReturnCode.Text = "Output Acquired Data to File: File.CreateText = file open error."
            Exit Sub
        End Try
        '----------------------------------------
        ' Get the number of channels
        '----------------------------------------
        ret = AioGetAiChannels(g_master_id, ai_channels)
        '----------------------------------------
        ' Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_MasterReturnCode.Text = "Output Acquired Data to File: AioGetAiChannels = " & ret & " : " & error_string.ToString()
            '----------------------------------------
            ' Close file
            '----------------------------------------
            fp.Close()
            Exit Sub
        End If
        '----------------------------------------
        ' Create sampling data for file output
        '----------------------------------------
        '--------------------
        ' If the total sampling count is 1 or more and pointer to sampling data storage area is not NULL, output the file
        '--------------------
        If ((g_master_sampling_count > 0) And (IsArray(g_master_sampling_data) = True)) Then
            '--------------------
            ' Repeat the process up to the total sampling count
            '--------------------
            For i = 0 To g_master_sampling_count - 1
                text_string = ""
                '--------------------
                ' Generate display string
                '--------------------
                text_string += String.Format("{0,5},", i + 1)
                '--------------------
                ' Repeat the process for the specified number of channels
                '--------------------
                For j = 0 To ai_channels - 1
                    text_string += String.Format(" {0,10:F5}", g_master_sampling_data(i * ai_channels + j))
                    '--------------------
                    ' Add newline character for the last channel
                    '--------------------
                    If (j = ai_channels - 1) Then
                        text_string += vbCrLf
                        '--------------------
                        ' Add comma for channels other than the last channel
                        '--------------------
                    Else
                        text_string += ","
                    End If
                Next j
                '----------------------------------------
                ' Write data
                '----------------------------------------
                Try
                    fp.Write(text_string)
                Catch ex As Exception
                    TextBox_MasterReturnCode.Text = "Output Acquired Data to File: fp.Write = file write error."
                    fp.Close()
                    Exit Sub
                End Try
            Next i
        End If
        '----------------------------------------
        ' Close file
        '----------------------------------------
        fp.Close()
        '----------------------------------------
        ' Display the message that file output is completed
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "Output Acquired Data to File: Save data to " & Chr(34) & file_name & Chr(34) & "."
    End Sub

    '================================================================================
    ' It is the process when the Slave Device Output Acquired Data to File button is clicked
    ' Output the globally held sampling data to a CSV file
    '================================================================================
    Private Sub Button_SlaveOutputSamplingData_Click(sender As Object, e As EventArgs) Handles Button_SlaveOutputSamplingData.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim file_name = "SlaveSamplingData.csv"           ' Sampling data output file name
        Dim text_string As String                         ' For updating the textbox
        Dim fp As StreamWriter                            ' File pointer
        Dim i, j As Long                                  ' Loop count
        Dim ret As Integer                                ' For return code
        Dim ai_channels As Short                          ' Number of channels

        '----------------------------------------
        ' Open file
        '----------------------------------------
        Try
            fp = File.CreateText(file_name)
        Catch
            TextBox_SlaveReturnCode.Text = "Output Acquired Data to File: File.CreateText = file open error."
            Exit Sub
        End Try
        '----------------------------------------
        ' Get the number of channels
        '----------------------------------------
        ret = AioGetAiChannels(g_slave_id, ai_channels)
        '----------------------------------------
        ' Error process
        '----------------------------------------
        If (ret <> 0) Then
            '--------------------
            ' Get error string
            '--------------------
            AioGetErrorString(ret, error_string)
            '--------------------
            ' Display message
            '--------------------
            TextBox_SlaveReturnCode.Text = "Output Acquired Data to File: AioGetAiChannels = " & ret & " : " & error_string.ToString()
            '----------------------------------------
            ' Close file
            '----------------------------------------
            fp.Close()
            Exit Sub
        End If
        '----------------------------------------
        ' Create sampling data for file output
        '----------------------------------------
        '--------------------
        ' If the total sampling count is 1 or more and pointer to sampling data storage area is not NULL, output the file
        '--------------------
        If ((g_slave_sampling_count > 0) And (IsArray(g_slave_sampling_data) = True)) Then
            '--------------------
            ' Repeat the process up to the total sampling count
            '--------------------
            For i = 0 To g_slave_sampling_count - 1
                text_string = ""
                '--------------------
                ' Generate display string
                '--------------------
                text_string += String.Format("{0,5},", i + 1)
                '--------------------
                ' Repeat the process for the specified number of channels
                '--------------------
                For j = 0 To ai_channels - 1
                    text_string += String.Format(" {0,10:F5}", g_slave_sampling_data(i * ai_channels + j))
                    '--------------------
                    ' Add newline character for the last channel
                    '--------------------
                    If (j = ai_channels - 1) Then
                        text_string += vbCrLf
                        '--------------------
                        ' Add comma for channels other than the last channel
                        '--------------------
                    Else
                        text_string += ","
                    End If
                Next j
                '----------------------------------------
                ' Write data
                '----------------------------------------
                Try
                    fp.Write(text_string)
                Catch ex As Exception
                    TextBox_SlaveReturnCode.Text = "Output Acquired Data to File: fp.Write = file write error."
                    fp.Close()
                    Exit Sub
                End Try
            Next i
        End If
        '----------------------------------------
        ' Close file
        '----------------------------------------
        fp.Close()
        '----------------------------------------
        ' Display the message that file output is completed
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "Output Acquired Data to File: Save data to " & Chr(34) & file_name & Chr(34) & "."
    End Sub

    '================================================================================
    ' It is the process when the AioExit button is clicked
    ' Perform the exit process of device
    '================================================================================
    Private Sub Button_AioExit_Click(sender As Object, e As EventArgs) Handles Button_AioExit.Click
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' [Master] Release the array for storing AD conversion data
        '----------------------------------------
        If IsArray(g_master_sampling_data) = True Then
            '----------------------------------------
            ' GCHandle free
            '----------------------------------------
            If (gCh_master_sampling_data.IsAllocated = True) Then
                 gCh_master_sampling_data.Free()
            End If
            Erase g_master_sampling_data
        End If
        '----------------------------------------
        ' [Master] Exit process
        '----------------------------------------
        ret = AioExit(g_master_id)
        '----------------------------------------
        ' [Master] Get error string
        '----------------------------------------
        AioGetErrorString(ret, error_string)
        '----------------------------------------
        ' [Master] Display message
        '----------------------------------------
        TextBox_MasterReturnCode.Text = "AioExit = " & ret & " : " & error_string.ToString()
        '----------------------------------------
        ' [Slave] Release the array for storing AD conversion data
        '----------------------------------------
        If IsArray(g_slave_sampling_data) = True Then
            '----------------------------------------
            ' GCHandle free
            '----------------------------------------
            If (gCh_slave_sampling_data.IsAllocated = True) Then
                 gCh_slave_sampling_data.Free()
            End If
            Erase g_slave_sampling_data
        End If
        '----------------------------------------
        ' [Slave]  Exit process
        '----------------------------------------
        ret = AioExit(g_slave_id)
        '----------------------------------------
        ' [Slave]  Get error string
        '----------------------------------------
        AioGetErrorString(ret, error_string)
        '----------------------------------------
        ' [Slave]  Display message
        '----------------------------------------
        TextBox_SlaveReturnCode.Text = "AioExit = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' It is the process when the Close button is clicked
    ' Perform the exit process of device and terminate the application
    '================================================================================
    Private Sub Button_Close_Click(sender As Object, e As EventArgs) Handles Button_Close.Click
        '----------------------------------------
        ' Release the array for storing AD conversion data
        '----------------------------------------
        If IsArray(g_master_sampling_data) = True Then
            '----------------------------------------
            ' GCHandle free
            '----------------------------------------
            If (gCh_master_sampling_data.IsAllocated = True) Then
                 gCh_master_sampling_data.Free()
            End If
            Erase g_master_sampling_data
        End If
        If IsArray(g_slave_sampling_data) = True Then
            '----------------------------------------
            ' GCHandle free
            '----------------------------------------
            If (gCh_slave_sampling_data.IsAllocated = True) Then
                 gCh_slave_sampling_data.Free()
            End If
            Erase g_slave_sampling_data
        End If
        '----------------------------------------
        ' Exit process
        '----------------------------------------
        AioExit(g_slave_id)
        AioExit(g_master_id)
        '----------------------------------------
        ' Close dialog
        '----------------------------------------
        Me.Close()
    End Sub

    '================================================================================
    ' Operation when event occurred
    ' Process for each event occurred
    '================================================================================
    Protected Overrides Sub WndProc(ByRef m As Message)
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim text_string As String                         ' For updating the textbox
        Dim ai_sampling_count As Integer                  ' Sampling count
        Dim ai_status As Integer                          ' Sampling status
        Dim ret As Integer                                ' For return code
        Dim i, j As Long                                  ' Loop count
        Dim loop_max_count As Long                        ' Maximum loop count
        Dim top_address As Long                           ' Top address of buffer for sampling data display
        Dim ai_channels As Short                          ' Number of channels
        Dim id As Short                                   ' ID for device access

        '----------------------------------------
        ' Get ID for device access
        '----------------------------------------
        Short.TryParse((m.WParam.ToInt64 And &HFFFF).ToString(), id)
        '----------------------------------------
        ' Event that AD conversion start
        ' Display the status
        '----------------------------------------
        If (m.Msg = AIOM_AIE_START) Then
            '----------------------------------------
            ' Slave ID
            '----------------------------------------
            If (id = g_slave_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_slave_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "Event that AD conversion start Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                    '--------------------
                    ' When status 'Device is running' is OFF
                    '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_SlaveAiStatus.Text = text_string
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_SlaveReturnCode.Text = "Event that AD conversion start Process: Successful completion"
            End If
        End If
        '----------------------------------------
        ' Event that device operation end
        ' Acquire and display data
        '----------------------------------------
        If (m.Msg = AIOM_AIE_END) Then
            '----------------------------------------
            ' Master ID
            '----------------------------------------
            If (id = g_master_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_master_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_MasterReturnCode.Text = "Device Operation End Event Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_MasterAiStatus.Text = text_string
                '----------------------------------------
                ' Get the current sampling count
                '----------------------------------------
                ret = AioGetAiSamplingCount(g_master_id, ai_sampling_count)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_MasterReturnCode.Text = "Device Operation End Event Process: AioGetAiSamplingCount = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display sampling count
                '----------------------------------------
                TextBox_MasterAiSamplingCount.Text = ai_sampling_count.ToString()
                '----------------------------------------
                ' Get the number of channels
                '----------------------------------------
                ret = AioGetAiChannels(g_master_id, ai_channels)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_MasterReturnCode.Text = "Device Operation End Event Process: AioGetAiChannels = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Get sampling data process
                '----------------------------------------
                '--------------------
                ' Allocate an array for storing data
                '--------------------
                If IsArray(g_master_sampling_data) = True Then
                    '----------------------------------------
                    ' GCHandle free
                    '----------------------------------------
                    If (gCh_master_sampling_data.IsAllocated = True) Then
                         gCh_master_sampling_data.Free()
                    End If
                    Erase g_master_sampling_data
                End If
                Try
                    ReDim g_master_sampling_data(ai_sampling_count * ai_channels - 1)
                Catch ex As Exception
                    TextBox_MasterReturnCode.Text = "Device Operation End Event Process: Failed to allocate an array for storing data"
                    Exit Sub
                End Try
                '----------------------------------------
                ' Specify Pinned handle to g_master_sampling_data
                '----------------------------------------
                If (gCh_master_sampling_data.IsAllocated = False) Then
                    gCh_master_sampling_data = GCHandle.Alloc(g_master_sampling_data, GCHandleType.Pinned)
                End If
                '----------------------------------------
                ' Get sampling data
                '----------------------------------------
                ret = AioGetAiSamplingDataEx(g_master_id, ai_sampling_count, g_master_sampling_data)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_MasterReturnCode.Text = "Device Operation End Event Process: AioGetAiSamplingDataEx = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Update the total sampling count
                '----------------------------------------
                g_master_sampling_count = ai_sampling_count
                '----------------------------------------
                ' Set the loop count for the sampling data display loop
                '----------------------------------------
                '--------------------
                ' When the sampling count of the data acquired this time exceeds the maximum sampling number of data display
                '--------------------
                If (ai_sampling_count > DISPLAY_SAMPLING_COUNT) Then
                    '--------------------
                    ' Limit the maximum number of loops to the data display maximum sampling count
                    '--------------------
                    loop_max_count = DISPLAY_SAMPLING_COUNT
                    '--------------------
                    ' Set the top address of the buffer to be referenced to the address 
                    ' before the maximum sampling count for data display from the end of the sampling data storage buffer
                    '--------------------
                    top_address = ai_sampling_count - DISPLAY_SAMPLING_COUNT
                '--------------------
                ' When the sampling count of the data acquired this time is less than or equal to the maximum sampling number of data display
                '--------------------
                Else
                    '--------------------
                    ' Set the number of total sampling data to the maximum loop number
                    '--------------------
                    loop_max_count = ai_sampling_count
                    '--------------------
                    ' Set the top address of the referenced buffer to 0
                    '--------------------
                    top_address = 0
                End If
                '----------------------------------------
                ' Display sampling data
                ' (Display from the end of acquired data to the maximum number of data display sampling count)
                '----------------------------------------
                '--------------------
                ' When the sampling count of the data acquired this time is 1 or more
                '--------------------
                If (ai_sampling_count > 0) Then
                    '--------------------
                    ' Clear the listbox for sampling data display
                    '--------------------
                    ListBox_MasterAiSamplingData.Items.Clear()
                    '--------------------
                    ' Repeat the process up to the maximum sampling count of the display data
                    '--------------------
                    For i = top_address To loop_max_count + top_address - 1
                        '--------------------
                        ' Clear display string storage variable
                        '--------------------
                        text_string = ""
                        '--------------------
                        ' Generate display string
                        '--------------------
                        text_string += String.Format("{0,5},  ", i + 1)
                        '--------------------
                        ' Repeat the process for the specified number of channels
                        '--------------------
                        For j = 0 To ai_channels - 1
                            text_string += String.Format(" {0, 10:F5}", g_master_sampling_data(i * ai_channels + j))
                        Next j
                        '----------------------------------------
                        ' Display sampling start data
                        '----------------------------------------
                        ListBox_MasterAiSamplingData.Items.Add(text_string)
                    Next i
                End If
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_MasterReturnCode.Text = "Device Operation End Event Process: Successful completion"
            '----------------------------------------
            ' Slave ID
            '----------------------------------------
            ElseIf (id = g_slave_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_slave_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "Device Operation End Event Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_SlaveAiStatus.Text = text_string
                '----------------------------------------
                ' Get the current sampling count
                '----------------------------------------
                ret = AioGetAiSamplingCount(g_slave_id, ai_sampling_count)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "Device Operation End Event Process: AioGetAiSamplingCount = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display sampling count
                '----------------------------------------
                TextBox_SlaveAiSamplingCount.Text = ai_sampling_count.ToString()
                '----------------------------------------
                ' Get the number of channels
                '----------------------------------------
                ret = AioGetAiChannels(g_slave_id, ai_channels)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "Device Operation End Event Process: AioGetAiChannels = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Get sampling data process
                '----------------------------------------
                '--------------------
                ' Allocate an array for storing data
                '--------------------
                If IsArray(g_slave_sampling_data) = True Then
                    '----------------------------------------
                    ' GCHandle free
                    '----------------------------------------
                    If (gCh_slave_sampling_data.IsAllocated = True) Then
                         gCh_slave_sampling_data.Free()
                    End If
                    Erase g_slave_sampling_data
                End If
                Try
                    ReDim g_slave_sampling_data(ai_sampling_count * ai_channels - 1)
                Catch ex As Exception
                    TextBox_SlaveReturnCode.Text = "Device Operation End Event Process: Failed to allocate an array for storing data"
                    Exit Sub
                End Try
                '----------------------------------------
                ' Specify Pinned handle to g_slave_sampling_data
                '----------------------------------------
                If (gCh_slave_sampling_data.IsAllocated = False) Then
                    gCh_slave_sampling_data = GCHandle.Alloc(g_slave_sampling_data, GCHandleType.Pinned)
                End If
                '----------------------------------------
                ' Get sampling data
                '----------------------------------------
                ret = AioGetAiSamplingDataEx(g_slave_id, ai_sampling_count, g_slave_sampling_data)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "Device Operation End Event Process: AioGetAiSamplingDataEx = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Update the total sampling count
                '----------------------------------------
                g_slave_sampling_count = ai_sampling_count
                '----------------------------------------
                ' Set the loop count for the sampling data display loop
                '----------------------------------------
                '--------------------
                ' When the sampling count of the data acquired this time exceeds the maximum sampling number of data display
                '--------------------
                If ai_sampling_count > DISPLAY_SAMPLING_COUNT Then
                    '--------------------
                    ' Limit the maximum number of loops to the data display maximum sampling count
                    '--------------------
                    loop_max_count = DISPLAY_SAMPLING_COUNT
                    '--------------------
                    ' Set the top address of the buffer to be referenced to the address 
                    ' before the maximum sampling count for data display from the end of the sampling data storage buffer
                    '--------------------
                    top_address = ai_sampling_count - DISPLAY_SAMPLING_COUNT
                '--------------------
                ' When the sampling count of the data acquired this time is less than or equal to the maximum sampling number of data display
                '--------------------
                Else
                    '--------------------
                    ' Set the number of total sampling data to the maximum loop number
                    '--------------------
                    loop_max_count = ai_sampling_count
                    '--------------------
                    ' Set the top address of the referenced buffer to 0
                    '--------------------
                    top_address = 0
                End If
                '----------------------------------------
                ' Display sampling data
                ' (Display from the end of acquired data to the maximum number of data display sampling count)
                '----------------------------------------
                '--------------------
                ' When the sampling count of the data acquired this time is 1 or more
                '--------------------
                If (ai_sampling_count > 0) Then
                    '--------------------
                    ' Clear the listbox for sampling data display
                    '--------------------
                    ListBox_SlaveAiSamplingData.Items.Clear()
                    '--------------------
                    ' Repeat the process up to the maximum sampling count of the display data
                    '--------------------
                    For i = top_address To loop_max_count + top_address - 1
                        '--------------------
                        ' Clear display string storage variable
                        '--------------------
                        text_string = ""
                        '--------------------
                        ' Generate display string
                        '--------------------
                        text_string += String.Format("{0,5},  ", i + 1)
                        '--------------------
                        ' Repeat the process for the specified number of channels
                        '--------------------
                        For j = 0 To ai_channels - 1
                            text_string += String.Format(" {0, 10:F5}", g_slave_sampling_data(i * ai_channels + j))
                        Next j
                        '----------------------------------------
                        ' Display sampling start data
                        '----------------------------------------
                        ListBox_SlaveAiSamplingData.Items.Add(text_string)
                    Next i
                End If
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_SlaveReturnCode.Text = "Device Operation End Event Process: Successful completion"
            End If
        End If
        '----------------------------------------
        ' Event that overflow
        ' Display the status
        '----------------------------------------
        If (m.Msg = AIOM_AIE_OFERR) Then
            '----------------------------------------
            ' Master ID
            '----------------------------------------
            If (id = g_master_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_master_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_MasterReturnCode.Text = "Overflow Occurrence Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_MasterAiStatus.Text = text_string
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_MasterReturnCode.Text = "Overflow Occurrence Process: Successful completion"
            '----------------------------------------
            ' Slave ID
            '----------------------------------------
            ElseIf (id = g_slave_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_slave_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "Overflow Occurrence Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_SlaveAiStatus.Text = text_string
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_SlaveReturnCode.Text = "Overflow Occurrence Process: Successful completion"
            End If
        End If
        '----------------------------------------
        ' Event that sampling clock error
        ' Display the status
        '----------------------------------------
        If (m.Msg = AIOM_AIE_SCERR) Then
            '----------------------------------------
            ' Master ID
            '----------------------------------------
            If (id = g_master_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_master_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_MasterReturnCode.Text = "Sampling Clock Error Occurrence Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_MasterAiStatus.Text = text_string
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_MasterReturnCode.Text = "Sampling Clock Error Occurrence Process: Successful completion"
            '----------------------------------------
            ' Slave ID
            '----------------------------------------
            ElseIf (id = g_slave_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_slave_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "Sampling Clock Error Occurrence Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_SlaveAiStatus.Text = text_string
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_SlaveReturnCode.Text = "Sampling Clock Error Occurrence Process: Successful completion"
            End If
        End If
        '----------------------------------------
        ' Event that AD conversion error
        ' Display the status
        '----------------------------------------
        If (m.Msg = AIOM_AIE_ADERR) Then
            '----------------------------------------
            ' Master ID
            '----------------------------------------
            If (id = g_master_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_master_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_MasterReturnCode.Text = "AD Conversion Error Occurrence Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_MasterAiStatus.Text = text_string
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_MasterReturnCode.Text = "AD Conversion Error Occurrence Process: Successful completion"
            '----------------------------------------
            ' Slave ID
            '----------------------------------------
            ElseIf (id = g_slave_id) Then
                '----------------------------------------
                ' Get status
                '----------------------------------------
                ret = AioGetAiStatus(g_slave_id, ai_status)
                '----------------------------------------
                ' Error process
                '----------------------------------------
                If (ret <> 0) Then
                    '--------------------
                    ' Get error string
                    '--------------------
                    AioGetErrorString(ret, error_string)
                    '--------------------
                    ' Display message
                    '--------------------
                    TextBox_SlaveReturnCode.Text = "AD Conversion Error Occurrence Process: AioGetAiStatus = " & ret & " : " & error_string.ToString()
                    Exit Sub
                End If
                '----------------------------------------
                ' Display status
                '----------------------------------------
                text_string = String.Format("{0:x8}H (", ai_status)
                '--------------------
                ' When status 'Device is running' is ON
                '--------------------
                If ((ai_status And AIS_BUSY) = AIS_BUSY) Then
                    text_string += "Operating"
                '--------------------
                ' When status 'Device is running' is OFF
                '--------------------
                Else
                    text_string += "Stop"
                End If
                '--------------------
                ' When status 'Wait the start trigger' is ON
                '--------------------
                If ((ai_status And AIS_START_TRG) = AIS_START_TRG) Then
                    text_string += ", Wait the start trigger"
                End If
                '--------------------
                ' When status 'The specified number of data are stored' is ON
                '--------------------
                If ((ai_status And AIS_DATA_NUM) = AIS_DATA_NUM) Then
                    text_string += ", The specified number of data are stored"
                End If
                '--------------------
                ' When status 'Overflow' is ON
                '--------------------
                If ((ai_status And AIS_OFERR) = AIS_OFERR) Then
                    text_string += ", Overflow"
                End If
                '--------------------
                ' When status 'Sampling clock error' is ON
                '--------------------
                If ((ai_status And AIS_SCERR) = AIS_SCERR) Then
                    text_string += ", Sampling clock error"
                End If
                '--------------------
                ' When status 'AD conversion error' is ON
                '--------------------
                If ((ai_status And AIS_AIERR) = AIS_AIERR) Then
                    text_string += ", AD conversion error"
                End If
                '--------------------
                ' When status 'Driver spec error' is ON
                '--------------------
                If ((ai_status And AIS_DRVERR) = AIS_DRVERR) Then
                    text_string += ", Driver spec error"
                End If
                text_string += ")"
                TextBox_SlaveAiStatus.Text = text_string
                '----------------------------------------
                ' Display the message that event processing is completed
                '----------------------------------------
                TextBox_SlaveReturnCode.Text = "AD Conversion Error Occurrence Process: Successful completion"
            End If
        End If
        MyBase.WndProc(m)
    End Sub
End Class
