Code:
#scriptMenu Discharge
#logcmds 0
="Battery discharging with DL24 / PX100"
=var endVoltage=0
=var testCurrent=1
=var endVoltageLoad = endVoltage-0.05
=var stepTime=1
=var Voltage
=var startCurrent
=var stopByLoad=2
=var addCapacity=1;
=var addEnergy=1;
=var reset=1
=var Timelimit=0
=var timelimit=72000
=var Timecheck=0
=var load=getDevice("Load")
="Loaddevice = " + load
=setOn(load,0);
=setCurrent(load,testCurrent)
; --------------------------------------------------------------
#popupInit "Battery discharge DL24 / PX100"
#popupNumber "Minimum voltage" endVoltage 0.5 60 "The fully discharged voltage for the battery"
#popupNumber "Discharge current" testCurrent 0.1 5 "Current used for discharge"
#popupNumber "Max. Discharge time" Timelimit 0 72000 "Max. Discharge time in Seconds"
#popupCheckbox "Add calculated capacity (Ah)" addCapacity "Add Math.Capacity expression"
#popupCheckbox "Add calculated energy (Wh)" addEnergy "Add Math.Energy expression"
#popupCheckbox "Time limited discharge" Timecheck "Activate Time limit"
#popupCheckbox "Reset Load" reset "Reset Load before start"
#popupButtons Start ok Abort
#popupShow
; --------------------------------------------------------------
#if !ok
="Test aborted"
#return
#endif
#math
#if addCapacity
#math Capacity Ah SumTimeHour 0 (nameCurrent(load))
#endif
#if addEnergy
#math Energy Wh SumTimeHour 0 (nameCurrent(load)+"*"+nameVoltage(load))
#endif
#if Timecheck
=timelimit=Timelimit
="Max. Discharge time = " +Timelimit + " Seconds"
#endif
#if reset
(load):reset
#endif
#delay 1
=endVoltageLoad=(endVoltage-0.05)
#delay 0.5
=setCurrent(load,testCurrent)
#delay 0.5
="Discharge with "+testCurrent+"A to "+endVoltage+"V";
=setVoltage(load,endVoltageLoad)
#delay 0.5
=setCurrent(load,testCurrent)
#delay 0.5
#delay 0.5
=setOn(load,1);
#delay 0.5
#log (stepTime)
#ChartCurves (load+".Voltage") (load+".Current) (load+".Temperature) RD6012.Voltage RD6012.Current
#haslogged
#haslogged
="Start Voltage = "+tableCalcMax((load+".Voltage"),tableRows()-2)+" Volt"
="Discharge Current = "+tableCalcMax((load+".Current"),tableRows()-2)+" Ampere"
=startCurrent=tableCalcMax((load+".Current"),tableRows()-2)
#haslogged
#haslogged
#haslogged
#haslogged
#if Timecheck then {
#wait (tableCalcMax((load+".Voltage"),tableRows()-6)>endVoltage) and (tableCalcMax((load+".Current"),tableRows()-6)>(0.5*testCurrent)) and timeendVoltage) and (tableCalcMax((load+".Current"),tableRows()-6)>(0.5*testCurrent))
}
#endif
=setOn(load,0);
#log 0
#if (tableCalcMax((load+".Current"),tableRows()-6)<(0.5*testCurrent)) then {
=stopByLoad=1
}
#endif
#log 0
#if startCurrent<0.1 then
="Discharge not started, Input Voltage to low"
#else
#endif
#if stopByLoad<2 then {
="Discharge stopped by Load"
}
#endif
#if stopByLoad>1 then {
="Discharge stopped by TestController"
}
#endif
="End Voltage = "+tableCalcMax((load+".Voltage"),tableRows()-3)+" Volt";
="Discharged with Current = "+testCurrent+" Ampere"
="Capacity = "+(tableCalcMax((load+".Capacity"),tableRows()-2))+"Ah"
="Energy = "+(tableCalcMax((load+".Energy"),tableRows()-2))+"Wh"