﻿#================================================================
#================================================================
# API-AIO(WDM)
# Device internal synchronization (Generating/Sampling) sample
# main file
#                                                 CONTEC Co.,Ltd.
#================================================================
#================================================================
#----------------------------------------
# Import modules
#----------------------------------------
import math
import ctypes
import caio
from InternalSyncGeneratingSamplingUI import InternalSyncGeneratingSamplingUI


#========================================
# InternalSyncGeneratingSampling class
#========================================
class InternalSyncGeneratingSampling:
    #========================================
    # Initialization function
    #========================================
    def __init__(self):
        #----------------------------------------
        # Variable
        #----------------------------------------
        self.DISPLAY_SAMPLING_COUNT = 1000       # Maximum sampling count of sampling data displayed in listbox
        self.id = ctypes.c_short()               # ID for device access
        self.file_name = 'GeneratingData.csv'    # Generating data output file name
        self.generating_count = 0                # Total generating count
        self.generating_data = None              # Output data
        self.ao_range = (  caio.PM10,            # +/-10V
                           caio.PM5,             # +/-5V
                           caio.PM25,            # +/-2.5V
                           caio.PM125,           # +/-1.25V
                           caio.P10,             # 0-10V
                           caio.P5,              # 0-5V
                           caio.P25,             # 0-2.5V
                           caio.P125,            # 0-1.25V
                           caio.P20MA,           # 0-20mA
                           caio.P4TO20MA,        # 4-20mA
                           caio.P1TO5)           # 1-5V
        self.sampling_count = 0                  # Total sampling count
        self.sampling_data = None                # Pointer to sampling data storage area
        self.ai_range = (  caio.PM10,            # +/-10V
                           caio.PM5,             # +/-5V
                           caio.PM25,            # +/-2.5V
                           caio.PM125,           # +/-1.25V
                           caio.P10,             # 0-10V
                           caio.P5,              # 0-5V
                           caio.P25,             # 0-2.5V
                           caio.P125,            # 0-1.25V
                           caio.P20MA,           # 0-20mA
                           caio.P4TO20MA,        # 4-20mA
                           caio.PM20MA,          # +/-20mA
                           caio.P1TO5)           # 1-5V
        self.pao_callback = None                 # Pointer to generating callback function
        self.pao_user_data = None                # User data of generating callback function
        self.pai_callback = None                 # Pointer to sampling callback function
        self.pai_user_data = None                # User data of sampling callback function
        #----------------------------------------
        # Start creating the UI
        #----------------------------------------
        self.ui = InternalSyncGeneratingSamplingUI()
        #----------------------------------------
        # Set the callback function for the UI controls
        #----------------------------------------
        self.ui.setup_commands(
            command_aio_init=self.OnClickedButtonAioInit,
            command_aio_reset_device=self.OnClickedButtonAioResetDevice,
            command_ai_ao_setting=self.OnClickedButtonAiAoSetting,
            command_generating_sampling_setting=self.OnClickedButtonGeneratingSamplingSetting,
            command_sync_setting=self.OnClickedButtonSyncSetting,
            command_output_data_setting=self.OnClickedButtonOutputDataSetting,
            command_generating_sampling_start=self.OnClickedButtonGeneratingSamplingStart,
            command_get_status=self.OnClickedButtonGetStatus,
            command_generating_sampling_stop=self.OnClickedButtonGeneratingSamplingStop,
            command_output_sampling_data=self.OnClickedButtonOutputSamplingData,
            command_aio_exit=self.OnClickedButtonAioExit,
            command_close=self.OnClickedButtonClose
        )

    #========================================
    # Function name    isnum
    # Parameter        str     String
    # Parameter        base    Base
    # Details          Function to checks if a string can be converted to a number
    # Return value     True: Can be converted
    #                  False: Can not be converted
    #========================================
    @staticmethod
    def isnum(str, base):
        try:
            if 10 == base:
                int(str, 10)
            elif 16 == base:
                int(str, 16)
            else:
                float(str)
        except:
            return False
        return True

    #========================================
    # Function name    GetSineCoefficient
    # Parameter        ao_range        Range
    # Details          Function to get sine waveform coefficient
    # Return value     gain, offset    Sine waveform gain, offset
    #========================================
    @staticmethod
    def GetSineCoefficient(ao_range):
        if ao_range.value == caio.PM10:
            gain = 10
            offset = 0
        elif ao_range.value == caio.PM5:
            gain = 5
            offset = 0
        elif ao_range.value == caio.PM25:
            gain = 2.5
            offset = 0
        elif ao_range.value == caio.PM125:
            gain = 1.25
            offset = 0
        elif ao_range.value == caio.P10:
            gain = 5
            offset = 5
        elif ao_range.value == caio.P5:
            gain = 2.5
            offset = 2.5
        elif ao_range.value == caio.P25:
            gain = 1.25
            offset = 1.25
        elif ao_range.value == caio.P125:
            gain = 0.625
            offset = 0.625
        elif ao_range.value == caio.P20MA:
            gain = 10
            offset = 10
        elif ao_range.value == caio.P4TO20MA:
            gain = 8
            offset = 12
        elif ao_range.value == caio.P1TO5:
            gain = 2
            offset = 3
        else:
            gain = 10
            offset = 0
        return gain, offset

    #========================================
    # Function name     GetAoStatusString
    # Parameter         ao_status           Status
    # Details           Function to get status string
    # Return value      ao_status_string    Status string
    #========================================
    @staticmethod
    def GetAoStatusString(ao_status):
        #----------------------------------------
        # Create the analog output status string
        #----------------------------------------
        #--------------------
        # When status 'Device is running' is ON
        #--------------------
        if (ao_status.value & caio.AOS_BUSY) == caio.AOS_BUSY:
            ao_status_string = "Operating"
        #--------------------
        # When status 'Device is running' is OFF
        #--------------------
        else:
            ao_status_string = "Stop"
        #--------------------
        # When status 'Wait the start trigger' is ON
        #--------------------
        if (ao_status.value & caio.AOS_START_TRG) == caio.AOS_START_TRG:
            ao_status_string += ", Wait the start trigger"
        #--------------------
        # When status 'The specified number of data are output' is ON
        #--------------------
        if (ao_status.value & caio.AOS_DATA_NUM) == caio.AOS_DATA_NUM:
            ao_status_string += ", The specified number of data are output"
        #--------------------
        # When status 'Sampling clock error' is ON
        #--------------------
        if (ao_status.value & caio.AOS_SCERR) == caio.AOS_SCERR:
            ao_status_string += ", Sampling clock error"
        #--------------------
        # When status 'DA conversion error' is ON
        #--------------------
        if (ao_status.value & caio.AOS_AOERR) == caio.AOS_AOERR:
            ao_status_string += ", DA conversion error"
        #--------------------
        # When status 'Driver spec error' is ON
        #--------------------
        if (ao_status.value & caio.AOS_DRVERR) == caio.AOS_DRVERR:
            ao_status_string += ", Driver spec error"
        return ao_status_string

    #========================================
    # Function name     GetAiStatusString
    # Parameter         ai_status           Status
    # Details           Function to get status string
    # Return value      ai_status_string    Status string
    #========================================
    @staticmethod
    def GetAiStatusString(ai_status):
        #----------------------------------------
        # Create the analog input status string
        #----------------------------------------
        #--------------------
        # When status 'Device is running' is ON
        #--------------------
        if (ai_status.value & caio.AIS_BUSY) == caio.AIS_BUSY:
            ai_status_string = "Operating"
        #--------------------
        # When status 'Device is running' is OFF
        #--------------------
        else:
            ai_status_string = "Stop"
        #--------------------
        # When status 'Wait the start trigger' is ON
        #--------------------
        if (ai_status.value & caio.AIS_START_TRG) == caio.AIS_START_TRG:
            ai_status_string += ", Wait the start trigger"
        #--------------------
        # When status 'The specified number of data are stored' is ON
        #--------------------
        if (ai_status.value & caio.AIS_DATA_NUM) == caio.AIS_DATA_NUM:
            ai_status_string += ", The specified number of data are stored"
        #--------------------
        # When status 'Overflow' is ON
        #--------------------
        if (ai_status.value & caio.AIS_OFERR) == caio.AIS_OFERR:
            ai_status_string += ", Overflow"
        #--------------------
        # When status 'Sampling clock error' is ON
        #--------------------
        if (ai_status.value & caio.AIS_SCERR) == caio.AIS_SCERR:
            ai_status_string += ", Sampling clock error"
        #--------------------
        # When status 'AD conversion error' is ON
        #--------------------
        if (ai_status.value & caio.AIS_AIERR) == caio.AIS_AIERR:
            ai_status_string += ", AD conversion error"
        #--------------------
        # When status 'Driver spec error' is ON
        #--------------------
        if (ai_status.value & caio.AIS_DRVERR) == caio.AIS_DRVERR:
            ai_status_string += ", Driver spec error"
        return ai_status_string

    #========================================
    # Function name    GeneratingMasterCallBackProc
    # Parameter        id          Id get by AioInit
    # Parameter        ao_event    The event that occurred
    # Parameter        wParam      Parameter passed from driver
    # Parameter        lParam      Parameter unique to each event
    # Parameter        Param       Parameter specified in the AioSetAoCallBackProc function
    # Details          Function registered with the AioSetAoCallBackProc function
    #                  This function is called when an event occurs
    # Return value     None
    #========================================
    @staticmethod
    def GeneratingMasterCallBackProc(id, ao_event, wParam, lParam, Param):
        ao_status = ctypes.c_long()                        # Generating Status
        ao_generating_count = ctypes.c_long()              # Generating count
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Create class object
        #----------------------------------------
        obj_ptr = ctypes.cast(Param, ctypes.POINTER(ctypes.py_object))
        self = obj_ptr.contents.value
        #----------------------------------------
        # [Generating]
        # Event that device operation end
        # Acquire and display data
        #----------------------------------------
        if ao_event == caio.AIOM_AOE_END:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAoStatus(self.id, ctypes.byref(ao_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Device Operation End Event Process : AioGetAoStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ao_status_string = self.GetAoStatusString(ao_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ao_status_var.set(f"{ao_status.value:08x}H ({ao_status_string})")
            #----------------------------------------
            # Get the current generating count
            #----------------------------------------
            lret.value = caio.AioGetAoSamplingCount(self.id, ctypes.byref(ao_generating_count))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Device Operation End Event Process : AioGetAoSamplingCount = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Display generating count
            #----------------------------------------
            text_buf = f"{ao_generating_count.value}"
            self.ui.textbox_ao_generating_count_var.set(text_buf)
            #----------------------------------------
            # Update the total generating count
            #----------------------------------------
            self.generating_count = ao_generating_count.value
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Device Operation End Event Process : Successful completion")
        #----------------------------------------
        # [Generating]
        # Event that sampling clock error
        # Display the status
        #----------------------------------------
        if ao_event == caio.AIOM_AOE_SCERR:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAoStatus(self.id, ctypes.byref(ao_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Sampling Clock Error Occurrence Process : AioGetAoStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ao_status_string = self.GetAoStatusString(ao_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ao_status_var.set(f"{ao_status.value:08x}H ({ao_status_string})")
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Sampling Clock Error Occurrence Process : Successful completion")
        #----------------------------------------
        # [Generating]
        # Event that DA conversion error
        # Display the status
        #----------------------------------------
        if ao_event == caio.AIOM_AOE_DAERR:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAoStatus(self.id, ctypes.byref(ao_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"DA Conversion Error Occurrence Process : AioGetAoStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ao_status_string = self.GetAoStatusString(ao_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ao_status_var.set(f"{ao_status.value:08x}H ({ao_status_string})")
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("DA Conversion Error Occurrence Process : Successful completion")

    #========================================
    # Function name    SamplingSlaveCallBackProc
    # Parameter        id          Id get by AioInit
    # Parameter        ai_event    The event that occurred
    # Parameter        wParam      Parameter passed from driver
    # Parameter        lParam      Parameter unique to each event
    # Parameter        Param       Parameter specified in the AioSetAiCallBackProc function
    # Details          Function registered with the AioSetAiCallBackProc function
    #                  This function is called when an event occurs
    # Return value     None
    #========================================
    @staticmethod
    def SamplingSlaveCallBackProc(id, ai_event, wParam, lParam, Param):
        ai_status = ctypes.c_long()                        # Sampling Status
        ai_sampling_count = ctypes.c_long()                # Sampling count
        ai_channels = ctypes.c_short()                     # Number of channels
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Create class object
        #----------------------------------------
        obj_ptr = ctypes.cast(Param, ctypes.POINTER(ctypes.py_object))
        self = obj_ptr.contents.value
        #----------------------------------------
        # [Sampling]
        # Event that AD conversion start
        # Display the status
        #----------------------------------------
        if ai_event == caio.AIOM_AIE_START:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Event that AD conversion start Process : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ai_status_string = self.GetAiStatusString(ai_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Event that AD conversion start Process : Successful completion")
        #----------------------------------------
        # [Sampling]
        # Event that device operation end
        # Acquire and display data
        #----------------------------------------
        if ai_event == caio.AIOM_AIE_END:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Device Operation End Event Process : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ai_status_string = self.GetAiStatusString(ai_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
            #----------------------------------------
            # Get the current sampling count
            #----------------------------------------
            lret.value = caio.AioGetAiSamplingCount(self.id, ctypes.byref(ai_sampling_count))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Device Operation End Event Process : AioGetAiSamplingCount = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Display sampling count
            #----------------------------------------
            text_buf = f"{ai_sampling_count.value}"
            self.ui.textbox_ai_sampling_count_var.set(text_buf)
            #----------------------------------------
            # Get the number of channels
             #----------------------------------------
            lret.value = caio.AioGetAiChannels(self.id, ctypes.byref(ai_channels))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Device Operation End Event Process : AioGetAiChannels = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Allocate an array for storing data
            #----------------------------------------
            if self.sampling_data is not None:
                self.sampling_data = None
            try:
                self.sampling_data = (ctypes.c_float * (ai_sampling_count.value * ai_channels.value))()
            except:
                self.ui.textbox_return_string_var.set("Device Operation End Event Process : Failed to allocate an array for storing data")
                return
            #----------------------------------------
            # Get sampling data
            #----------------------------------------
            lret.value = caio.AioGetAiSamplingDataEx(self.id, ctypes.byref(ai_sampling_count), self.sampling_data)
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Device Operation End Event Process : AioGetAiSamplingDataEx = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Update the total sampling count
            #----------------------------------------
            self.sampling_count = ai_sampling_count.value
            #----------------------------------------
            # 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.value > self.DISPLAY_SAMPLING_COUNT:
                #--------------------
                # Limit the maximum number of loops to the data display maximum sampling count
                #--------------------
                loop_max_count = self.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 acquired data
                #--------------------
                top_address = ai_sampling_count.value - self.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.value
                #--------------------
                # Set the top address of the referenced buffer to 0
                #--------------------
                top_address = 0
            #----------------------------------------
            # 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.value > 0:
                #--------------------
                # Clear the listbox for sampling data display
                #--------------------
                self.ui.listbox_ai_sampling_data_var.set([""])
                data = []
                #--------------------
                # Repeat the process up to the maximum sampling count of the display data
                #--------------------
                for i in range(top_address, loop_max_count + top_address):
                    #--------------------
                    # Generate display string
                    #--------------------
                    text_string = f"{(i + 1):5d}:  "
                    #--------------------
                    # Repeat the process for the specified number of channels
                    #--------------------
                    for j in range(ai_channels.value):
                        text_string += f" {self.sampling_data[i * ai_channels.value + j]:10.5f}"
                    #----------------------------------------
                    # Collect sampling data
                    #----------------------------------------
                    data.append(text_string)
                #----------------------------------------
                # Display sampling start data
                #----------------------------------------
                self.ui.listbox_ai_sampling_data_var.set(data)
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Device Operation End Event Process : Successful completion")
        #----------------------------------------
        # [Sampling]
        # Event that overflow
        # Display the status
        #----------------------------------------
        if ai_event == caio.AIOM_AIE_OFERR:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Overflow Occurrence Process : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ai_status_string = self.GetAiStatusString(ai_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Overflow Occurrence Process : Successful completion")
        #----------------------------------------
        # [Sampling]
        # Event that sampling clock error
        # Display the status
        #----------------------------------------
        if ai_event == caio.AIOM_AIE_SCERR:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Sampling Clock Error Occurrence Process : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ai_status_string = self.GetAiStatusString(ai_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Sampling Clock Error Occurrence Process : Successful completion")
        #----------------------------------------
        # [Sampling]
        # Event that AD conversion error
        # Display the status
        #----------------------------------------
        if ai_event == caio.AIOM_AIE_ADERR:
            #----------------------------------------
            # Get status
            #----------------------------------------
            lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"AD Conversion Error Occurrence Process : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Create the status string
            #----------------------------------------
            ai_status_string = self.GetAiStatusString(ai_status)
            #----------------------------------------
            # Display the status
            #----------------------------------------
            self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
            #----------------------------------------
            # Display the message that event processing is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("AD Conversion Error Occurrence Process : Successful completion")

    #========================================
    # Function name    OnClickedButtonAioInit
    # Parameter        None
    # Details          AioInit button click event function
    # Return value     None
    #========================================
    def OnClickedButtonAioInit(self):
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Get device name from textbox
        #----------------------------------------
        device_name = self.ui.textbox_device_name_var.get()
        #----------------------------------------
        # Device initialization
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioInit(device_name.encode(), ctypes.byref(self.id))
        #----------------------------------------
        # Get error string
        #----------------------------------------
        caio.AioGetErrorString(lret, error_string)
        #----------------------------------------
        # Display message
        #----------------------------------------
        text_buf = f"AioInit = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # Function name    OnClickedButtonAioResetDevice
    # Parameter        None
    # Details          AioResetDevice button click event function
    # Return value     None
    #========================================
    def OnClickedButtonAioResetDevice(self):
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Reset device
        #----------------------------------------
        lret.value = caio.AioResetDevice(self.id)
        #----------------------------------------
        # Get error string
        #----------------------------------------
        caio.AioGetErrorString(lret, error_string)
        #----------------------------------------
        # Display message
        #----------------------------------------
        text_buf = f"AioResetDevice = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # Function name    OnClickedButtonAiAoSetting
    # Parameter        None
    # Details          Analog I/O Set button click event function
    # Return value     None
    #========================================
    def OnClickedButtonAiAoSetting(self):
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Get the analog input range setting value from combobox
        #----------------------------------------
        ai_range = ctypes.c_short(self.ai_range[self.ui.combobox_ai_range.current()])
        #----------------------------------------
        # Set the analog input range (all channels)
        #----------------------------------------
        lret.value = caio.AioSetAiRangeAll(self.id, ai_range)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Analog I/O Set : AioSetAiRangeAll = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get the input method setting value from combobox
        #----------------------------------------
        input_method = ctypes.c_short(self.ui.combobox_ai_input_method.current())
        #----------------------------------------
        # Set the analog input method
        #----------------------------------------
        lret.value = caio.AioSetAiInputMethod(self.id, input_method)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Analog I/O Set : AioSetAiInputMethod = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get the analog output range setting value from combobox
        #----------------------------------------
        ao_range = ctypes.c_short(self.ao_range[self.ui.combobox_ao_range.current()])
        #----------------------------------------
        # Set the analog output range (all channels)
        #----------------------------------------
        lret.value = caio.AioSetAoRangeAll(self.id, ao_range)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Analog I/O Set : AioSetAoRangeAll = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Display the message that analog input/output settings is completed
        #----------------------------------------
        self.ui.textbox_return_string_var.set("Analog I/O Set : Successful completion")

    #========================================
    # Function name    OnClickedButtonGeneratingSamplingSetting
    # Parameter        None
    # Details          Generating/Sampling Set button click event function
    # Return value     None
    #========================================
    def OnClickedButtonGeneratingSamplingSetting(self):
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Get the number of analog input channels from textbox
        #----------------------------------------
        buf = self.ui.textbox_ai_channels_var.get()
        #----------------------------------------
        # Check if the input value is a number
        #----------------------------------------
        if False == self.isnum(buf, 10):
            self.ui.show_error("Error", "The input value is invalid.")
            return
        else:
            ai_channels = ctypes.c_short(int(buf))
        #----------------------------------------
        # Set the number of analog input channels used for conversion
        #----------------------------------------
        lret.value = caio.AioSetAiChannels(self.id, ai_channels)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAiChannels = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the analog input conversion data transfer mode to device buffer mode
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAiTransferMode(self.id, 0)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAiTransferMode = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the data storage memory type to FIFO
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAiMemoryType(self.id, 0)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAiMemoryType = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the sampling start condition to Event controller output
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAiStartTrigger(self.id, 10)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAiStartTrigger = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the clock type to Event controller output
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAiClockType(self.id, 10)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAiClockType = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the sampling stop condition to Event controller output
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAiStopTrigger(self.id, 10)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAiStopTrigger = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the callback routine: '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)
        #----------------------------------------
        self.pai_callback = caio.PAIO_AI_CALLBACK(self.SamplingSlaveCallBackProc)
        self.pai_user_data = ctypes.cast(ctypes.pointer(ctypes.py_object(self)), ctypes.c_void_p)
        lret.value = caio.AioSetAiCallBackProc(self.id, self.pai_callback, (caio.AIE_START | caio.AIE_END | caio.AIE_OFERR | caio.AIE_SCERR | caio.AIE_ADERR), self.pai_user_data)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAiCallBackProc = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get the number of analog output channels from textbox
        #----------------------------------------
        buf = self.ui.textbox_ao_channels_var.get()
        #----------------------------------------
        # Check if the input value is a number
        #----------------------------------------
        if False == self.isnum(buf, 10):
            self.ui.show_error("Error", "The input value is invalid.")
            return
        else:
            ao_channels = ctypes.c_short(int(buf))
        #----------------------------------------
        # Set the number of analog output channels used for conversion
        #----------------------------------------
        lret.value = caio.AioSetAoChannels(self.id, ao_channels)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoChannels = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the analog output conversion data transfer mode to device buffer mode
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAoTransferMode(self.id, 0)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoTransferMode = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the data storage memory type to FIFO
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAoMemoryType(self.id, 0)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoMemoryType = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the generating start condition to Software
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAoStartTrigger(self.id, 0)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoStartTrigger = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the clock type to Internal Clock
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAoClockType(self.id, 0)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoClockType = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get the internal clock conversion speed from textbox
        #----------------------------------------
        buf = self.ui.textbox_ao_generating_clock_var.get()
        #----------------------------------------
        # Check if the input value is a number
        #----------------------------------------
        if False == self.isnum(buf, 0):
            self.ui.show_error("Error", "The input value is invalid.")
            return
        else:
            ao_generating_clock = ctypes.c_float(float(buf))
        #----------------------------------------
        # Set the internal clock conversion speed
        #----------------------------------------
        lret.value = caio.AioSetAoSamplingClock(self.id, ao_generating_clock)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoSamplingClock = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the generating stop condition to Stop conversion by the specified times
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        lret.value = caio.AioSetAoStopTrigger(self.id, 0)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoStopTrigger = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Set the callback routine: 'Event that device operation end', 
        # 'Event that sampling clock error', and 'Event that DA conversion error'.
        # Caution for modify this function (if modified, the application may not work)
        #----------------------------------------
        self.pao_callback = caio.PAIO_AO_CALLBACK(self.GeneratingMasterCallBackProc)
        self.pao_user_data = ctypes.cast(ctypes.pointer(ctypes.py_object(self)), ctypes.c_void_p)
        lret.value = caio.AioSetAoCallBackProc(self.id, self.pao_callback, (caio.AOE_END | caio.AOE_SCERR | caio.AIOM_AOE_DAERR), self.pao_user_data)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Set : AioSetAoCallBackProc = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Display the message that generating/sampling settings is completed
        #----------------------------------------
        self.ui.textbox_return_string_var.set("Generating/Sampling Set : Successful completion")

    #========================================
    # Function name    OnClickedButtonSyncSetting
    # Parameter        None
    # Details          Sync Operation Set button click event function
    # Return value     None
    #========================================
    def OnClickedButtonSyncSetting(self):
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Event Controller Setting : Connect Analog output internal clock signal to Analog input sampling clock
        #----------------------------------------
        lret.value = caio.AioSetEcuSignal(self.id, caio.AIOECU_DEST_AI_CLK, caio.AIOECU_SRC_AO_CLK)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Sync Operation Set : AioSetEcuSignal = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Event Controller Setting : Connect Ao software start signal to Analog input converting start signal
        #----------------------------------------
        lret.value = caio.AioSetEcuSignal(self.id, caio.AIOECU_DEST_AI_START, caio.AIOECU_SRC_START)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Sync Operation Set : AioSetEcuSignal = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Event Controller Setting: Connect Analog output signal that data of the specified sampling times have been output (FIFO) to Analog input converting stop signal
        #----------------------------------------
        lret.value = caio.AioSetEcuSignal(self.id, caio.AIOECU_DEST_AI_STOP, caio.AIOECU_SRC_AO_STOP_FIFO)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Sync Operation Set : AioSetEcuSignal = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Display the message that synchronous operation settings is completed
        #----------------------------------------
        self.ui.textbox_return_string_var.set("Sync Operation Set : Successful completio")

    #========================================
    # Function name    OnClickedButtonOutputDataSetting
    # Parameter        None
    # Details          Output Data Set button click event function
    # Return value     None
    #========================================
    def OnClickedButtonOutputDataSetting(self):
        ao_channels = ctypes.c_short()                     # Number of channels
        ao_range = ctypes.c_short()                        # Range
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Get the number of channels
        #----------------------------------------
        lret.value = caio.AioGetAoChannels(self.id, ctypes.byref(ao_channels))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Output Data Set : AioGetAoChannels = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get range (channel 0 only)
        #----------------------------------------
        lret.value = caio.AioGetAoRange(self.id, 0, ctypes.byref(ao_range))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Output Data Set : AioGetAoRange = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get generating times from textbox
        #----------------------------------------
        buf = self.ui.textbox_ao_generating_times_var.get()
        #----------------------------------------
        # Check if the input value is a number
        #----------------------------------------
        if False == self.isnum(buf, 10):
            self.ui.show_error("Error", "The input value is invalid.")
            return
        else:
            generating_times = ctypes.c_long(int(buf))
        #----------------------------------------
        # Allocate an array for data storage
        #----------------------------------------
        if self.generating_data is not None:
            self.generating_data = None
        try:
            self.generating_data = (ctypes.c_float * (generating_times.value * ao_channels.value))()
        except:
            self.ui.textbox_return_string_var.set('Output Data Set : Failed to allocate an array for storing data')
            return
        #----------------------------------------
        # Create analog output data : sine waveform
        #----------------------------------------
        gain, offset = self.GetSineCoefficient(ao_range)
        for i in range(generating_times.value):
            for j in range(ao_channels.value):
                self.generating_data[i * ao_channels.value + j] = ctypes.c_float(gain * math.sin(2 * 3.14159265358979 * i / generating_times.value + 3.14159265358979 / 2 * (j % 4)) + offset)
        #----------------------------------------
        # Set analog output data
        #----------------------------------------
        lret.value = caio.AioSetAoSamplingDataEx(self.id, generating_times, self.generating_data)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Output Data Set : AioSetAoSamplingDataEx = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Open file
        #----------------------------------------
        try:
            file = open(self.file_name, 'w')
        except:
            self.ui.textbox_return_string_var.set("Output Data Set : open = file open error.")
            return
        #----------------------------------------
        # Create file
        #----------------------------------------
        for i in range(generating_times.value):
            #--------------------
            # Generate display string
            #--------------------
            text_string = f"{(i + 1):d},"
            #--------------------
            # Repeat the process for the specified number of channels
            #--------------------
            for j in range(ao_channels.value):
                text_string += f"{self.generating_data[i * ao_channels.value + j]:0.5f}"
                #--------------------
                # Add newline character for the last channel
                #--------------------
                if j == ao_channels.value - 1:
                    text_string += "\n"
                #--------------------
                # Add comma for channels other than the last channel
                #--------------------
                else:
                    text_string += ","
            #----------------------------------------
            # Write data
            #----------------------------------------
            file.write(text_string)
        #----------------------------------------
        # Close file
        #----------------------------------------
        file.close()
        #----------------------------------------
        # Display the message that output data set is completed
        #----------------------------------------
        self.ui.textbox_return_string_var.set('Output Data Set : Successful completion')

    #========================================
    # Function name    OnClickedButtonGeneratingSamplingStart
    # Parameter        None
    # Details          Generating/Sampling Start button click event function
    # Return value     None
    #========================================
    def OnClickedButtonGeneratingSamplingStart(self):
        ai_status = ctypes.c_long()                        # Analog input status
        ao_status = ctypes.c_long()                        # Analog output status
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Clear memory
        #----------------------------------------
        lret.value = caio.AioResetAiMemory(self.id)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Start : AioResetAiMemory = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Clear status
        #----------------------------------------
        lret.value = caio.AioResetAiStatus(self.id)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Start : AioResetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Initialize the total sampling count
        #----------------------------------------
        self.sampling_count = 0
        #----------------------------------------
        # Start sampling
        #----------------------------------------
        lret.value = caio.AioStartAi(self.id)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Start : AioStartAi = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get status
        #----------------------------------------
        lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Start : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Create the status string
        #----------------------------------------
        ai_status_string = self.GetAiStatusString(ai_status)
        #----------------------------------------
        # Display the status
        #----------------------------------------
        self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
        #----------------------------------------
        # Update the sampling count
        #----------------------------------------
        self.ui.textbox_ai_sampling_count_var.set("0")
        #----------------------------------------
        # Clear the listbox for sampling data display
        #----------------------------------------
        self.ui.listbox_ai_sampling_data_var.set([""])
        #----------------------------------------
        # Reset the analog output status
        #----------------------------------------
        lret.value = caio.AioResetAoStatus(self.id)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Start : AioResetAoStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Initialize the total generating count
        #----------------------------------------
        self.generating_count = 0
        #----------------------------------------
        # Start generating
        #----------------------------------------
        lret.value = caio.AioStartAo(self.id)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Start : AioStartAo = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get status
        #----------------------------------------
        lret.value = caio.AioGetAoStatus(self.id, ctypes.byref(ao_status))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Start : AioGetAoStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Create the status string
        #----------------------------------------
        ao_status_string = self.GetAoStatusString(ao_status)
        #----------------------------------------
        # Display the status
        #----------------------------------------
        self.ui.textbox_ao_status_var.set(f"{ao_status.value:08x}H ({ao_status_string})")
        #----------------------------------------
        # Update generating count
        #----------------------------------------
        self.ui.textbox_ao_generating_count_var.set("0")
        #----------------------------------------
        # Display the message that generating/sampling start is completed
        #----------------------------------------
        self.ui.textbox_return_string_var.set("Generating/Sampling Start : Successful completion")

    #========================================
    # Function name    OnClickedButtonGetStatus
    # Parameter        None
    # Details          Get Status button click event function
    # Return value     None
    #========================================
    def OnClickedButtonGetStatus(self):
        ai_sampling_count = ctypes.c_long()                # Sampling count
        ai_status = ctypes.c_long()                        # Sampling status
        ao_generating_count = ctypes.c_long()              # Generating count
        ao_status = ctypes.c_long()                        # Generating status
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Get the sampling count
        #----------------------------------------
        lret.value = caio.AioGetAiSamplingCount(self.id, ctypes.byref(ai_sampling_count))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Get Status : AioGetAiSamplingCount = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Display sampling count
        #----------------------------------------
        text_buf = f"{ai_sampling_count.value}"
        self.ui.textbox_ai_sampling_count_var.set(text_buf)
        #----------------------------------------
        # Get sampling status
        #----------------------------------------
        lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Get Status : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Create the status string
        #----------------------------------------
        ai_status_string = self.GetAiStatusString(ai_status)
        #----------------------------------------
        # Display the status
        #----------------------------------------
        self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
        #----------------------------------------
        # Get generating count
        #----------------------------------------
        lret.value = caio.AioGetAoSamplingCount(self.id, ctypes.byref(ao_generating_count))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Get Status : AioGetAoSamplingCount = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Update the generating count
        #----------------------------------------
        text_buf = f"{ao_generating_count.value}"
        self.ui.textbox_ao_generating_count_var.set(text_buf)
        #----------------------------------------
        # Get generating status
        #----------------------------------------
        lret.value = caio.AioGetAoStatus(self.id, ctypes.byref(ao_status))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Get Status : AioGetAoStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Create the status string
        #----------------------------------------
        ao_status_string = self.GetAoStatusString(ao_status)
        #----------------------------------------
        # Display the status
        #----------------------------------------
        self.ui.textbox_ao_status_var.set(f"{ao_status.value:08x}H ({ao_status_string})")
        #----------------------------------------
        # Display the message that get status is completed
        #----------------------------------------
        self.ui.textbox_return_string_var.set("Get Status : Successful completion")

    #========================================
    # Function name    OnClickedButtonGeneratingSamplingStop
    # Parameter        None
    # Details          Generating/Sampling Stop button click event function
    # Return value     None
    #========================================
    def OnClickedButtonGeneratingSamplingStop(self):
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code
        ao_status = ctypes.c_long()                        # Generating Status
        ao_generating_count = ctypes.c_long()              # Generating count
        ai_status = ctypes.c_long()                        # Sampling Status
        ai_sampling_count = ctypes.c_long()                # Sampling count
        ai_channels = ctypes.c_short()                     # Number of channels

        #----------------------------------------
        # Stop generating
        #----------------------------------------
        lret.value = caio.AioStopAo(self.id)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Stop : AioStopAo = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get status
        #----------------------------------------
        lret.value = caio.AioGetAoStatus(self.id, ctypes.byref(ao_status))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Stop : AioGetAoStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Create the status string
        #----------------------------------------
        ao_status_string = self.GetAoStatusString(ao_status)
        #----------------------------------------
        # Display the status
        #----------------------------------------
        self.ui.textbox_ao_status_var.set(f"{ao_status.value:08x}H ({ao_status_string})")
        #----------------------------------------
        # Get the current generating count
        #----------------------------------------
        lret.value = caio.AioGetAoSamplingCount(self.id, ctypes.byref(ao_generating_count))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Stop : AioGetAoSamplingCount = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Display generating count
        #----------------------------------------
        text_buf = f"{ao_generating_count.value}"
        self.ui.textbox_ao_generating_count_var.set(text_buf)
        #----------------------------------------
        # Update the total generating count
        #----------------------------------------
        self.generating_count = ao_generating_count.value
        #----------------------------------------
        # Stop sampling
        #----------------------------------------
        lret.value = caio.AioStopAi(self.id)
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Stop : AioStopAi = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Get status
        #----------------------------------------
        lret.value = caio.AioGetAiStatus(self.id, ctypes.byref(ai_status))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Stop : AioGetAiStatus = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Create the status string
        #----------------------------------------
        ai_status_string = self.GetAiStatusString(ai_status)
        #----------------------------------------
        # Display the status
        #----------------------------------------
        self.ui.textbox_ai_status_var.set(f"{ai_status.value:08x}H ({ai_status_string})")
        #----------------------------------------
        # Get the current sampling count
        #----------------------------------------
        lret.value = caio.AioGetAiSamplingCount(self.id, ctypes.byref(ai_sampling_count))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Generating/Sampling Stop : AioGetAiSamplingCount = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # Display sampling count
        #----------------------------------------
        text_buf = f"{ai_sampling_count.value}"
        self.ui.textbox_ai_sampling_count_var.set(text_buf)
        #----------------------------------------
        # When the sampling count of the data acquired this time is 1 or more
        #----------------------------------------
        if ai_sampling_count.value > 0:
            #----------------------------------------
            # Get the number of channels
            #----------------------------------------
            lret.value = caio.AioGetAiChannels(self.id, ctypes.byref(ai_channels))
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Generating/Sampling Stop : AioGetAiChannels = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Allocate an array for storing data
            #----------------------------------------
            if self.sampling_data is not None:
                self.sampling_data = None
            try:
                self.sampling_data = (ctypes.c_float * (ai_sampling_count.value * ai_channels.value))()
            except:
                self.ui.textbox_return_string_var.set("Generating/Sampling Stop : Failed to allocate an array for storing data")
                return
            #----------------------------------------
            # Get sampling data
            #----------------------------------------
            lret.value = caio.AioGetAiSamplingDataEx(self.id, ctypes.byref(ai_sampling_count), self.sampling_data)
            #----------------------------------------
            # Error process
            #----------------------------------------
            if lret.value != 0:
                #--------------------
                # Get error string
                #--------------------
                caio.AioGetErrorString(lret, error_string)
                #--------------------
                # Display message
                #--------------------
                text_buf = f"Generating/Sampling Stop : AioGetAiSamplingDataEx = {lret.value} : {error_string.value.decode('sjis')}"
                self.ui.textbox_return_string_var.set(text_buf)
                return
            #----------------------------------------
            # Update the total sampling count
            #----------------------------------------
            self.sampling_count = ai_sampling_count.value
            #----------------------------------------
            # 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.value > self.DISPLAY_SAMPLING_COUNT:
                #--------------------
                # Limit the maximum number of loops to the data display maximum sampling count
                #--------------------
                loop_max_count = self.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 acquired data
                #--------------------
                top_address = ai_sampling_count.value - self.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.value
                #--------------------
                # Set the top address of the referenced buffer to 0
                #--------------------
                top_address = 0
            #----------------------------------------
            # Display sampling data
            # (Display from the end of acquired data to the maximum number of data display sampling count)
            #----------------------------------------
            #--------------------
            # Clear the listbox for sampling data display
            #--------------------
            self.ui.listbox_ai_sampling_data_var.set([""])
            data = []
            #--------------------
            # Repeat the process up to the maximum sampling count of the display data
            #--------------------
            for i in range(top_address, loop_max_count + top_address):
                #--------------------
                # Generate display string
                #--------------------
                text_string = f"{(i + 1):5d}:  "
                #--------------------
                # Repeat the process for the specified number of channels
                #--------------------
                for j in range(ai_channels.value):
                    text_string += f" {self.sampling_data[i * ai_channels.value + j]:10.5f}"
                #----------------------------------------
                # Collect sampling data
                #----------------------------------------
                data.append(text_string)
            #----------------------------------------
            # Display sampling start data
            #----------------------------------------
            self.ui.listbox_ai_sampling_data_var.set(data)
            #----------------------------------------
            # Display the message that generating/sampling stop is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Generating/Sampling Stop : Successful completion")
        #----------------------------------------
        # When the sampling count of the data acquired this time is 0 or less
        #----------------------------------------
        else:
            #----------------------------------------
            # Display the message that generating/sampling stop is completed
            #----------------------------------------
            self.ui.textbox_return_string_var.set("Generating/Sampling Stop : Successful completion")

    #========================================
    # Function name    OnClickedButtonOutputSamplingData
    # Parameter        None
    # Details          Output Acquired Data to File button click event function
    # Return value     None
    #========================================
    def OnClickedButtonOutputSamplingData(self):
        ai_channels = ctypes.c_short()                     # Number of channels
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code
        file_name = "SamplingData.csv"                     # Sampling data output file name

        #----------------------------------------
        # Open file
        #----------------------------------------
        try:
            file = open(file_name, 'w')
        except:
            self.ui.textbox_return_string_var.set("Output Acquired Data to File : open = file open error.")
            return
        #----------------------------------------
        # Get the number of channels
        #----------------------------------------
        lret.value = caio.AioGetAiChannels(self.id, ctypes.byref(ai_channels))
        #----------------------------------------
        # Error process
        #----------------------------------------
        if lret.value != 0:
            #--------------------
            # Get error string
            #--------------------
            caio.AioGetErrorString(lret, error_string)
            #--------------------
            # Display message
            #--------------------
            text_buf = f"Output Acquired Data to File : AioGetAiChannels = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            #--------------------
            # Close file
            #--------------------
            file.close()
            return
        #----------------------------------------
        # Create sampling data for file output
        #----------------------------------------
        #--------------------
        # If the total sampling count is 1 or more, output the file
        #--------------------
        if self.sampling_count > 0:
            #--------------------
            # Repeat the process up to the total sampling count
            #--------------------
            for i in range(self.sampling_count):
                #--------------------
                # Generate display string
                #--------------------
                text_string = f"{(i + 1):d},"
                #--------------------
                # Repeat the process for the specified number of channels
                #--------------------
                for j in range(ai_channels.value):
                    text_string += f"{self.sampling_data[i * ai_channels.value + j]:0.5f}"
                    #--------------------
                    # Add newline character for the last channel
                    #--------------------
                    if j == ai_channels.value - 1:
                        text_string += "\n"
                    #--------------------
                    # Add comma for channels other than the last channel
                    #--------------------
                    else:
                        text_string += ","
                #----------------------------------------
                # Write data
                #----------------------------------------
                file.write(text_string)
        #----------------------------------------
        # Close file
        #----------------------------------------
        file.close()
        #----------------------------------------
        # Display the message that file output is completed
        #----------------------------------------
        text_buf = f"Output Acquired Data to File : Save data to \"{file_name}\"."
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # Function name    OnClickedButtonAioExit
    # Parameter        None
    # Details          AioExit button click event function
    # Return value     None
    #========================================
    def OnClickedButtonAioExit(self):
        error_string = ctypes.create_string_buffer(256)    # Error code string
        lret = ctypes.c_long()                             # For return code

        #----------------------------------------
        # Release the array for storing AD conversion data
        #----------------------------------------
        if self.sampling_data is not None:
            self.sampling_data = None
        #----------------------------------------
        # Release the output data buffer
        #----------------------------------------
        if self.generating_data is not None:
            self.generating_data = None
        #----------------------------------------
        # Exit process
        #----------------------------------------
        lret.value = caio.AioExit(self.id)
        #----------------------------------------
        # Get error string
        #----------------------------------------
        caio.AioGetErrorString(lret, error_string)
        #----------------------------------------
        # Display message
        #----------------------------------------
        text_buf = f"AioExit = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # Function name    OnClickedButtonClose
    # Parameter        None
    # Details          Close button click event function
    # Return value     None
    #========================================
    def OnClickedButtonClose(self):
        #----------------------------------------
        # Release the array for storing AD conversion data
        #----------------------------------------
        if self.sampling_data is not None:
            self.sampling_data = None
        #----------------------------------------
        # Release the output data buffer
        #----------------------------------------
        if self.generating_data is not None:
            self.generating_data = None
        #----------------------------------------
        # Exit process
        #----------------------------------------
        caio.AioExit(self.id)
        #----------------------------------------
        # Close window
        #----------------------------------------
        self.ui.root.destroy()

    #========================================
    # Function name    run
    # Parameter        None
    # Details          Run the application function
    # Return value     None
    #========================================
    def run(self):
        self.ui.run()


#========================================
# main function
#========================================
def main():
    #----------------------------------------
    # Create and Run InternalSyncGeneratingSampling
    #----------------------------------------
    instance = InternalSyncGeneratingSampling()
    instance.run()

#========================================
# Call main function
#========================================
if __name__ == "__main__":
    main()