def calc_Ctot():
    if can_calc_Ctot():
        global Ctot
        Ctot = C1 * C2 / (C1 + C2)
        setCapacitanceData("Ctot", Ctot)
    else:
        scpi("DISP:ERROR \"Enter C1 and C2\"")
def inputCapacitance(name, capacitance):
    value = scpi('DISP:INPUT? "' + name + '",NUMBER,FARAD,-1E15,1E15,' +
                 (str(capacitance) if capacitance != None else "1E-6"))
    if value != None:
        capacitance = float(value)
        scpi('DISP:DIALog:DATA "' + name + '",FLOAT,FARAD,' + str(capacitance))
    return capacitance
def calc_C1():
    if can_calc_C1():
        global C1
        C1 = C2 * Ctot / (C2 - Ctot)
        setCapacitanceData("C1", C1)
    else:
        scpi("DISP:ERROR \"Enter C2 and Ctot\"")
def calc_C2():
    if can_calc_C2():
        global C2
        C2 = C1 * Ctot / (C1 - Ctot)
        setCapacitanceData("C2", C2)
    else:
        scpi("DISP:ERROR \"Enter C1 and Ctot\"")
def calc_Rtot():
    if can_calc_Rtot():
        global Rtot
        Rtot = R1 * R2 / (R1 + R2)
        setResistanceData("Rtot", Rtot)
    else:
        scpi("DISP:ERROR \"Enter R1 and R2\"")
def calc_R2():
    if can_calc_R2():
        global R2
        R2 = R1 * Rtot / (R1 - Rtot)
        setResistanceData("R2", R2)
    else:
        scpi("DISP:ERROR \"Enter R1 and Rtot\"")
def calc_R1():
    if can_calc_R1():
        global R1
        R1 = R2 * Rtot / (R2 - Rtot)
        setResistanceData("R1", R1)
    else:
        scpi("DISP:ERROR \"Enter R2 and Rtot\"")
def select_type():
    global circuitType
    value = scpi('DISP:SELECT? ' + str(circuitType + 1) +
                 ',"R or L in parallel","C in series"')
    if value != None and value != 0:
        circuitType = value - 1
        scpi("DISP:DIALog:DATA \"type\",INTEGER," + str(circuitType))
示例#9
0
def select_device_type():
    global deviceType
    value = scpi('DISP:SELECT? ' + str(deviceType + 1) +
                 ',"NPN BJT","PNP BJT","N-Ch MOSFET","P-Ch MOSFET"')
    if value != None and value != 0:
        deviceType = value - 1
        scpi("DISP:DIALog:DATA \"device_type\",INTEGER," + str(deviceType))
def input_voltage():
    global voltage, max_voltage
    value = scpi('DISP:INPUT? "",NUMBER,VOLT,0.0,' + str(max_voltage) + '.0,' + str(voltage))
    if value != None:
        voltage = float(value)
        scpi('DISP:DIALog:DATA "voltage",FLOAT,VOLT,' + str(voltage))
        scpi('DISP:DIALog:DATA "can_set_voltage",INT,1')
示例#11
0
def input_device_name():
    global deviceName
    value = scpi('disp:input? "Device name",TEXT,1,20,"' + (deviceName if deviceName != None else "") + '"')
    if value != None:
        deviceName = value
        scpi('DISP:DIALog:DATA "device_name",STRING,"' + deviceName + '"')
        scpi('DISP:DIALog:DATA "can_start",INTEGER,1')
def input_diode_name():
    global diode_name
    value = scpi('disp:input? "Diode name",TEXT,1,20,"' + (diode_name if diode_name != None else "") + '"')
    if value != None:
        diode_name = value
        scpi('DISP:DIALog:DATA "diode_name",STRING,"' + diode_name + '"')
        update_can_start()
def inputVoltage(name, voltage):
    value = scpi('DISP:INPUT? "' + name + '",NUMBER,VOLT,-1E6,1E6,' +
                 (str(voltage) if voltage != None else "1"))
    if value != None:
        voltage = float(value)
        scpi('DISP:DIALog:DATA "' + name + '",FLOAT,VOLT,' + str(voltage))
    return voltage
def inputResistance(name, resistance):
    value = scpi('DISP:INPUT? "' + name + '",NUMBER,OHM,-1E15,1E15,' +
                 (str(resistance) if resistance != None else "1E3"))
    if value != None:
        resistance = float(value)
        scpi('DISP:DIALog:DATA "' + name + '",FLOAT,OHM,' + str(resistance))
    return resistance
