#================================================================
#================================================================
# C-WaveformGenerator
# MultiChannelWave
# Common function file
#                                                CONTEC Co., Ltd.
#================================================================
#================================================================

#========================================
# 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
#========================================
def isnum(str, base):
    try:
        if 16 == base:
            int(str, 16)
        elif 10 == base:
            int(str)
        else:
            float(str)
    except:
        return False
    return True

#========================================
# Function name    GetFrequencyUnitValueString
# Parameter        frequencyunit_value           Frequency unit setting value
# Details          Function to get frequency unit setting value string
# Return value     frequencyunit_value_string    Frequency unit setting 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

#========================================
# Function name    GetOscillationTypeString
# Parameter        oscillation_type           Oscillation type setting value
# Details          Function to get oscillation type setting value string
# Return value     oscillation_type_string    Oscillation type setting value string
#========================================
def GetOscillationTypeString(oscillation_type):
    if oscillation_type.value == 0:
        oscillation_type_string = "None"
    elif oscillation_type.value == 1:
        oscillation_type_string = "Auto burst"
    elif oscillation_type.value == 2:
        oscillation_type_string = "Trigger burst(rising edge)"
    elif oscillation_type.value == 3:
        oscillation_type_string = "Trigger burst(falling edge)"
    else:
        oscillation_type_string = "-"
    return oscillation_type_string

#========================================
# Function name    GetAmplitudeTypeString
# Parameter        amplitude_type           Amplitude type setting value
# Details          Function to get amplitude type setting value string
# Return value     amplitude_type_string    Amplitude type setting value string
#========================================
def GetAmplitudeTypeString(amplitude_type):
    if amplitude_type.value == 0:
        amplitude_type_string = "Amplitude"
    elif amplitude_type.value == 1:
        amplitude_type_string = "Vp-p"
    else:
        amplitude_type_string = "-"
    return amplitude_type_string

#========================================
# Function name    GetAmplitudeUnitString
# Parameter        amplitude_unit           Amplitude unit setting value
# Details          Function to get amplitude unit setting value string
# Return value     amplitude_unit_string    Amplitude unit setting value 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

#========================================
# Function name    GetSweepTypeString
# Parameter        wave_type            Wave type
# Parameter        sweep_type           Sweep type setting value
# Details          Function to get sweep type setting value string
# Return value     sweep_type_string    Sweep type setting value string
#========================================
def GetSweepTypeString(wave_type, sweep_type):
    #----------------------------------------
    # For Sinewave
    #----------------------------------------
    if wave_type.value == 0:
        if sweep_type.value == 0:
            sweep_type_string = "None"
        elif sweep_type.value == 1:
            sweep_type_string = "Frequency sweep"
        elif sweep_type.value == 2:
            sweep_type_string = "Amplitude sweep"
        elif sweep_type.value == 3:
            sweep_type_string = "DC offset sweep"
        else:
            sweep_type_string = "-"
    #----------------------------------------
    # For Square
    #----------------------------------------
    elif wave_type.value == 4:
        if sweep_type.value == 0:
            sweep_type_string = "None"
        elif sweep_type.value == 1:
            sweep_type_string = "Duty ratio sweep"
        else:
            sweep_type_string = "-"
    #----------------------------------------
    # For others
    #----------------------------------------
    else:
        if sweep_type.value == 0:
            sweep_type_string = "None"
        else:
            sweep_type_string = "-"
    return sweep_type_string
