improvements for flame
- frappy_psi.channelswitcher: use isBusy instead of checking value and target - frappy_psi.ls372: remove underflow mechanism - frappy_psi.parmod.SwitchDriv: switch the controlled module also when not buys
This commit is contained in:
@ -202,6 +202,7 @@ class ResChannel(Channel):
|
||||
_toggle_autorange = 'init'
|
||||
_prev_rdgrng = (1, 1) # last read values for icur and exc
|
||||
_last_range_change = 0
|
||||
_value = None # if not None, a fresh value
|
||||
rdgrng_params = 'range', 'iexc', 'vexc'
|
||||
inset_params = 'enabled', 'pause', 'dwell'
|
||||
STATUS_MASK = 0x3f # mask T_OVER and T_UNDER
|
||||
@ -221,7 +222,7 @@ class ResChannel(Channel):
|
||||
def read_status(self):
|
||||
if not self.enabled:
|
||||
return [self.Status.DISABLED, 'disabled']
|
||||
if not self.channel == self.switcher.value == self.switcher.target:
|
||||
if self.switcher.isBusy():
|
||||
return self.status
|
||||
result = int(self.communicate('RDGST?%d' % self.channel)) & self.STATUS_MASK
|
||||
statustext = ' '.join(formatStatusBits(result, STATUS_BIT_LABELS))
|
||||
@ -259,15 +260,19 @@ class ResChannel(Channel):
|
||||
return result
|
||||
|
||||
def read_value(self):
|
||||
if self.channel == self.switcher.value == self.switcher.target:
|
||||
return self._read_value() or self.value
|
||||
return self.value if self.enabled else 0
|
||||
if self.switcher.isBusy():
|
||||
return self.value if self.enabled else 0
|
||||
value = self._read_value() if self._value is None else self._value
|
||||
self._value = None
|
||||
return self.value if value is None else value
|
||||
|
||||
def is_switching(self, now, last_switch, switch_delay):
|
||||
last_switch = max(last_switch, self._last_range_change)
|
||||
if now + 0.5 > last_switch + self.pause:
|
||||
self._read_value() # adjust range only
|
||||
return super().is_switching(now, last_switch, switch_delay)
|
||||
result = super().is_switching(now, last_switch, switch_delay)
|
||||
if not result: # the time since last switch has passed
|
||||
self._value = self._read_value() # for autorange
|
||||
# now check for the time since last range change
|
||||
result = super().is_switching(now, self._last_range_change, switch_delay)
|
||||
return result
|
||||
|
||||
@CommonReadHandler(rdgrng_params)
|
||||
def read_rdgrng(self):
|
||||
@ -377,7 +382,6 @@ class TemperatureLoop(HasConvergence, TemperatureChannel, Drivable):
|
||||
HTRRNG = {n: i for i, n in enumerate(['off', '30uA', '100uA', '300uA', '1mA', '3mA', '10mA', '30mA', '100mA'])}
|
||||
htrrng = Parameter('', EnumType(HTRRNG), readonly=False)
|
||||
_control_active = False
|
||||
_underflow = False
|
||||
|
||||
@Command
|
||||
def control_off(self):
|
||||
@ -399,16 +403,6 @@ class TemperatureLoop(HasConvergence, TemperatureChannel, Drivable):
|
||||
if newhtr:
|
||||
self.log.info('switched heater on %d', newhtr)
|
||||
self.communicate(f'RANGE {self.loop},{newhtr};RANGE?{self.loop}')
|
||||
if self.minheater:
|
||||
self.log.info('underflow open loop')
|
||||
self._underflow = True
|
||||
self.communicate(f'OUTMODE {self.loop},2,{self.channel},0,0,1,3;*OPC?')
|
||||
self.communicate(f'MOUT {self.loop}{self.min_percent()};*OPC?')
|
||||
elif self._underflow:
|
||||
self.log.info('switch to control after underflow')
|
||||
self._underflow = False
|
||||
self.communicate(f'OUTMODE {self.loop},5,{self.channel},0,0,1,3;*OPC?')
|
||||
self.communicate(f'SETP {self.loop},{self.target};*OPC?')
|
||||
|
||||
def read_control_active(self):
|
||||
self.set_htrrng()
|
||||
@ -416,7 +410,7 @@ class TemperatureLoop(HasConvergence, TemperatureChannel, Drivable):
|
||||
|
||||
def read_target(self):
|
||||
if self._control_active:
|
||||
return float(self.communicate('SETP?{self.loop}'))
|
||||
return float(self.communicate(f'SETP?{self.loop}'))
|
||||
return 0
|
||||
|
||||
def write_htrrng(self, value):
|
||||
@ -428,15 +422,15 @@ class TemperatureLoop(HasConvergence, TemperatureChannel, Drivable):
|
||||
outmode = (5, self.channel, 0, 0, 1, 3)
|
||||
prev = parse(self.communicate(f'OUTMODE?{self.loop}'))
|
||||
if outmode != prev:
|
||||
self.communicate(f'OUTMODE {self.loop}, %g,%g,%g,%g,%g,%g;*OPC?' % tuple(outmode))
|
||||
self.communicate(f'OUTMODE {self.loop},%g,%g,%g,%g,%g,%g;*OPC?' % tuple(outmode))
|
||||
self.communicate(f'MOUT {self.loop},{self.min_percent()};*OPC?')
|
||||
for chan in self.switcher.channels.values():
|
||||
chan._control_active = False
|
||||
self._control_active = True
|
||||
self.read_control_active()
|
||||
self.convergence_start()
|
||||
# do not resturn the readback value, as it might not yet be correct
|
||||
self.communicate(f'SETP {self.loop},{target};SETP?{self.loop}')
|
||||
# do not return the readback value, as it might not yet be correct
|
||||
self.communicate(f'SETP {self.loop},{target};*OPC?')
|
||||
return target
|
||||
|
||||
#def write_ctrlpars(self, ctrlpars):
|
||||
|
Reference in New Issue
Block a user