Write option id into driver implementation section when saving the sics_config.ini

This commit is contained in:
Ferdi Franceschini
2014-07-02 14:40:22 +10:00
parent a439601d7d
commit 7a4ce1f234
2 changed files with 62 additions and 11 deletions

View File

@ -1,6 +1,7 @@
[12tmagnet_oxford]
desc = "12 Tesla Oxford Magnet"
driver = "oxford_labview"
id = 1
imptype = magnetic_field
ip = 10.157.205.3
port = 55001
@ -10,11 +11,12 @@ desc = "som will be redefined as the magnet sample insert rotation. Sample stage
imptype = motion_axis
[12tmagnet_setup]
cascade = B1:12tmagnet_oxford,sample_stage:12tmagnet_sample_insert,T1:mercury_scpi
cascade = B1:12tmagnet_oxford,sample_stage:12tmagnet_sample_insert,T1:mercury_scpi_01
enabled = False
[B1]
enabled = False
id = 1
implementation = 12tmagnet_oxford
name = magnet1
optype = magnetic_field
@ -40,6 +42,7 @@ enabled = True
[I1]
datype = I
enabled = False
id = 1
implementation = protek_01
name = curr1
optype = multimeter
@ -47,39 +50,45 @@ optype = multimeter
[I2]
datype = I
enabled = False
id = 2
implementation = protek_02
name = curr2
optype = multimeter
[T1]
enabled = False
implementation = mercury_scpi
id = 1
implementation = mercury_scpi_01
name = tc1
optype = temperature
[T2]
enabled = False
implementation = ls336_02
id = 2
implementation = ls340_01
name = tc2
optype = temperature
[T3]
enabled = False
implementation = ls336_04
id = 3
implementation = ls340_02
name = tc3
optype = temperature
[V1]
datype = V
enabled = False
implementation = protek_01
id = 1
implementation = none
name = volts1
optype = multimeter
[V2]
datype = V
enabled = False
implementation = protek_02
id = 2
implementation = none
name = volts2
optype = multimeter
@ -150,6 +159,7 @@ tol2 = 1.0
[ls340_01]
desc = "tc7: Lakeshore 340 temperature controller"
driver = "lakeshore_340"
id = 2
imptype = temperature
ip = 137.157.201.86
port = 4001
@ -160,6 +170,7 @@ tol2 = 1.0
[ls340_02]
desc = "tc8: Lakeshore 340 temperature controller"
driver = "lakeshore_340"
id = 3
imptype = temperature
ip = 137.157.201.86
port = 4002
@ -167,14 +178,28 @@ terminator = \r\n
tol1 = 1.0
tol2 = 1.0
[mercury_scpi]
desc = "tc9: Oxford Mercury temperature controller in Mercury mode"
[mercury_scpi_01]
desc = "Oxford Mercury temperature controller in Mercury mode"
driver = "mercury_scpi"
id = 1
imptype = temperature
ip = 10.157.205.5
permlink = LT
port = 7020
terminator = \r
tol = 2.0
terminator = \r\n
tol = 1.0
valve_tol = 2
[mercury_scpi_02]
desc = "Oxford Mercury temperature controller in Mercury mode"
driver = "mercury_scpi"
imptype = temperature
ip = 10.157.205.47
permlink = LT
port = 7020
terminator = \r\n
tol = 1.0
valve_tol = 2
[normal_sample_stage]
desc = "This is the default sample stage configuration with xy translation and phi and chi tilt stages"
@ -183,6 +208,7 @@ imptype = motion_axis
[protek_01]
desc = "Protek Multimeter"
driver = "protek"
id = 1
imptype = multimeter
ip = 10.157.205.36
port = 4001
@ -190,6 +216,7 @@ port = 4001
[protek_02]
desc = "Protek Multimeter"
driver = "protek"
id = 2
imptype = multimeter
ip = 10.157.205.37
port = 4001

View File

@ -43,6 +43,10 @@ class InstConfigData:
# {optype: [impname] }
imp_dict = defaultdict(list)
# imp2opt_dict: Maps each implementation to an option or None,
# {imp: opt/None}
imp2opt_dict = {}
def __init__(self):
return
@ -77,16 +81,28 @@ class InstConfigData:
stateval = False
permanent = False
if self.file_parser.has_option(s, 'id'):
id = self.file_parser.get(s, 'id')
self.opt_dict[s]['id'] = id
self.opt_dict[s]['enabled'] = stateval
self.opt_dict[s]['permanent'] = permanent
self.opt_dict[s]['imptype'] = imptype
self.opt_dict[s]['selected_imp'] = selected_imp
if selected_imp in self.imp2opt_dict:
self.opt_dict[s]['selected_imp'] = "none"
else:
self.opt_dict[s]['selected_imp'] = selected_imp
print 'Add imp2opt_dict[{0}] = {1}'.format(selected_imp,s)
self.imp2opt_dict[selected_imp] = s
def __get_implementations(self):
for s in self.file_parser.sections():
if self.file_parser.has_option(s, 'imptype'):
key = self.file_parser.get(s, 'imptype')
self.imp_dict[key].append(s)
if s not in self.imp2opt_dict:
print 'Add imp2opt_dict[{0}] = none'.format(s)
self.imp2opt_dict[s] = "none"
def read_config_file(self, config_filename):
self.config_filename = config_filename
@ -111,17 +127,25 @@ class InstConfigData:
enabled = 'Always'
else:
enabled = dict['enabled'].__str__()
self.file_parser.set(item, 'enabled', enabled)
self.file_parser.set(item, 'implementation', dict['selected_imp'])
self.file_parser.set(item, 'optype', dict['imptype'])
for item,dict in self.configuration_dict.iteritems():
enabled = dict['enabled'].__str__()
self.file_parser.set(item, 'enabled', enabled)
for imp,opt in self.imp2opt_dict.iteritems():
if imp != 'none' and 'id' in self.opt_dict[opt]:
self.file_parser.set(imp, 'id', self.opt_dict[opt]['id'])
with open(self.config_filename,'w') as cfile:
for section in sorted(self.file_parser.sections()):
cfile.write("[%s]\n" % section)
for option in sorted(self.file_parser.options(section)):
cfile.write("%s = %s\n" % (option, self.file_parser.get(section, option)))
cfile.write("\n")
#self.file_parser.write(cfile)