def __init__(self): state.Module.__init__(self, None) self.can_hang = {} self.active_port = None self.comm = FriendlySocket() self.comm.read_timeout = 2.5 # locks link to Ethernet bridge self.lck = RLock() self.rem_vdq = factory.VDQ(False) self.error_code = 0 self.state_id = None self.update_t = None # only true when the cabinet is ON self.updater = UpdateThread() self.desc = 'generic' self.stat = (DevState.UNKNOWN, 'unknown') self.command_queue = deque() # counters self.init_counter = 0 self.command_counter = 0 # counting can bus level timeouts self.command_canbus_timeout = 0 # counting socket level timeouts self.command_timeout = 0 self.__log = None self.telnet_connection = None
class CabinetControl(state.Module): '''Cabinet wide-status and control link. ''' name = 'cabinet' state_id = 0 host = property(lambda inst: inst.comm.host) port = None #< port of the cabinet controller / relay board (used for resetting interlocks) type_hint = 0 use_waveforms = None #< using None to indicate UNKNOWN stat = DevState.UNKNOWN, 'unknown' # which alarm bits shall be used #< indicates which 'port' of the PS should be used to reading cabinet-wide # status and which relay board to use for switching on dipole & quad # the default (None) indicates that there is no relay board in the system # and the functionality is provided by the relay board # when CAN bus hangs this flag will be true # reset it by explicit assignment or by calling update_state def __init__(self): state.Module.__init__(self, None) self.can_hang = {} self.active_port = None self.comm = FriendlySocket() self.comm.read_timeout = 2.5 # locks link to Ethernet bridge self.lck = RLock() self.rem_vdq = factory.VDQ(False) self.error_code = 0 self.state_id = None self.update_t = None # only true when the cabinet is ON self.updater = UpdateThread() self.desc = 'generic' self.stat = (DevState.UNKNOWN, 'unknown') self.command_queue = deque() # counters self.init_counter = 0 self.command_counter = 0 # counting can bus level timeouts self.command_canbus_timeout = 0 # counting socket level timeouts self.command_timeout = 0 self.__log = None self.telnet_connection = None def set_logger(self, l): self.__log = l self.updater.log = l log = property(lambda self: self.__log, set_logger) is_connected = property(lambda self: self.comm.is_connected) def start(self): if self.update is None: self.updater = UpdateThread() self.updater.start() def stop(self): if self.updater is None: return else: self.updater.running = False def restart(self): self.stop() old_register = copy(self.updater.register) self.updater = UpdateThread() self.updater.add_list(old_register) self.start(re=True) 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 def restart_bsw_tcp(self): self.log.info('restart_bsw_tcp stub does nothing') def reconnect(self, reap=False): '''Ensures that a connection with 'host' (if configured) is etablished Raising an exception if fails. If connection is refused it is attempted to restart_bsw_tcp. ''' try: return self.reconnect_core() except socket.error, err: if reap and err.errno == ECONNREFUSED: self.restart_bsw_tcp() return False else: raise except Exception: traceback.print_exc()
class CabinetControl(state.Module): '''Cabinet wide-status and control link. ''' name = 'cabinet' state_id = 0 host = property(lambda inst: inst.comm.host) port = None #< port of the cabinet controller / relay board (used for resetting interlocks) type_hint = 0 use_waveforms = None #< using None to indicate UNKNOWN stat = DevState.UNKNOWN, 'unknown' # which alarm bits shall be used #< indicates which 'port' of the PS should be used to reading cabinet-wide # status and which relay board to use for switching on dipole & quad # the default (None) indicates that there is no relay board in the system # and the functionality is provided by the relay board # when CAN bus hangs this flag will be true # reset it by explicit assignment or by calling update_state def __init__(self): state.Module.__init__(self, None) self.can_hang = {} self.active_port = None self.comm = FriendlySocket() self.comm.read_timeout = 2.5 # locks link to Ethernet bridge self.lck = RLock() self.rem_vdq = factory.VDQ(False) self.error_code = 0 self.state_id = None self.update_t = None # only true when the cabinet is ON self.updater = UpdateThread() self.desc = 'generic' self.stat = (DevState.UNKNOWN, 'unknown') self.command_queue = deque() # counters self.init_counter = 0 self.command_counter = 0 # counting can bus level timeouts self.command_canbus_timeout = 0 # counting socket level timeouts self.command_timeout = 0 self.__log = None self.telnet_connection = None def set_logger(self, l): self.__log = l self.updater.log = l log = property( lambda self: self.__log, set_logger ) is_connected = property(lambda self: self.comm.is_connected) def start(self): if self.update is None: self.updater = UpdateThread() self.updater.start() def stop(self): if self.updater is None: return else: self.updater.running = False def restart(self): self.stop() old_register = copy(self.updater.register) self.updater = UpdateThread() self.updater.add_list(old_register) self.start(re=True) 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 def restart_bsw_tcp(self): self.log.info('restart_bsw_tcp stub does nothing') def reconnect(self, reap=False): '''Ensures that a connection with 'host' (if configured) is etablished Raising an exception if fails. If connection is refused it is attempted to restart_bsw_tcp. ''' try: return self.reconnect_core() except socket.error, err: if reap and err.errno==ECONNREFUSED: self.restart_bsw_tcp() return False else: raise except Exception: traceback.print_exc()