#================================================================
#================================================================
# API-DIO(WDM)
# デジタル入力カウンタサンプル
# mainファイル
#                                                CONTEC Co., Ltd.
#================================================================
#================================================================
#----------------------------------------
# インポートモジュール
#----------------------------------------
import ctypes
import cdio
from DiCounterUI import DiCounterUI


#========================================
# DiCounter クラス
#========================================
class DiCounter:
    #========================================
    # 初期化関数
    #========================================
    def __init__(self):
        #----------------------------------------
        # マクロ定義
        #----------------------------------------
        self.MAX_COUNT_CH = 16                                               # 最大カウントチャネル数
        self.DISP_MAX_COUNT_CH = 8                                           # 最大表示カウントチャネル数
        #----------------------------------------
        # 変数
        #----------------------------------------
        self.id = ctypes.c_short()                                           # デバイスアクセス用ID
        self.count_ch_num = ctypes.c_short()                                 # デバイスのカウンタチャネル数
        self.combobox_count_edge = [None] * self.MAX_COUNT_CH                # カウントエッジコントロール格納用の配列
        self.textbox_compare_count_value_var = [None] * self.MAX_COUNT_CH    # 比較カウント値コントロール変数格納用の配列
        self.textbox_compare_count_value = [None] * self.MAX_COUNT_CH        # 比較カウント値コントロール格納用の配列
        self.textbox_preset_value_var = [None] * self.MAX_COUNT_CH           # プリセット値コントロール変数格納用の配列
        self.textbox_preset_value = [None] * self.MAX_COUNT_CH               # プリセット値コントロール格納用の配列
        self.textbox_count_value_var = [None] * self.MAX_COUNT_CH            # カウント値コントロール変数格納用の配列
        self.textbox_count_value = [None] * self.MAX_COUNT_CH                # カウント値コントロール格納用の配列
        self.textbox_count_status_var = [None] * self.MAX_COUNT_CH           # カウントステータスコントロール変数格納用の配列
        self.textbox_count_status = [None] * self.MAX_COUNT_CH               # カウントステータスコントロール格納用の配列
        #----------------------------------------
        # UIの作成を開始
        #----------------------------------------
        self.ui = DiCounterUI()
        #----------------------------------------
        # コンボボックスのインスタンス配列を設定する
        #----------------------------------------
        self.combobox_count_edge[0] = self.ui.combobox_count_edge0
        self.combobox_count_edge[1] = self.ui.combobox_count_edge1
        self.combobox_count_edge[2] = self.ui.combobox_count_edge2
        self.combobox_count_edge[3] = self.ui.combobox_count_edge3
        self.combobox_count_edge[4] = self.ui.combobox_count_edge4
        self.combobox_count_edge[5] = self.ui.combobox_count_edge5
        self.combobox_count_edge[6] = self.ui.combobox_count_edge6
        self.combobox_count_edge[7] = self.ui.combobox_count_edge7
        #----------------------------------------
        # テキストボックスの比較カウント値とインスタンス配列を設定する
        #----------------------------------------
        self.textbox_compare_count_value_var[0] = self.ui.textbox_compare_count_value0_var
        self.textbox_compare_count_value[0] = self.ui.textbox_compare_count_value0
        self.textbox_compare_count_value_var[1] = self.ui.textbox_compare_count_value1_var
        self.textbox_compare_count_value[1] = self.ui.textbox_compare_count_value1
        self.textbox_compare_count_value_var[2] = self.ui.textbox_compare_count_value2_var
        self.textbox_compare_count_value[2] = self.ui.textbox_compare_count_value2
        self.textbox_compare_count_value_var[3] = self.ui.textbox_compare_count_value3_var
        self.textbox_compare_count_value[3] = self.ui.textbox_compare_count_value3
        self.textbox_compare_count_value_var[4] = self.ui.textbox_compare_count_value4_var
        self.textbox_compare_count_value[4] = self.ui.textbox_compare_count_value4
        self.textbox_compare_count_value_var[5] = self.ui.textbox_compare_count_value5_var
        self.textbox_compare_count_value[5] = self.ui.textbox_compare_count_value5
        self.textbox_compare_count_value_var[6] = self.ui.textbox_compare_count_value6_var
        self.textbox_compare_count_value[6] = self.ui.textbox_compare_count_value6
        self.textbox_compare_count_value_var[7] = self.ui.textbox_compare_count_value7_var
        self.textbox_compare_count_value[7] = self.ui.textbox_compare_count_value7
        #----------------------------------------
        # テキストボックスのプリセット値とインスタンス配列を設定する
        #----------------------------------------
        self.textbox_preset_value_var[0] = self.ui.textbox_preset_value0_var
        self.textbox_preset_value[0] = self.ui.textbox_preset_value0
        self.textbox_preset_value_var[1] = self.ui.textbox_preset_value1_var
        self.textbox_preset_value[1] = self.ui.textbox_preset_value1
        self.textbox_preset_value_var[2] = self.ui.textbox_preset_value2_var
        self.textbox_preset_value[2] = self.ui.textbox_preset_value2
        self.textbox_preset_value_var[3] = self.ui.textbox_preset_value3_var
        self.textbox_preset_value[3] = self.ui.textbox_preset_value3
        self.textbox_preset_value_var[4] = self.ui.textbox_preset_value4_var
        self.textbox_preset_value[4] = self.ui.textbox_preset_value4
        self.textbox_preset_value_var[5] = self.ui.textbox_preset_value5_var
        self.textbox_preset_value[5] = self.ui.textbox_preset_value5
        self.textbox_preset_value_var[6] = self.ui.textbox_preset_value6_var
        self.textbox_preset_value[6] = self.ui.textbox_preset_value6
        self.textbox_preset_value_var[7] = self.ui.textbox_preset_value7_var
        self.textbox_preset_value[7] = self.ui.textbox_preset_value7
        #----------------------------------------
        # テキストボックスのカウント値とインスタンス配列を設定する
        #----------------------------------------
        self.textbox_count_value_var[0] = self.ui.textbox_count_value0_var
        self.textbox_count_value[0] = self.ui.textbox_count_value0
        self.textbox_count_value_var[1] = self.ui.textbox_count_value1_var
        self.textbox_count_value[1] = self.ui.textbox_count_value1
        self.textbox_count_value_var[2] = self.ui.textbox_count_value2_var
        self.textbox_count_value[2] = self.ui.textbox_count_value2
        self.textbox_count_value_var[3] = self.ui.textbox_count_value3_var
        self.textbox_count_value[3] = self.ui.textbox_count_value3
        self.textbox_count_value_var[4] = self.ui.textbox_count_value4_var
        self.textbox_count_value[4] = self.ui.textbox_count_value4
        self.textbox_count_value_var[5] = self.ui.textbox_count_value5_var
        self.textbox_count_value[5] = self.ui.textbox_count_value5
        self.textbox_count_value_var[6] = self.ui.textbox_count_value6_var
        self.textbox_count_value[6] = self.ui.textbox_count_value6
        self.textbox_count_value_var[7] = self.ui.textbox_count_value7_var
        self.textbox_count_value[7] = self.ui.textbox_count_value7
        #----------------------------------------
        # テキストボックスのカウントステータスとインスタンス配列を設定する
        #----------------------------------------
        self.textbox_count_status_var[0] = self.ui.textbox_count_status0_var
        self.textbox_count_status[0] = self.ui.textbox_count_status0
        self.textbox_count_status_var[1] = self.ui.textbox_count_status1_var
        self.textbox_count_status[1] = self.ui.textbox_count_status1
        self.textbox_count_status_var[2] = self.ui.textbox_count_status2_var
        self.textbox_count_status[2] = self.ui.textbox_count_status2
        self.textbox_count_status_var[3] = self.ui.textbox_count_status3_var
        self.textbox_count_status[3] = self.ui.textbox_count_status3
        self.textbox_count_status_var[4] = self.ui.textbox_count_status4_var
        self.textbox_count_status[4] = self.ui.textbox_count_status4
        self.textbox_count_status_var[5] = self.ui.textbox_count_status5_var
        self.textbox_count_status[5] = self.ui.textbox_count_status5
        self.textbox_count_status_var[6] = self.ui.textbox_count_status6_var
        self.textbox_count_status[6] = self.ui.textbox_count_status6
        self.textbox_count_status_var[7] = self.ui.textbox_count_status7_var
        self.textbox_count_status[7] = self.ui.textbox_count_status7
        #----------------------------------------
        # UIコントロールのコールバック関数を設定
        #----------------------------------------
        self.ui.setup_commands(
            command_dio_init=self.OnClickedButtonDioInit,
            command_dio_set_count_edge=self.OnClickedButtonDioSetCountEdge,
            command_dio_set_count_match_value=self.OnClickedButtonDioSetCountMatchValue,
            command_dio_start_count=self.OnClickedButtonDioStartCount,
            command_dio_read_count=self.OnClickedButtonDioReadCount,
            command_dio_get_count_status=self.OnClickedButtonDioGetCountStatus,
            command_dio_count_preset=self.OnClickedButtonDioCountPreset,
            command_dio_stop_count=self.OnClickedButtonDioStopCount,
            command_dio_exit=self.OnClickedButtonDioExit,
            command_exit=self.OnClickedButtonExit
        )

    #========================================
    # 関数名    isnum
    # 引数      str     文字列
    # 引数      base    ベース
    # 詳細      文字列を数値に変換できるかどうか確認する関数
    # 戻り値    True : 変換できる
    #           False : 変換できない
    #========================================
    @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

    #========================================
    # 関数名    OnClickedButtonDioInit
    # 引数      なし
    # 詳細      DioInitボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioInit(self):
        error_string = ctypes.create_string_buffer(256)    # エラーコード文字列
        lret = ctypes.c_long()                             # 戻り値取得用

        #----------------------------------------
        # 画面からデバイス名を取得する
        #----------------------------------------
        device_name = self.ui.textbox_device_name_var.get()
        #----------------------------------------
        # 初期化処理を行ない、IDを取得する
        #----------------------------------------
        lret.value = cdio.DioInit(device_name.encode(), ctypes.byref(self.id))
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioInit = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)
        if lret.value != cdio.DIO_ERR_SUCCESS:
            return
        #----------------------------------------
        # チャネル数取得
        #----------------------------------------
        lret.value = cdio.DioGetMaxCountChannels(self.id, ctypes.byref(self.count_ch_num))
        if lret.value != cdio.DIO_ERR_SUCCESS:
            cdio.DioGetErrorString(lret, error_string)
            text_buf = f"DioGetMaxCountChannels = {lret.value} : {error_string.value.decode('sjis')}"
            self.ui.textbox_return_string_var.set(text_buf)
            return
        #----------------------------------------
        # デバイスに存在しないチャネル用コントロールを無効化
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value, self.DISP_MAX_COUNT_CH):
            #----------------------------------------
            # カウントエッジコントロール
            #----------------------------------------
            self.combobox_count_edge[ch_no].config(state = 'disabled')
            #----------------------------------------
            # 比較カウント値コントロール
            #----------------------------------------
            self.textbox_compare_count_value[ch_no].config(state = 'disabled')
            #----------------------------------------
            # プリセット値コントロール
            #----------------------------------------
            self.textbox_preset_value[ch_no].config(state = 'disabled')
            #----------------------------------------
            # カウント値コントロール
            #----------------------------------------
            self.textbox_count_value[ch_no].config(state = 'disabled')
            #----------------------------------------
            # カウントステータスコントロール
            #----------------------------------------
            self.textbox_count_status[ch_no].config(state = 'disabled')
        #----------------------------------------
        # カウントチャネル数を表示できる最大チャネル数に補正
        #----------------------------------------
        if self.DISP_MAX_COUNT_CH < self.count_ch_num.value:
            self.count_ch_num.value = self.DISP_MAX_COUNT_CH

    #========================================
    # 関数名    OnClickedButtonDioSetCountEdge
    # 引数      なし
    # 詳細      DioSetCountEdgeボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioSetCountEdge(self):
        error_string = ctypes.create_string_buffer(256)         # エラーコード文字列
        lret = ctypes.c_long()                                  # 戻り値取得用
        ch_no_array = (ctypes.c_short * self.MAX_COUNT_CH)()    # チャネル番号格納領域のポインタ
        count_edge = (ctypes.c_short * self.MAX_COUNT_CH)()     # カウントエッジ格納領域のポインタ

        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # チャネル番号格納
            #----------------------------------------
            ch_no_array[ch_no] = ch_no
            #----------------------------------------
            # カウントエッジ指定値取得
            #----------------------------------------
            if self.combobox_count_edge[ch_no].get() == '立上り':
                count_edge[ch_no] = cdio.DIO_COUNT_EDGE_UP
            elif self.combobox_count_edge[ch_no].get() == '立下り':
                count_edge[ch_no] = cdio.DIO_COUNT_EDGE_DOWN
            else:
                count_edge[ch_no] = cdio.DIO_COUNT_EDGE_UP | cdio.DIO_COUNT_EDGE_DOWN
        #----------------------------------------
        # カウントエッジ設定
        #----------------------------------------
        lret.value = cdio.DioSetCountEdge(self.id, ch_no_array, self.count_ch_num, count_edge)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioSetCountEdge = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # 関数名    OnClickedButtonDioSetCountMatchValue
    # 引数      なし
    # 詳細      DioSetCountMatchValueボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioSetCountMatchValue(self):
        error_string = ctypes.create_string_buffer(256)                     # エラーコード文字列
        lret = ctypes.c_long()                                              # 戻り値取得用
        ch_no_array = (ctypes.c_short * self.MAX_COUNT_CH)()                # チャネル番号格納領域のポインタ
        count_match_register_no = (ctypes.c_short * self.MAX_COUNT_CH)()    # 比較レジスタ番号格納領域のポインタ
        count_match_value = (ctypes.c_ulong * self.MAX_COUNT_CH)()          # 比較カウント値格納領域のポインタ

        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # チャネル番号格納
            #----------------------------------------
            ch_no_array[ch_no] = ch_no
            #----------------------------------------
            # 比較レジスタ番号格納
            #----------------------------------------
            count_match_register_no[ch_no] = 0
            #----------------------------------------
            # 比較カウント指定値取得
            #----------------------------------------
            buf = self.textbox_compare_count_value_var[ch_no].get()
            #----------------------------------------
            # 入力値が数値かどうかをチェック
            #----------------------------------------
            if False == self.isnum(buf, 10):
                self.ui.show_error("Error", "入力値が無効です。")
                return
            else:
                count_match_value[ch_no] = ctypes.c_ulong(int(buf, 10))
        #----------------------------------------
        # 比較レジスタ設定
        #----------------------------------------
        lret.value = cdio.DioSetCountMatchValue(self.id, ch_no_array, self.count_ch_num, count_match_register_no, count_match_value)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioSetCountMatchValue = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # 関数名    OnClickedButtonDioStartCount
    # 引数      なし
    # 詳細      DioStartCountボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioStartCount(self):
        error_string = ctypes.create_string_buffer(256)         # エラーコード文字列
        lret = ctypes.c_long()                                  # 戻り値取得用
        ch_no_array = (ctypes.c_short * self.MAX_COUNT_CH)()    # チャネル番号格納領域のポインタ

        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # チャネル番号格納
            #----------------------------------------
            ch_no_array[ch_no] = ch_no
        #----------------------------------------
        # カウントスタート
        #----------------------------------------
        lret.value = cdio.DioStartCount(self.id, ch_no_array, self.count_ch_num)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioStartCount = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # 関数名    OnClickedButtonDioReadCount
    # 引数      なし
    # 詳細      DioReadCountボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioReadCount(self):
        error_string = ctypes.create_string_buffer(256)         # エラーコード文字列
        lret = ctypes.c_long()                                  # 戻り値取得用
        ch_no_array = (ctypes.c_short * self.MAX_COUNT_CH)()    # チャネル番号格納領域のポインタ
        count = (ctypes.c_ulong * self.MAX_COUNT_CH)()          # カウント値格納領域のポインタ

        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # チャネル番号格納
            #----------------------------------------
            ch_no_array[ch_no] = ch_no
        #----------------------------------------
        # カウント値リード
        #----------------------------------------
        lret.value = cdio.DioReadCount(self.id, ch_no_array, self.count_ch_num, count)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioReadCount = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)
        if lret.value != cdio.DIO_ERR_SUCCESS:
            return
        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # カウント値表示更新
            #----------------------------------------
            text_buf = f"{count[ch_no]}"
            self.textbox_count_value_var[ch_no].set(text_buf)

    #========================================
    # 関数名    OnClickedButtonDioGetCountStatus
    # 引数      なし
    # 詳細      DioGetCountStatusボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioGetCountStatus(self):
        error_string = ctypes.create_string_buffer(256)          # エラーコード文字列
        lret = ctypes.c_long()                                   # 戻り値取得用
        ch_no_array = (ctypes.c_short * self.MAX_COUNT_CH)()     # チャネル番号格納領域のポインタ
        count_status = (ctypes.c_ulong * self.MAX_COUNT_CH)()    # カウントステータス格納領域のポインタ

        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # チャネル番号格納
            #----------------------------------------
            ch_no_array[ch_no] = ch_no
        #----------------------------------------
        # カウントステータスリード
        #----------------------------------------
        lret.value = cdio.DioGetCountStatus(self.id, ch_no_array, self.count_ch_num, count_status)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioGetCountStatus = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)
        if lret.value != cdio.DIO_ERR_SUCCESS:
            return
        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # カウントステータス表示更新
            #----------------------------------------
            text_buf = f"{count_status[ch_no]:x}"
            self.textbox_count_status_var[ch_no].set(text_buf)

    #========================================
    # 関数名    OnClickedButtonDioCountPreset
    # 引数      なし
    # 詳細      DioCountPresetボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioCountPreset(self):
        error_string = ctypes.create_string_buffer(256)          # エラーコード文字列
        lret = ctypes.c_long()                                   # 戻り値取得用
        ch_no_array = (ctypes.c_short * self.MAX_COUNT_CH)()     # チャネル番号格納領域のポインタ
        preset_count = (ctypes.c_ulong * self.MAX_COUNT_CH)()    # プリセット値格納領域のポインタ

        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # チャネル番号格納
            #----------------------------------------
            ch_no_array[ch_no] = ch_no
            #----------------------------------------
            # プリセットカウント指定値取得
            #----------------------------------------
            buf = self.textbox_preset_value_var[ch_no].get()
            #----------------------------------------
            # 入力値が数値かどうかをチェック
            #----------------------------------------
            if False == self.isnum(buf, 10):
                self.ui.show_error("Error", "入力値が無効です。")
                return
            else:
                preset_count[ch_no] = ctypes.c_ulong(int(buf, 10))
        #----------------------------------------
        # カウント値をプリセット
        #----------------------------------------
        lret.value = cdio.DioCountPreset(self.id, ch_no_array, self.count_ch_num, preset_count)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioCountPreset = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # 関数名    OnClickedButtonDioStopCount
    # 引数      なし
    # 詳細      DioStopCountボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioStopCount(self):
        error_string = ctypes.create_string_buffer(256)         # エラーコード文字列
        lret = ctypes.c_long()                                  # 戻り値取得用
        ch_no_array = (ctypes.c_short * self.MAX_COUNT_CH)()    # チャネル番号格納領域のポインタ

        #----------------------------------------
        # 各チャネルごとに
        #----------------------------------------
        for ch_no in range(self.count_ch_num.value):
            #----------------------------------------
            # チャネル番号格納
            #----------------------------------------
            ch_no_array[ch_no] = ch_no
        #----------------------------------------
        # カウントストップ
        #----------------------------------------
        lret.value = cdio.DioStopCount(self.id, ch_no_array, self.count_ch_num)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioStopCount = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # 関数名    OnClickedButtonDioExit
    # 引数      なし
    # 詳細      DioExitボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonDioExit(self):
        error_string = ctypes.create_string_buffer(256)    # エラーコード文字列
        lret = ctypes.c_long()                             # 戻り値取得用

        #----------------------------------------
        # 終了処理を行う
        #----------------------------------------
        lret.value = cdio.DioExit(self.id)
        #----------------------------------------
        # エラー処理
        #----------------------------------------
        cdio.DioGetErrorString(lret, error_string)
        text_buf = f"DioExit = {lret.value} : {error_string.value.decode('sjis')}"
        self.ui.textbox_return_string_var.set(text_buf)

    #========================================
    # 関数名    OnClickedButtonExit
    # 引数      なし
    # 詳細      Exitボタンクリックイベント関数
    # 戻り値    なし
    #========================================
    def OnClickedButtonExit(self):
        #----------------------------------------
        # 終了処理を行う
        #----------------------------------------
        cdio.DioExit(self.id)
        #----------------------------------------
        # ウィンドウを終了する
        #----------------------------------------
        self.ui.root.destroy()

    #========================================
    # 関数名    run
    # 引数      なし
    # 詳細      アプリケーションを実行する関数
    # 戻り値    なし
    #========================================
    def run(self):
        self.ui.run()


#========================================
# main関数
#========================================
def main():
    #----------------------------------------
    # DiCounterの作成と実行
    #----------------------------------------
    instance = DiCounter()
    instance.run()

#========================================
# main関数呼び出し
#========================================
if __name__ == "__main__":
    main()