﻿#================================================================
#================================================================
# API-AIO(WDM)
# Sampling synchronization between 2 devices using synchronization bus sample
# main UI file
#                                                 CONTEC Co.,Ltd.
#================================================================
#================================================================
#----------------------------------------
# Import modules
#----------------------------------------
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox


#========================================
# SyncBusSamplingUI class
#========================================
class SyncBusSamplingUI:
    #========================================
    # Initialization function
    #========================================
    def __init__(self):
        #----------------------------------------
        # Start creating main screen
        #----------------------------------------
        self.root = tk.Tk()
        #----------------------------------------
        # Title
        #----------------------------------------
        self.root.title('Sampling Synchronization Between 2 Devices Using Synchronization Bus')
        self.root.minsize(1156,765)
        #----------------------------------------
        # Set the font for controls
        #----------------------------------------
        self.root.option_add("*Font", ("MS Gothic", 9))
        #----------------------------------------
        # Start creating the UI
        #----------------------------------------
        self._create_ui()

    #========================================
    # UI creation function
    #========================================
    def _create_ui(self):
        #----------------------------------------
        # Create LabelFrame for Initialize
        #----------------------------------------
        self.groupbox_init = tk.LabelFrame(self.root, text="Initialize")
        self.groupbox_init.place(x=15, y=10, width=1126, height=98)
        #--------------------
        # Create LabelFrame for Master
        #--------------------
        self.groupbox_init_master = tk.LabelFrame(self.groupbox_init, text="Master")
        self.groupbox_init_master.place(x=10, y=3, width=440, height=45)
        #--------------------
        # Create Label for Device Name
        #--------------------
        tk.Label(self.groupbox_init_master, text='Device Name : ', anchor='nw').place(x=5, y=3, width=90, height=19)
        #--------------------
        # Create Entry for Device Name
        #--------------------
        self.textbox_master_device_name_var = tk.StringVar(self.groupbox_init_master)
        self.textbox_master_device_name_var.set('AIO000')
        tk.Entry(self.groupbox_init_master, textvariable=self.textbox_master_device_name_var).place(x=170, y=3, width=140, height=19)
        #--------------------
        # Create LabelFrame for Salve
        #--------------------
        self.groupbox_init_slave = tk.LabelFrame(self.groupbox_init, text="Salve")
        self.groupbox_init_slave.place(x=460, y=3, width=440, height=45)
        #--------------------
        # Create Label for Device Name
        #--------------------
        tk.Label(self.groupbox_init_slave, text='Device Name : ', anchor='nw').place(x=5, y=3, width=90, height=19)
        #--------------------
        # Create Entry for Device Name
        #--------------------
        self.textbox_slave_device_name_var = tk.StringVar(self.groupbox_init_slave)
        self.textbox_slave_device_name_var.set('AIO001')
        tk.Entry(self.groupbox_init_slave, textvariable=self.textbox_slave_device_name_var).place(x=170, y=3, width=140, height=19)
        #--------------------
        # Create Button for AioInit
        #--------------------
        self.button_aio_init = tk.Button(self.groupbox_init, text='AioInit')
        self.button_aio_init.place(x=910, y=3, width=200, height=30)
        #--------------------
        # Create Button for AioResetDevice
        #--------------------
        self.button_aio_reset_device = tk.Button(self.groupbox_init, text='AioResetDevice')
        self.button_aio_reset_device.place(x=910, y=43, width=200, height=30)
        #----------------------------------------
        # Create LabelFrame for Sync Operation
        #----------------------------------------
        self.groupbox_sync = tk.LabelFrame(self.root, text="Sync Operation")
        self.groupbox_sync.place(x=15, y=118, width=1126, height=450)
        #--------------------
        # Create LabelFrame for Master
        #--------------------
        self.groupbox_sync_master = tk.LabelFrame(self.groupbox_sync, text="Master")
        self.groupbox_sync_master.place(x=10, y=3, width=440, height=425)
        #--------------------
        # Create LabelFrame for Analog Input Set
        #--------------------
        self.groupbox_sync_master_ai = tk.LabelFrame(self.groupbox_sync_master, text="Analog Input Set")
        self.groupbox_sync_master_ai.place(x=10, y=3, width=417, height=70)
        #--------------------
        # Create Label for Range
        #--------------------
        tk.Label(self.groupbox_sync_master_ai, text='Range : ', anchor='nw').place(x=5, y=3, width=90, height=19)
        #--------------------
        # Create Combobox for Range
        #--------------------
        self.combobox_master_ai_range = ttk.Combobox(self.groupbox_sync_master_ai)
        self.combobox_master_ai_range.place(x=158, y=3, width=140, height=20)
        self.combobox_master_ai_range['value'] = ('-10 - +10V', '-5 - +5V', '-2.5 - +2.5V', '-1.25 - +1.25V', '0 - +10V', '0 - +5V', '0 - +2.5V', '0 - +1.25V', '0 - 20mA', '4 - 20mA', '-20 - +20mA', '1 - +5V')
        self.combobox_master_ai_range['state'] = 'readonly'
        self.combobox_master_ai_range.current(0)
        #--------------------
        # Create Label for Input Method
        #--------------------
        tk.Label(self.groupbox_sync_master_ai, text='Input Method : ', anchor='nw').place(x=5, y=28, width=90, height=19)
        #--------------------
        # Create Combobox for Input Method
        #--------------------
        self.combobox_master_ai_input_method = ttk.Combobox(self.groupbox_sync_master_ai)
        self.combobox_master_ai_input_method.place(x=158, y=28, width=140, height=20)
        self.combobox_master_ai_input_method['value'] = ('Single-end input', 'Differential input')
        self.combobox_master_ai_input_method['state'] = 'readonly'
        self.combobox_master_ai_input_method.current(0)
        #--------------------
        # Create LabelFrame for Sampling Set
        #--------------------
        self.groupbox_sync_master_sampling = tk.LabelFrame(self.groupbox_sync_master, text="Sampling Set")
        self.groupbox_sync_master_sampling.place(x=10, y=78, width=417, height=120)
        #--------------------
        # Create Label for Number of Channels
        #--------------------
        tk.Label(self.groupbox_sync_master_sampling, text='Number of Channels : ', anchor='nw').place(x=5, y=3, width=120, height=19)
        #--------------------
        # Create Entry for Number of Channels
        #--------------------
        self.textbox_master_ai_channels_var = tk.StringVar(self.groupbox_sync_master_sampling)
        self.textbox_master_ai_channels_var.set('1')
        tk.Entry(self.groupbox_sync_master_sampling, textvariable=self.textbox_master_ai_channels_var, justify=tk.RIGHT).place(x=158, y=3, width=140, height=19)
        #--------------------
        # Create Label for Start Condition
        #--------------------
        tk.Label(self.groupbox_sync_master_sampling, text='Start Condition : ', anchor='nw').place(x=5, y=28, width=120, height=19)
        #--------------------
        # Create Label for Software
        #--------------------
        tk.Label(self.groupbox_sync_master_sampling, text='Software', anchor='nw').place(x=156, y=28, width=90, height=19)
        #--------------------
        # Create Label for Internal Clock Value
        #--------------------
        tk.Label(self.groupbox_sync_master_sampling, text='Internal Clock Value : ', anchor='nw').place(x=5, y=53, width=150, height=19)
        #--------------------
        # Create Entry for Internal Clock Value
        #--------------------
        self.textbox_master_ai_sampling_clock_var = tk.StringVar(self.groupbox_sync_master_sampling)
        self.textbox_master_ai_sampling_clock_var.set('1000')
        tk.Entry(self.groupbox_sync_master_sampling, textvariable=self.textbox_master_ai_sampling_clock_var, justify=tk.RIGHT).place(x=158, y=53, width=140, height=19)
        #--------------------
        # Create Label for Internal Clock Value Unit
        #--------------------
        tk.Label(self.groupbox_sync_master_sampling, text='[usec]', anchor='nw').place(x=300, y=53, width=50, height=19)
        #--------------------
        # Create Label for Stop Times
        #--------------------
        tk.Label(self.groupbox_sync_master_sampling, text='Stop Times : ', anchor='nw').place(x=5, y=78, width=90, height=19)
        #--------------------
        # Create Entry for Stop Times
        #--------------------
        self.textbox_master_ai_stop_times_var = tk.StringVar(self.groupbox_sync_master_sampling)
        self.textbox_master_ai_stop_times_var.set('1000')
        tk.Entry(self.groupbox_sync_master_sampling, textvariable=self.textbox_master_ai_stop_times_var, justify=tk.RIGHT).place(x=158, y=78, width=140, height=19)
        #--------------------
        # Create LabelFrame for Sampling Status
        #--------------------
        self.groupbox_sync_master_status = tk.LabelFrame(self.groupbox_sync_master, text="Sampling Status")
        self.groupbox_sync_master_status.place(x=10, y=203, width=417, height=200)
        #--------------------
        # Create Label for Count
        #--------------------
        tk.Label(self.groupbox_sync_master_status, text='Count', anchor='nw').place(x=156, y=3, width=90, height=19)
        #--------------------
        # Create Label for Voltage[V]/Current[mA]
        #--------------------
        tk.Label(self.groupbox_sync_master_status, text='Voltage[V]/Current[mA]', anchor='nw').place(x=246, y=3, width=150, height=19)
        #--------------------
        # Create Label for Sampling Data
        #--------------------
        tk.Label(self.groupbox_sync_master_status, text='Sampling Data : ', anchor='nw').place(x=5, y=23, width=120, height=19)
        #--------------------
        # Create Listbox for Sampling Data
        #--------------------
        self.listbox_master_ai_sampling_data_var = tk.StringVar(self.groupbox_sync_master_status)
        self.listbox_master_ai_sampling_data = tk.Listbox(self.groupbox_sync_master_status, listvariable=self.listbox_master_ai_sampling_data_var)
        self.listbox_master_ai_sampling_data.place(x=158, y=23, width=227, height=80)
        self.scrollbar_master_v = ttk.Scrollbar(self.groupbox_sync_master_status, orient=tk.VERTICAL, command=self.listbox_master_ai_sampling_data.yview)
        self.scrollbar_master_v.place(x=385, y=23, width=20, height=80)
        self.scrollbar_master_h = ttk.Scrollbar(self.groupbox_sync_master_status, orient=tk.HORIZONTAL, command=self.listbox_master_ai_sampling_data.xview)
        self.scrollbar_master_h.place(x=158, y=103, width=227, height=20)
        self.listbox_master_ai_sampling_data.config(yscrollcommand=self.scrollbar_master_v.set, xscrollcommand=self.scrollbar_master_h.set)
        #--------------------
        # Create Label for Sampling Count
        #--------------------
        tk.Label(self.groupbox_sync_master_status, text='Sampling Count : ', anchor='nw').place(x=5, y=130, width=120, height=19)
        #--------------------
        # Create Entry for Sampling Count
        #--------------------
        self.textbox_master_ai_sampling_count_var = tk.StringVar(self.groupbox_sync_master_status)
        tk.Entry(self.groupbox_sync_master_status, textvariable=self.textbox_master_ai_sampling_count_var, justify=tk.RIGHT).place(x=158, y=130, width=247, height=19)
        #--------------------
        # Create Label for Status
        #--------------------
        tk.Label(self.groupbox_sync_master_status, text='Status : ', anchor='nw').place(x=5, y=155, width=120, height=19)
        #--------------------
        # Create Entry for Status
        #--------------------
        self.textbox_master_ai_status_var = tk.StringVar(self.groupbox_sync_master_status)
        tk.Entry(self.groupbox_sync_master_status, textvariable=self.textbox_master_ai_status_var).place(x=158, y=155, width=247, height=19)
        #--------------------
        # Create LabelFrame for Salve
        #--------------------
        self.groupbox_sync_slave = tk.LabelFrame(self.groupbox_sync, text="Salve")
        self.groupbox_sync_slave.place(x=460, y=3, width=440, height=425)
        #--------------------
        # Create LabelFrame for Analog Input Set
        #--------------------
        self.groupbox_sync_slave_ai = tk.LabelFrame(self.groupbox_sync_slave, text="Analog Input Set")
        self.groupbox_sync_slave_ai.place(x=10, y=3, width=417, height=70)
        #--------------------
        # Create Label for Range
        #--------------------
        tk.Label(self.groupbox_sync_slave_ai, text='Range : ', anchor='nw').place(x=5, y=3, width=90, height=19)
        #--------------------
        # Create Combobox for Range
        #--------------------
        self.combobox_slave_ai_range = ttk.Combobox(self.groupbox_sync_slave_ai)
        self.combobox_slave_ai_range.place(x=158, y=3, width=140, height=20)
        self.combobox_slave_ai_range['value'] = ('-10 - +10V', '-5 - +5V', '-2.5 - +2.5V', '-1.25 - +1.25V', '0 - +10V', '0 - +5V', '0 - +2.5V', '0 - +1.25V', '0 - 20mA', '4 - 20mA', '-20 - +20mA', '1 - +5V')
        self.combobox_slave_ai_range['state'] = 'readonly'
        self.combobox_slave_ai_range.current(0)
        #--------------------
        # Create Label for Input Method
        #--------------------
        tk.Label(self.groupbox_sync_slave_ai, text='Input Method : ', anchor='nw').place(x=5, y=28, width=90, height=19)
        #--------------------
        # Create Combobox for Input Method
        #--------------------
        self.combobox_slave_ai_input_method = ttk.Combobox(self.groupbox_sync_slave_ai)
        self.combobox_slave_ai_input_method.place(x=158, y=28, width=140, height=20)
        self.combobox_slave_ai_input_method['value'] = ('Single-end input', 'Differential input')
        self.combobox_slave_ai_input_method['state'] = 'readonly'
        self.combobox_slave_ai_input_method.current(0)
        #--------------------
        # Create LabelFrame for Sampling Set
        #--------------------
        self.groupbox_sync_slave_sampling = tk.LabelFrame(self.groupbox_sync_slave, text="Sampling Set")
        self.groupbox_sync_slave_sampling.place(x=10, y=78, width=417, height=120)
        #--------------------
        # Create Label for Number of Channels
        #--------------------
        tk.Label(self.groupbox_sync_slave_sampling, text='Number of Channels : ', anchor='nw').place(x=5, y=3, width=120, height=19)
        #--------------------
        # Create Entry for Number of Channels
        #--------------------
        self.textbox_slave_ai_channels_var = tk.StringVar(self.groupbox_sync_slave_sampling)
        self.textbox_slave_ai_channels_var.set('1')
        tk.Entry(self.groupbox_sync_slave_sampling, textvariable=self.textbox_slave_ai_channels_var, justify=tk.RIGHT).place(x=158, y=3, width=140, height=19)
        #--------------------
        # Create Label for Start Condition
        #--------------------
        tk.Label(self.groupbox_sync_slave_sampling, text='Start Condition : ', anchor='nw').place(x=5, y=28, width=120, height=19)
        #--------------------
        # Create Label for Master Device Sampling Start
        #--------------------
        tk.Label(self.groupbox_sync_slave_sampling, text='Master Device Sampling Start', anchor='nw').place(x=156, y=28, width=250, height=19)
        #--------------------
        # Create Label for Clock Condition
        #--------------------
        tk.Label(self.groupbox_sync_slave_sampling, text='Clock Condition : ', anchor='nw').place(x=5, y=53, width=120, height=19)
        #--------------------
        # Create Label for Master Device Sampling Internal Clock
        #--------------------
        tk.Label(self.groupbox_sync_slave_sampling, text='Master Device Sampling Internal Clock', anchor='nw').place(x=156, y=53, width=250, height=19)
        #--------------------
        # Create Label for Stop Condition
        #--------------------
        tk.Label(self.groupbox_sync_slave_sampling, text='Stop Condition : ', anchor='nw').place(x=5, y=78, width=120, height=19)
        #--------------------
        # Create Label for Master Device Sampling Stop
        #--------------------
        tk.Label(self.groupbox_sync_slave_sampling, text='Master Device Sampling Stop', anchor='nw').place(x=156, y=78, width=250, height=19)
        #--------------------
        # Create LabelFrame for Sampling Status
        #--------------------
        self.groupbox_sync_slave_status = tk.LabelFrame(self.groupbox_sync_slave, text="Sampling Status")
        self.groupbox_sync_slave_status.place(x=10, y=203, width=417, height=200)
        #--------------------
        # Create Label for Count
        #--------------------
        tk.Label(self.groupbox_sync_slave_status, text='Count', anchor='nw').place(x=156, y=3, width=90, height=19)
        #--------------------
        # Create Label for Voltage[V]/Current[mA]
        #--------------------
        tk.Label(self.groupbox_sync_slave_status, text='Voltage[V]/Current[mA]', anchor='nw').place(x=246, y=3, width=150, height=19)
        #--------------------
        # Create Label for Sampling Data
        #--------------------
        tk.Label(self.groupbox_sync_slave_status, text='Sampling Data : ', anchor='nw').place(x=5, y=23, width=120, height=19)
        #--------------------
        # Create Listbox for Sampling Data
        #--------------------
        self.listbox_slave_ai_sampling_data_var = tk.StringVar(self.groupbox_sync_slave_status)
        self.listbox_slave_ai_sampling_data = tk.Listbox(self.groupbox_sync_slave_status, listvariable=self.listbox_slave_ai_sampling_data_var)
        self.listbox_slave_ai_sampling_data.place(x=158, y=23, width=227, height=80)
        self.scrollbar_slave_v = ttk.Scrollbar(self.groupbox_sync_slave_status, orient=tk.VERTICAL, command=self.listbox_slave_ai_sampling_data.yview)
        self.scrollbar_slave_v.place(x=385, y=23, width=20, height=80)
        self.scrollbar_slave_h = ttk.Scrollbar(self.groupbox_sync_slave_status, orient=tk.HORIZONTAL, command=self.listbox_slave_ai_sampling_data.xview)
        self.scrollbar_slave_h.place(x=158, y=103, width=227, height=20)
        self.listbox_slave_ai_sampling_data.config(yscrollcommand=self.scrollbar_slave_v.set, xscrollcommand=self.scrollbar_slave_h.set)
        #--------------------
        # Create Label for Sampling Count
        #--------------------
        tk.Label(self.groupbox_sync_slave_status, text='Sampling Count : ', anchor='nw').place(x=5, y=130, width=120, height=19)
        #--------------------
        # Create Entry for Sampling Count
        #--------------------
        self.textbox_slave_ai_sampling_count_var = tk.StringVar(self.groupbox_sync_slave_status)
        tk.Entry(self.groupbox_sync_slave_status, textvariable=self.textbox_slave_ai_sampling_count_var, justify=tk.RIGHT).place(x=158, y=130, width=247, height=19)
        #--------------------
        # Create Label for Status
        #--------------------
        tk.Label(self.groupbox_sync_slave_status, text='Status : ', anchor='nw').place(x=5, y=155, width=120, height=19)
        #--------------------
        # Create Entry for Status
        #--------------------
        self.textbox_slave_ai_status_var = tk.StringVar(self.groupbox_sync_slave_status)
        tk.Entry(self.groupbox_sync_slave_status, textvariable=self.textbox_slave_ai_status_var).place(x=158, y=155, width=247, height=19)
        #--------------------
        # Create Button for Analog Input Set
        #--------------------
        self.button_ai_setting = tk.Button(self.groupbox_sync, text='Analog Input Set')
        self.button_ai_setting.place(x=910, y=20, width=200, height=30)
        #--------------------
        # Create Button for Sampling Set
        #--------------------
        self.button_sampling_setting = tk.Button(self.groupbox_sync, text='Sampling Set')
        self.button_sampling_setting.place(x=910, y=70, width=200, height=30)
        #--------------------
        # Create Button for Sync Operation Set
        #--------------------
        self.button_sync_setting = tk.Button(self.groupbox_sync, text='Sync Operation Set')
        self.button_sync_setting.place(x=910, y=120, width=200, height=30)
        #--------------------
        # Create Button for Sampling Start
        #--------------------
        self.button_sampling_start = tk.Button(self.groupbox_sync, text='Sampling Start')
        self.button_sampling_start.place(x=910, y=170, width=200, height=30)
        #--------------------
        # Create Button for Get Status
        #--------------------
        self.button_get_status = tk.Button(self.groupbox_sync, text='Get Status')
        self.button_get_status.place(x=910, y=220, width=200, height=30)
        #--------------------
        # Create Button for Sampling Stop
        #--------------------
        self.button_sampling_stop = tk.Button(self.groupbox_sync, text='Sampling Stop')
        self.button_sampling_stop.place(x=910, y=270, width=200, height=30)
        #--------------------
        # Create Button for Master Device Output Acquired Data to File
        #--------------------
        self.button_master_output_sampling_data = tk.Button(self.groupbox_sync, text='Master Device\nOutput Acquired Data to File...')
        self.button_master_output_sampling_data.place(x=910, y=320, width=200, height=30)
        #--------------------
        # Create Button for Slave Device Output Acquired Data to File
        #--------------------
        self.button_slave_output_sampling_data = tk.Button(self.groupbox_sync, text='Slave Device\nOutput Acquired Data to File...')
        self.button_slave_output_sampling_data.place(x=910, y=370, width=200, height=30)
        #----------------------------------------
        # Create LabelFrame for Exit process
        #----------------------------------------
        self.groupbox_exit = tk.LabelFrame(self.root, text="Exit")
        self.groupbox_exit.place(x=15, y=578, width=1126, height=60)
        #--------------------
        # Create Button for AioExit
        #--------------------
        self.button_aio_exit = tk.Button(self.groupbox_exit, text='AioExit')
        self.button_aio_exit.place(x=910, y=3, width=200, height=30)
        #----------------------------------------
        # Create LabelFrame for Return Code
        #----------------------------------------
        self.groupbox_ret = tk.LabelFrame(self.root, text="Return Code")
        self.groupbox_ret.place(x=15, y=648, width=912, height=75)
        #--------------------
        # Create LabelFrame for Master
        #--------------------
        self.groupbox_ret_master = tk.LabelFrame(self.groupbox_ret, text="Master")
        self.groupbox_ret_master.place(x=10, y=3, width=440, height=47)
        #--------------------
        # Create Entry for Return Code
        #--------------------
        self.textbox_master_return_string_var = tk.StringVar(self.groupbox_ret_master)
        tk.Entry(self.groupbox_ret_master, textvariable=self.textbox_master_return_string_var).place(x=10, y=3, width=415, height=19)
        #--------------------
        # Create LabelFrame for Master
        #--------------------
        self.groupbox_ret_slave = tk.LabelFrame(self.groupbox_ret, text="Salve")
        self.groupbox_ret_slave.place(x=460, y=3, width=440, height=47)
        #--------------------
        # Create Entry for Return Code
        #--------------------
        self.textbox_slave_return_string_var = tk.StringVar(self.groupbox_ret_slave)
        tk.Entry(self.groupbox_ret_slave, textvariable=self.textbox_slave_return_string_var).place(x=10, y=3, width=415, height=19)
        #--------------------
        # Create Button for Close
        #--------------------
        self.button_close = tk.Button(self.root, text='Close')
        self.button_close.place(x=927, y=725, width=200, height=30)

    #========================================
    # Function that sets the callback function for the UI controls
    #========================================
    def setup_commands(self,
                       command_aio_init,
                       command_aio_reset_device,
                       command_ai_setting,
                       command_sampling_setting,
                       command_sync_setting,
                       command_sampling_start,
                       command_get_status,
                       command_sampling_stop,
                       command_master_output_sampling_data,
                       command_slave_output_sampling_data,
                       command_aio_exit,
                       command_close):
        #----------------------------------------
        # Set the callback function for the [AioInit] button
        #----------------------------------------
        self.button_aio_init.configure(command=command_aio_init)
        #----------------------------------------
        # Set the callback function for the [AioResetDevice] button
        #----------------------------------------
        self.button_aio_reset_device.configure(command=command_aio_reset_device)
        #----------------------------------------
        # Set the callback function for the [Analog Input Set] button
        #----------------------------------------
        self.button_ai_setting.configure(command=command_ai_setting)
        #----------------------------------------
        # Set the callback function for the [Sampling Set] button
        #----------------------------------------
        self.button_sampling_setting.configure(command=command_sampling_setting)
        #----------------------------------------
        # Set the callback function for the [Sync Operation Set] button
        #----------------------------------------
        self.button_sync_setting.configure(command=command_sync_setting)
        #----------------------------------------
        # Set the callback function for the [Sampling Start] button
        #----------------------------------------
        self.button_sampling_start.configure(command=command_sampling_start)
        #----------------------------------------
        # Set the callback function for the [GetStatus] button
        #----------------------------------------
        self.button_get_status.configure(command=command_get_status)
        #----------------------------------------
        # Set the callback function for the [Sampling Stop] button
        #----------------------------------------
        self.button_sampling_stop.configure(command=command_sampling_stop)
        #----------------------------------------
        # Set the callback function for the [Master Device Output Acquired Data to File] button
        #----------------------------------------
        self.button_master_output_sampling_data.configure(command=command_master_output_sampling_data)
        #----------------------------------------
        # Set the callback function for the [Slave Device Output Acquired Data to File] button
        #----------------------------------------
        self.button_slave_output_sampling_data.configure(command=command_slave_output_sampling_data)
        #----------------------------------------
        # Set the callback function for the [AioExit] button
        #----------------------------------------
        self.button_aio_exit.configure(command=command_aio_exit)
        #----------------------------------------
        # Set the callback function for the [Close] button
        #----------------------------------------
        self.button_close.configure(command=command_close)

    #========================================
    # Display the error in a message box
    #========================================
    def show_error(self, caption, error):
        messagebox.showerror(caption, error, parent=self.root)

    #========================================
    # Run the main event loop
    #========================================
    def run(self):
        self.root.mainloop()