def main():
    global charge_voltage
    global charge_current
    global termination_current
    global datalog_filename

    calc = calculator()
    charge = charger()

    scpi('DISP:DIAL:OPEN "/Scripts/CC-CV Battery Charge.res"')

    try:
        while True:
            display_setup_pane()
            action = scpi('DISP:DIALog:ACTIon?')
            if action == 'input_charge_current':
                charge_current = input_float('AMPER', 0, 5, charge_current)
            elif action == 'input_charge_voltage':
                charge_voltage = input_float('VOLT', 0, 40, charge_voltage)
            elif action == 'input_termination_current':
                termination_current = input_float('AMPER', 0, 5, charge_current)
            elif action == 'input_filename':
                datalog_filename = input_text(2, 30, datalog_filename)
            elif action == 'view_calculator':
                calc.loop()
            elif action == 'start':
                charge.loop()
            elif action == 'close' or action == 0:
                break
        
    finally:
        scpi('DISP:DIAL:CLOS')
示例#16
0
def input_charge_current():
    global charge_current
    value = scpi('DISP:INPUT? "Charge current",NUMBER,AMPER,0.0,80.0,' +
                 str(charge_current))
    if value != None:
        charge_current = float(value)
        scpi('DISP:DIALog:DATA "charge_current", FLOAT, AMPER,' +
             str(charge_current))
示例#17
0
def input_reform_time():
    global reform_time
    value = scpi('DISP:INPUT? "Reform duration",NUMBER,SECOND,10.0,7200.0,' +
                 str(reform_time))
    if value != None:
        reform_time = float(value)
        scpi('DISP:DIALog:DATA "reform_time", FLOAT, SECOND,' +
             str(reform_time))
def select_type():
    global opAmpType
    value = scpi(
        'DISP:SELECT? ' + str(opAmpType + 1) +
        ',"Non-inverting","Inverting","Diff. simplified","Differential"')
    if value != None and value != 0:
        opAmpType = value - 1
        scpi("DISP:DIALog:DATA \"type\",INTEGER," + str(opAmpType))
示例#19
0
def input_cap_max_volt():
    global cap_max_volt
    value = scpi('DISP:INPUT? "Max Cap Voltage",NUMBER,VOLT,1.0,' +
                 str(module_max_volt) + ',' + str(cap_max_volt))
    if value != None:
        cap_max_volt = float(value)
        scpi('DISP:DIALog:DATA "cap_max_volt", FLOAT, VOLT,' +
             str(cap_max_volt))
示例#20
0
def update_can_init(slot_index):
    if slots[slot_index]["model"] != slots_orig[slot_index]["model"] or slots[
            slot_index]["version_r"] != slots_orig[slot_index][
                "version_r"] or slots[slot_index]["version_b"] != slots_orig[
                    slot_index]["version_b"]:
        scpi("DISP:DIALog:DATA \"slot" + str(slot_index + 1) +
             "_can_init\",INT,1")
    else:
        scpi("DISP:DIALog:DATA \"slot" + str(slot_index + 1) +
             "_can_init\",INT,0")
    def done_loop(self):
        while True:
            self.display_done_pane()

            action = scpi('DISP:DIALog:ACTIon?')
            if action == 'start':
                break
            elif action == 'view_datalog':
                scpi('DISP:WINDOW:DLOG')
            elif action == 'close' or action == 0:
                # TODO this wont actually exit...
                break
示例#22
0
def inputAmperage(name, amperage, min, max):
    value = scpi('DISP:INPUT? "' + name + '",NUMBER,AMPER,' + str(min) + ',' +
                 str(max) + ',' + str(amperage))
    if value != None:
        amperage = float(value)
        updateData(name, 'AMPER', amperage)
    return amperage
示例#23
0
def select_version_b(slot_index):
    value = scpi('DISP:INPUT? "",INT,0,255,' +
                 str(slots[slot_index]["version_b"]))
    if value != None:
        slots[slot_index]["version_b"] = value
        update_model_and_version(slot_index)
        update_can_init(slot_index)
示例#24
0
def inputVoltage(name, voltage, min, max):
    value = scpi('DISP:INPUT? "' + name + '",NUMBER,VOLT,' + str(min) + ',' +
                 str(max) + ',' + str(voltage))
    if value != None:
        voltage = float(value)
        updateData(name, 'VOLT', voltage)
    return voltage
示例#25
0
def discharge_cap():
    global channel
    setU(channel, 0.0)
    setI(channel, 0.1)  # Must be >= 10mA otherwise Downprogrammer is off.
    scpi("DISP:WINDOW:TEXT \"Discharging...\"")
    scpi("OUTP 1")
    sleep_ms(1000)
    while getU(channel) > 0.5:
        sleep_ms(100)
    scpi("DISP:WINDOW:TEXT:CLEAR")
    setI(channel, 0.1)
    scpi("OUTP 0")
