Created
June 28, 2021 20:02
-
-
Save goran-mahovlic/5320659fac05c1143658a872c4dc885a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from eez import scpi | |
from utime import ticks_ms | |
TIMEOUT = 5000 | |
def init_dlog_message(msg): | |
scpi('DISP:TEXT "Init DLOG ' + msg + '"') | |
def init_y12_and_y13(): | |
init_dlog_message("Y14") | |
scpi("SENS:DLOG:TRAC:Y14:UNIT VOLT") | |
scpi("SENS:DLOG:TRAC:Y14:LAB \"Uch1\"") | |
scpi("SENS:DLOG:TRAC:Y14:RANG:MIN 0") | |
scpi("SENS:DLOG:TRAC:Y14:RANG:MAX 40") | |
init_dlog_message("Y15") | |
scpi("SENS:DLOG:TRAC:Y15:UNIT AMPE") | |
scpi("SENS:DLOG:TRAC:Y15:LAB \"Ich1\"") | |
scpi("SENS:DLOG:TRAC:Y15:RANG:MIN 0") | |
scpi("SENS:DLOG:TRAC:Y15:RANG:MAX 5") | |
def init_all(): | |
scpi('DISP:TEXT "Imax B6 in controll!"') | |
scpi('SYST:DEL 50') | |
init_dlog_message("X") | |
scpi('SENS:DLOG:TRAC:X:UNIT SECO') | |
scpi('SENS:DLOG:TRAC:X:STEP 1') | |
scpi('SENS:DLOG:TRAC:X:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:X:RANG:MAX 20') | |
scpi('SENS:DLOG:TRAC:X:LAB "t"') | |
init_dlog_message("Y1") | |
scpi('SENS:DLOG:TRAC:Y1:UNIT SECO') | |
scpi('SENS:DLOG:TRAC:Y1:LAB "t"') | |
scpi('SENS:DLOG:TRAC:Y1:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y1:RANG:MAX 86400') | |
init_dlog_message("Y2") | |
scpi('SENS:DLOG:TRAC:Y2:UNIT VOLT') | |
scpi('SENS:DLOG:TRAC:Y2:LAB "U"') | |
scpi('SENS:DLOG:TRAC:Y2:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y2:RANG:MAX 12') | |
init_dlog_message("Y3") | |
scpi('SENS:DLOG:TRAC:Y3:UNIT AMPE') | |
scpi('SENS:DLOG:TRAC:Y3:LAB "I"') | |
scpi('SENS:DLOG:TRAC:Y3:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y3:RANG:MAX 5') | |
init_dlog_message("Y4") | |
scpi('SENS:DLOG:TRAC:Y4:UNIT UNKN') | |
scpi('SENS:DLOG:TRAC:Y4:LAB "C"') | |
scpi('SENS:DLOG:TRAC:Y4:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y4:RANG:MAX 1000') | |
init_dlog_message("Y5") | |
scpi('SENS:DLOG:TRAC:Y5:UNIT WATT') | |
scpi('SENS:DLOG:TRAC:Y5:LAB "P"') | |
scpi('SENS:DLOG:TRAC:Y5:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y5:RANG:MAX 1000') | |
init_dlog_message("Y6") | |
scpi('SENS:DLOG:TRAC:Y6:UNIT UNKN') | |
scpi('SENS:DLOG:TRAC:Y6:LAB "E"') | |
scpi('SENS:DLOG:TRAC:Y6:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y6:RANG:MAX 1000') | |
init_dlog_message("Y7") | |
scpi('SENS:DLOG:TRAC:Y7:UNIT UNKN') | |
scpi('SENS:DLOG:TRAC:Y7:LAB "Text"') | |
scpi('SENS:DLOG:TRAC:Y7:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y7:RANG:MAX 200') | |
init_dlog_message("Y8") | |
scpi('SENS:DLOG:TRAC:Y8:UNIT UNKN') | |
scpi('SENS:DLOG:TRAC:Y8:LAB "Tint"') | |
scpi('SENS:DLOG:TRAC:Y8:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y8:RANG:MAX 200') | |
init_dlog_message("Y9") | |
scpi('SENS:DLOG:TRAC:Y9:UNIT VOLT') | |
scpi('SENS:DLOG:TRAC:Y9:LAB "Uin"') | |
scpi('SENS:DLOG:TRAC:Y9:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y9:RANG:MAX 12') | |
init_dlog_message("Y10") | |
scpi('SENS:DLOG:TRAC:Y10:UNIT OHM') | |
scpi('SENS:DLOG:TRAC:Y10:LAB "Rbat"') | |
scpi('SENS:DLOG:TRAC:Y10:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y10:RANG:MAX 100000') | |
init_dlog_message("Y11") | |
scpi('SENS:DLOG:TRAC:Y11:UNIT OHM') | |
scpi('SENS:DLOG:TRAC:Y11:LAB "Rwire"') | |
scpi('SENS:DLOG:TRAC:Y11:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y11:RANG:MAX 100000') | |
init_dlog_message("Y12") | |
scpi('SENS:DLOG:TRAC:Y12:UNIT UNKN') | |
scpi('SENS:DLOG:TRAC:Y12:LAB "Charge"') | |
scpi('SENS:DLOG:TRAC:Y12:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y12:RANG:MAX 100') | |
init_dlog_message("Y13") | |
scpi('SENS:DLOG:TRAC:Y13:UNIT SECO') | |
scpi('SENS:DLOG:TRAC:Y13:LAB "t"') | |
scpi('SENS:DLOG:TRAC:Y13:RANG:MIN 0') | |
scpi('SENS:DLOG:TRAC:Y13:RANG:MAX 86400') | |
init_y12_and_y13() | |
scpi('DISP:TEXT:CLE') | |
scpi('INIT:DLOG:TRACE "/Recordings/imaxB6.dlog"') | |
def flush_uart(): | |
while scpi("SYSTem:COMMunicate:UART:RECeive?") != "": | |
pass | |
scpi("*SAV 10") | |
scpi("MEM:STATE:FREEZE ON") | |
#scpi("*RST") | |
# remove everything from the UART buffer at the start | |
flush_uart() | |
start_timeout_counting = ticks_ms() | |
# store characters received from the UART into this buffer | |
received = "" | |
first_line = True | |
try: | |
while True: | |
received_before_len = len(received) | |
received += scpi("SYSTem:COMMunicate:UART:RECeive?") | |
received_after_len = len(received) | |
if not first_line and received_before_len == received_after_len: | |
if ticks_ms() - start_timeout_counting >= TIMEOUT: | |
# we didn't received anything from the UART in TIMEOUT milliseconds, | |
# finish execution of the script | |
break | |
else: | |
start_timeout_counting = ticks_ms() | |
# split received buffer into lines | |
received = received.replace("\r\n", "\n") | |
received = received.replace("\r", "\n") | |
lines = received.split("\n") | |
# execute each line as SCPI command | |
for line in lines[0:-1]: | |
if line.startswith("INIT:DLOG:TRACE"): | |
# add Y12 (meas:volt?) and Y13 (meas:curr?) to DLOG Y-Axes | |
init_y12_and_y13() | |
scpi('DISP:TEXT:CLE') | |
if line.startswith("SENS:DLOG:TRACE:DATA"): | |
# append meas:volt? and meas:curr? to trace data | |
line = line + "," + str(scpi("meas:volt?")) | |
line = line + "," + str(scpi("meas:curr?")) | |
if line.startswith("$"): | |
# RAW format detected | |
if first_line: | |
# if this is first line then initialize DLOG | |
init_all() | |
values = line[0:].split(";")[0:28] | |
values[3] = round(float(values[3])/1000,2) | |
values[4] = round(float(values[4])/1000,2) | |
values[5] = round(float(values[5])/1000,2) | |
values[6] = round(float(values[6])/100,2) | |
values[7] = round(float(values[7])/100,2) | |
values[8] = 0.0 | |
values[9] =round(float( values[9])/100,2) | |
for x in range(10,25): | |
values[x] = round((float(values[x])/1000),2) | |
values[26] = round((float(values[26]) * 60),2) | |
logValues = [] | |
y=0 | |
for x in range(2,11): | |
logValues.insert(y, values[x]) | |
y+=1 | |
#logValues[0] = 0.00 | |
logValues.insert(9, values[23]) | |
logValues.insert(10, values[24]) | |
logValues.insert(11, values[25]) | |
logValues.insert(12, values[26]) | |
string_ints = [str(int) for int in logValues] | |
logValues = ",".join(string_ints) | |
print(logValues) | |
scpi("SENS:DLOG:TRACE:DATA " + logValues + "," + str(scpi("meas:volt?")) + "," + str(scpi("meas:curr?"))) | |
else: | |
scpi(line) | |
first_line = False | |
# remove processed lines from the received buffer | |
received = lines[-1] | |
finally: | |
scpi("ABOR:DLOG") | |
scpi("*RCL 10") | |
scpi("MEM:STATE:FREEZE OFF") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment