#================================================================
#================================================================
# C-WaveformGenerator
# 複数チャネル波形出力サンプル
# コモンファンクションファイル
#                                                CONTEC Co., Ltd.
#================================================================
#================================================================

#========================================
# 関数名    isnum
# 引数      str     文字列
# 引数      base    ベース
# 詳細      文字列を数値に変換できるかどうか確認する関数
# 戻り値    True：変換できる
#           False：変換できない
#========================================
def isnum(str, base):
    try:
        if 16 == base:
            int(str, 16)
        elif 10 == base:
            int(str)
        else:
            float(str)
    except:
        return False
    return True

#========================================
# 関数名    GetFrequencyUnitValueString
# 引数      frequencyunit_value           周波数単位の設定値
# 詳細      周波数単位の設定値から文字列を取得する関数になります
# 戻り値    frequencyunit_value_string    周波数単位の設定値にあった文字列
#========================================
def GetFrequencyUnitValueString(frequencyunit_value):
    if frequencyunit_value.value == 0:
        frequencyunit_value_string = "Hz"
    elif frequencyunit_value.value == 1:
        frequencyunit_value_string = "KHz"
    elif frequencyunit_value.value == 2:
        frequencyunit_value_string = "sec"
    elif frequencyunit_value.value == 3:
        frequencyunit_value_string = "msec"
    else:
        frequencyunit_value_string = "-"
    return frequencyunit_value_string

#========================================
# 関数名    GetOscillationTypeString
# 引数      oscillation_type           発振タイプの設定値
# 詳細      発振タイプの設定値から文字列を取得する関数になります
# 戻り値    oscillation_type_string    発振タイプの設定値にあった文字列
#========================================
def GetOscillationTypeString(oscillation_type):
    if oscillation_type.value == 0:
        oscillation_type_string = "なし"
    elif oscillation_type.value == 1:
        oscillation_type_string = "オートバースト"
    elif oscillation_type.value == 2:
        oscillation_type_string = "トリガバースト（立ち上がり）"
    elif oscillation_type.value == 3:
        oscillation_type_string = "トリガバースト（立ち下がり）"
    else:
        oscillation_type_string = "-"
    return oscillation_type_string

#========================================
# 関数名    GetAmplitudeTypeString
# 引数      amplitude_type           振幅タイプの設定値
# 詳細      振幅タイプの設定値から文字列を取得する関数になります
# 戻り値    amplitude_type_string    振幅タイプの設定値にあった文字列
#========================================
def GetAmplitudeTypeString(amplitude_type):
    if amplitude_type.value == 0:
        amplitude_type_string = "振幅"
    elif amplitude_type.value == 1:
        amplitude_type_string = "Vp-p"
    else:
        amplitude_type_string = "-"
    return amplitude_type_string

#========================================
# 関数名    GetAmplitudeUnitString
# 引数      amplitude_unit           振幅単位の設定値
# 詳細      振幅単位の設定値から文字列を取得する関数になります
# 戻り値    amplitude_unit_string    振幅単位の設定値にあった文字列
#========================================
def GetAmplitudeUnitString(amplitude_unit):
    if amplitude_unit.value == 0:
        amplitude_unit_string = "V or mA"
    elif amplitude_unit.value == 1:
        amplitude_unit_string = "LSB"
    else:
        amplitude_unit_string = "-"
    return amplitude_unit_string

#========================================
# 関数名    GetSweepTypeString
# 引数      wave_type            波形タイプ
# 引数      sweep_type           スイープタイプの設定値
# 詳細      スイープタイプの設定値から文字列を取得する関数になります
# 戻り値    sweep_type_string    スイープタイプの設定値にあった文字列
#========================================
def GetSweepTypeString(wave_type, sweep_type):
    #----------------------------------------
    # サイン波の場合
    #----------------------------------------
    if wave_type.value == 0:
        if sweep_type.value == 0:
            sweep_type_string = "なし"
        elif sweep_type.value == 1:
            sweep_type_string = "周波数スイープ"
        elif sweep_type.value == 2:
            sweep_type_string = "振幅スイープ"
        elif sweep_type.value == 3:
            sweep_type_string = "DCオフセットスイープ"
        else:
            sweep_type_string = "-"
    #----------------------------------------
    # 矩形波の場合
    #----------------------------------------
    elif wave_type.value == 4:
        if sweep_type.value == 0:
            sweep_type_string = "なし"
        elif sweep_type.value == 1:
            sweep_type_string = "デューティスイープ"
        else:
            sweep_type_string = "-"
    #----------------------------------------
    # その他の場合
    #----------------------------------------
    else:
        if sweep_type.value == 0:
            sweep_type_string = "なし"
        else:
            sweep_type_string = "-"
    return sweep_type_string
