Ejemplo n.º 1
0
 def est1_on_t(self, b, c):
     '''estimates how long it takes from the current state to
        bending power supply on, depending on cabinet state c and
        power supply state b.
     '''
     if c in CAB_ON_T:
         t = CAB_ON_T[c]
         if b in BEND_ON_T:
             return t+BEND_ON_T[b]
         else:
             msg = 'can not switch on power supply when in state [%02x,%02x]' % (b,c)
             raise PS.PS_Exception(msg)
     else:
         msg = 'can not switch on cabinet when in state [%02x,%02x]' % (b,c)
         raise PS.PS_Exception(msg)
Ejemplo n.º 2
0
    def check_waveform(self, dat):
        """Generates exception when trying to transmit values that are out of
           valid range, which is given by PT_MAX (two times the nominal value).
        """
        max_dat = max(dat)
        if max_dat > PT_MAX:
            idx = dat.index(max_dat)
            msg = 'waveform point %d too big: %d > %d' % (idx, max_dat, PT_MAX)
            raise PS.PS_Exception(msg)

        min_dat = min(dat)
        if min_dat < PT_MIN:
            idx = dat.index(min_dat)
            msg = 'waveform point %d too small: %d < %d' % (idx, min_dat, PT_MIN)
            raise PS.PS_Exception(msg)
Ejemplo n.º 3
0
 def get_mac(self):
     aval = self['MachineState']
     if aval.quality==AQ_VALID:
         return aval.value, None
     else:
         name = self.get_name().split('/')[-1]
         raise PS.PS_Exception('failure to get valid state id for %s' % name)
Ejemplo n.º 4
0
    def upload(self, ch, maxlen=None):
        '''reads waveform from hardware, discarding the last point.
           since the server appends a copy of the first point to then end.
        '''
        sok = self.sok
        if not sok.is_connected:
            raise PS.PS_Exception('not connected')
        cmd_start_ul = 'u'+str(ch)+TERM
        wave = deque()
        tmout = AVG_TIME_PER_SAMPLE*maxlen + TIME_BASE
        self.log.debug('starting upload %s, timeout %s', ch, tmout)
        start_t = time()
        self.sok.write(cmd_start_ul)
        if maxlen is None: maxlen = MAX_WAVE_LEN
        self.sok.timeout = tmout
        try_again = True
        while True:
            payload = self.sok.readline().strip()
            if payload.startswith('ok'):
                break

            elif payload == 'er08' and try_again:
                self.log.debug('was busy, trying again')
                try_again = False
                self.sok.write(cmd_start_ul)
                continue

            elif payload.startswith('e'):
                raise WaveformException(payload)

            elif payload == '':
                self.sok.disconnect_exc()
                raise PS.PS_Exception('disconnected from wave loader')
            else:
                try:
                    wave.append(int(payload))
                except Exception:
                    raise PS.PS_Exception('strange payload %r in upload, read %d points so far' % (payload, len(wave)))

        self._duration = time()-start_t
        wave = tuple(wave)
        if maxlen and maxlen<len(wave):
            msg = 'upload yielded %d points, expected maximal %d' % (len(wave), maxlen)
            raise PS.PS_Exception(msg)

        self.log.debug('upload time %s s for %s pt', self._duration, len(wave))
        return wave
Ejemplo n.º 5
0
 def connect(self, host, type_hint=0):
     '''Tells where to connect to. The actual connecting is done by reconnect.
     '''
     if not host:
         raise PS.PS_Exception('no IpAddress configured')
     self.log.info('connecting to ' + host)
     self.comm.connect(host, DEFAULT_EC_PORT, connect=False)
     self.type_hint = type_hint
Ejemplo n.º 6
0
 def run(self, impl, wavl):
     was_power_on = impl.is_power_on()
     impl.ramp_off()
     if impl.is_ramping():#it would have to have change to 'off' with ramp_off() call
         raise PS.PS_Exception('Trying to download a waveform when ramping')
     rval = wavl.download(self.port, self.data)
     impl.push_wave_down(self.wave)
     if was_power_on: impl.On()
     return rval
