fix set/get_par

Change-Id: I9790a667bc2e89baf2be9e35edb7473cdfc5dd31
This commit is contained in:
Oksana Shliakhtun 2023-03-08 14:49:56 +01:00
parent ec15a35977
commit d6c641e67b

View File

@ -40,11 +40,17 @@ class LakeShore(HasIO):
head = ','.join([cmd] + [f'{a:g}' for a in args])
tail = cmd.replace(' ', '? ')
reply = self.communicate(f'{head};{tail}')
return [float(num) for num in reply.split(',')]
reply = [float(num) for num in reply.split(',')]
if len(reply) == 1:
return reply[0]
return reply
def get_par(self, cmd):
reply = self.communicate(cmd)
return [float(num) for num in reply.split(',')]
reply = [float(num) for num in reply.split(',')]
if len(reply) == 1:
return reply[0]
return reply
class Sensor340(LakeShore, Readable):
@ -75,7 +81,7 @@ class Sensor340(LakeShore, Readable):
if c % 2:
return ERROR, 'invalid reading'
# ask for high alarm status and return warning
if '1' in self.get_par(f'ALARMST? {self.channel}'):
if 1 in self.get_par(f'ALARMST? {self.channel}'):
return WARN, 'alarm triggered'
return IDLE, ''
@ -131,12 +137,10 @@ class HeaterOutput(LakeShore, HasControlledBy, HasIO, Writable):
self.set_par(f'CLIMIT {self.loop}', self.SETPOINTLIMS, 0, 0, icurrent, irange)
self.set_par(f'RANGE {irange}')
self.set_par(f'CDISP {self.loop}', 1, self.resistance, 0)
self.get_par(f'RELAY? 1') #only high relay
return self.read_max_power()
def read_max_power(self):
setplimit, _, _, icurrent, irange = [
float(s) for s in self.get_par(f'CLIMIT? {self.loop}')]
setplimit, _, _, icurrent, irange = self.get_par(f'CLIMIT? {self.loop}')
# max_power from codes disregarding voltage limit:
self._max_power = self.MAXCURRENTS[icurrent] ** 2 * self.RANGES[irange] * self.resistance
# voltage limit = 50V:
@ -154,7 +158,7 @@ class HeaterOutput(LakeShore, HasControlledBy, HasIO, Writable):
return (power / self._max_power) ** (1 / 2) * 100 # limit
def read_status(self):
return self.STATUS_MAP[int(self.get_par(f'HTRST?'))]
return self.STATUS_MAP[self.get_par(f'HTRST?')]
def write_target(self, target):
self.self_controlled()
@ -162,7 +166,7 @@ class HeaterOutput(LakeShore, HasControlledBy, HasIO, Writable):
self.set_heater_mode(3)
self.set_range()
percent = self.power_to_percent(target)
reply, = self.set_par(f'MOUT {self.loop}', '%g' % percent)
reply = self.set_par(f'MOUT {self.loop}', '%g' % percent)
return self.percent_to_power(reply)
def set_heater_mode(self, mode):
@ -215,16 +219,14 @@ class TemperatureLoop340(HasConvergence, HasOutputModule, Sensor340, Drivable, L
return {'p': p, 'i': i, 'd': d}
def write_ramp(self, ramp):
return self.set_par(f'RAMP {self.loop}', self.ramp_used, ramp)
return self.set_par(f'RAMP {self.loop}', self.ramp_used, ramp)[1]
def write_ramp_used(self, ramp_used):
return self.set_par(f'RAMP {self.loop}', ramp_used, self.ramp)
return self.set_par(f'RAMP {self.loop}', ramp_used, self.ramp)[0]
def read_ramp(self):
status, rate = self.get_par(f'RAMP? {self.loop}')
if status == 'off':
return False, rate
return True, rate
self.ramp_used, rate = self.get_par(f'RAMP? {self.loop}')
return rate
def read_status(self):
statuscode, statustext = super().read_status()