-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathModule Initialization.py
158 lines (133 loc) · 6.01 KB
/
Module Initialization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Module initialization utility
from utime import ticks_ms, ticks_add, ticks_diff, sleep_ms
from eez import scpi, setU, getOutputMode, getI
MODEL_NONE = 0
MODELS = [
{ "name": "None", "id": 0, "r": 0, "b": 0 },
{ "name": "DCP405", "id": 405, "r": 2, "b": 11 },
{ "name": "DCM220", "id": 220, "r": 2, "b": 8 },
{ "name": "DCM224", "id": 224, "r": 1, "b": 1 },
{ "name": "MIO168", "id": 168, "r": 1, "b": 2 },
{ "name": "PREL6", "id": 6, "r": 1, "b": 2 },
{ "name": "SMX46", "id": 46, "r": 1, "b": 2 },
{ "name": "MUX14D", "id": 14, "r": 1, "b": 2 },
]
slots = [
{ "model": MODEL_NONE, "version_r": 0, "version_b": 0 },
{ "model": MODEL_NONE, "version_r": 0, "version_b": 0 },
{ "model": MODEL_NONE, "version_r": 0, "version_b": 0 },
]
slots_orig = []
can_restart = 0
def error(message):
scpi('DISP:ERROR "' + message + '"')
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 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 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)
def select_version_r(slot_index):
value = scpi('DISP:INPUT? "",INT,0,255,' + str(slots[slot_index]["version_r"]))
if value != None:
slots[slot_index]["version_r"] = value
update_model_and_version(slot_index)
update_can_init(slot_index)
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)
def to_hex_str(num):
hex_str = hex(num)[2:]
return "0" + hex_str if len(hex_str) == 1 else hex_str
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")
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"] },
]
get_slots_info()
scpi("DISP:DIALog:OPEN \"/Scripts/Module Initialization.res\"")
try:
update_model_and_version(0)
update_model_and_version(1)
update_model_and_version(2)
while True:
action = scpi("DISP:DIALog:ACTIon?")
if action == "slot1_select_model":
select_model(0)
elif action == "slot2_select_model":
select_model(1)
elif action == "slot3_select_model":
select_model(2)
elif action == "slot1_input_version_r":
select_version_r(0)
elif action == "slot1_input_version_b":
select_version_b(0)
elif action == "slot2_input_version_r":
select_version_r(1)
elif action == "slot2_input_version_b":
select_version_b(1)
elif action == "slot3_input_version_r":
select_version_r(2)
elif action == "slot3_input_version_b":
select_version_b(2)
elif action == "slot1_init":
slot_init(0)
elif action == "slot2_init":
slot_init(1)
elif action == "slot3_init":
slot_init(2)
elif action == "restart":
scpi("SYST:RES")
elif action == "close" or action == 0:
break
finally:
scpi("DISP:DIALog:CLOSe")