Ejemplo n.º 7
0
    def _command(self, cmd):
        '''Executes a single command.
           this command is not thread-safe!
        '''
        if not self.comm.is_connected:
            traceback.print_exc()
            raise PS.PS_Exception('control %s not connected' % self.comm.hopo)
        cmd = cmd.upper().strip()
        COM = self.comm
        txt = cmd + "\r"
        response = None
        self.command_counter += 1

        # retries CAN bus commands COMMAND_RETRY times
        for r in range(COMMAND_RETRY):
            # communication pause before retry
            command_pause_retry(r)
            COM.write(txt)
            response = COM.readline()
            # indicates TCP socket timeout
            if not response:
                self.command_timeout += 1
                self.log.debug("timed out reading")
                msg = "timed out waiting %s for responding to %s" % \
                    (self.comm.hopo, cmd)
                raise PS.PS_Exception(msg)

            if response[0] == '*':
                self.capture_can_bus_timeout(cmd)
            else:
                break

        if response[0] == '*':
            self.raise_can_bus_timeout(cmd)

        payload = response.strip()
        if payload.startswith("E"):
            if payload in ERROR_RESPONSE:
                msg = ERROR_RESPONSE[payload] % dict(
                    cmd=cmd, port=self.active_port) + " (" + payload + ")"
            else:
                msg = payload
            raise PS.PS_Exception(msg)
        return payload
Ejemplo n.º 8
0
 def write_attribute(self, attr):
     try:
       if time()<self.next_update_t:
           raise PS.PS_Exception('devices proxies are not available')
       aname = attr.get_name()
       data = attr.get_write_value()
       self.bend1.write_attribute_asynch(aname, data, nop)
       self.bend2.write_attribute_asynch(aname, data, nop)
     except Tg.DevFailed:
       self.delay_update()
Ejemplo n.º 9
0
    def download(self, ch, wave):
        '''Transmits waveform to control unit.
        '''
        if not self.sok.is_connected:
            raise PS.PS_Exception('not connected')

        wave = tuple(int(w) for w in wave)
        tmout = self.sok.timeout
        self.log.debug('starting download %s, timeout %s s', ch, tmout)
        self.sok.timeout = self.sok.read_timeout
        start_dl_cmd = 'd'+str(ch)+TERM
        self.sok.write(start_dl_cmd)
        buf = ''.join(str(w)+TERM for w in wave) + ';' + TERM
        self.log.debug('buf contains %d characters' % len(buf))
        start_t = time()
        self.sok.timeout = AVG_TIME_PER_SAMPLE * len(wave) + TIME_BASE
        self.sok.write(buf)
        ret = self.sok.readline().strip()
        if not ret.startswith('ok'):
            raise WaveformException(ret)
        duration = time()-start_t
        self.log.info('download {0} finished after {1} s'.format(ch, duration))
        if self.verify:
            self.log.debug('verifying...')
            success = False
        else:
            success = True

        for r in range(1,1+self.verify):
            upstart_t = time()
            wup = self.upload(ch,len(wave))
            up_duration = time()-upstart_t
            if tuple(wup)==tuple(wave):
                self.log.info('verification succeeded at {0}. attempt'.format(r))
                success = True
                break
            else:
                self.log.warn('verification failed, attempt {0}'.format(r))
                dump_to_file(self, wup, wave, r)

        if not success:
            raise LoadException('verification failed')
        self._duration = duration
        return ret
Ejemplo n.º 10
0
 def power_off(self):
     """Switches cabinet off.
     """
     self.log.error('can not turn off cabinet without relay board')
     raise PS.PS_Exception('cabinet without relay boards are always on.')
Ejemplo n.º 11
0
 def write_f(inst, wattr):
     if not self.writeable:
         raise PS.PS_Exception('tuning regulation parameters disabled')
     write_value = wattr.get_write_value()
     inst.obj_set(rp.cobj, index, repr(write_value))