示例#26
0
def select_model(slot_index):
    model_names = ",".join(map(lambda x: '"' + x["name"] + '"', MODELS))
    value = scpi('DISP:SELECT? ' + str(slots[slot_index]["model"] + 1) + ',' +
                 model_names)
    if value != None and value != 0:
        value = value - 1
        slots[slot_index]["model"] = value
        slots[slot_index]["version_r"] = MODELS[value]["r"]
        slots[slot_index]["version_b"] = MODELS[value]["b"]
        update_model_and_version(slot_index)
        update_can_init(slot_index)
示例#27
0
def get_slots_info():
    num_channels = scpi("SYSTem:CHANnel?")
    for channel_index in range(num_channels):
        slot_index = scpi("SYST:CHAN:SLOT? CH" + str(channel_index + 1)) - 1

        model = scpi("SYST:CHAN:MOD? CH" + str(channel_index + 1))
        for i in range(len(MODELS)):
            if MODELS[i]["name"] == model:
                slots[slot_index]["model"] = i

                version = scpi("SYST:CHAN:VERS? CH" + str(channel_index + 1))
                i = version.index('R')
                j = version.index('B')
                slots[slot_index]["version_r"] = int(version[i + 1:j])
                slots[slot_index]["version_b"] = int(version[j + 1:])

                break
        else:
            slots[slot_index]["model"] = MODEL_NONE
            slots[slot_index]["version_r"] = 0
            slots[slot_index]["version_b"] = 0

    global slots_orig
    slots_orig = [
        {
            "model": slots[0]["model"],
            "version_r": slots[0]["version_r"],
            "version_b": slots[0]["version_b"]
        },
        {
            "model": slots[1]["model"],
            "version_r": slots[1]["version_r"],
            "version_b": slots[1]["version_b"]
        },
        {
            "model": slots[2]["model"],
            "version_r": slots[2]["version_r"],
            "version_b": slots[2]["version_b"]
        },
    ]
示例#28
0
def update_model_and_version(slot_index):
    scpi("DISP:DIALog:DATA \"slot" + str(slot_index + 1) + "_model\",STR,\"" +
         MODELS[slots[slot_index]["model"]]["name"] + "\"")
    scpi("DISP:DIALog:DATA \"slot" + str(slot_index + 1) +
         "_version_r\",INT," + str(slots[slot_index]["version_r"]))
    scpi("DISP:DIALog:DATA \"slot" + str(slot_index + 1) +
         "_version_b\",INT," + str(slots[slot_index]["version_b"]))
def get_slots_info():
    for slot_index in range(3):
        model = scpi("SYST:SLOT:MOD? " + str(slot_index + 1))
        for i in range(len(MODELS)):
            if MODELS[i]["name"] == model:
                slots[slot_index]["model"] = i

                version = scpi("SYST:SLOT:VERS? " + str(slot_index + 1))
                i = version.index('R')
                j = version.index('B')
                slots[slot_index]["version_r"] = int(version[i + 1:j])
                slots[slot_index]["version_b"] = int(version[j + 1:])

                break
        else:
            slots[slot_index]["model"] = MODEL_NONE
            slots[slot_index]["version_r"] = 0
            slots[slot_index]["version_b"] = 0

    global slots_orig
    slots_orig = [
        {
            "model": slots[0]["model"],
            "version_r": slots[0]["version_r"],
            "version_b": slots[0]["version_b"]
        },
        {
            "model": slots[1]["model"],
            "version_r": slots[1]["version_r"],
            "version_b": slots[1]["version_b"]
        },
        {
            "model": slots[2]["model"],
            "version_r": slots[2]["version_r"],
            "version_b": slots[2]["version_b"]
        },
    ]
def slot_init(slot_index):
    try:
        scpi("INST:MEMO " + str(slot_index + 1) + ",0,2," +
             str(MODELS[slots[slot_index]["model"]]["id"]))
        scpi("INST:MEMO " + str(slot_index + 1) + ",2,2,#H" +
             to_hex_str(slots[slot_index]["version_r"]) +
             to_hex_str(slots[slot_index]["version_b"]))
        scpi("INST:MEMO " + str(slot_index + 1) +
             ",4,2,#HFFFF")  # firmware is not installed
    except:
        error("Failed to write to module EEPROM.")
        return

    slots_orig[slot_index]["model"] = slots[slot_index]["model"]
    slots_orig[slot_index]["version_r"] = slots[slot_index]["version_r"]
    slots_orig[slot_index]["version_b"] = slots[slot_index]["version_b"]

    update_can_init(slot_index)

    global can_restart
    if not can_restart:
        can_restart = 1
        scpi("DISP:DIALog:DATA \"can_restart\",INT,1")