def __init__(self, useChans=None, configModule_klass=Configurable, **kwargs): ''' Args: useChans (list(int)): integers that indicate channel number. Used to key dictionaries and write select messages. configModule_klass (type): class that members will be initialized as. When ``Configurable``, this object is basically a container; however, when ``ConfigModule``, there is special behavior for multi-channel instruments. ''' if useChans is None: logger.warning('No useChans specified for MultiModuleConfigurable') useChans = list() self.useChans = useChans # Check that the requested channels are available to be blocked out if self.maxChannel is not None: if any(ch > self.maxChannel - 1 for ch in self.useChans): raise ChannelError( 'Requested channel is more than there are available') self.modules = [] for chan in self.useChans: self.modules.append(configModule_klass(channel=chan, bank=self)) super().__init__(**kwargs)
def setConfigArray(self, cStr, newValArr, forceHardware=False): ''' Iterate over modules setting the parameter to the corresponding array value. Values for *ALL* channels must be specified. To only change some, use the dictionary-based setter: ``setConfigDict`` Args: cStr (str): parameter name newValArr (np.ndarray, list): values in same ordering as useChans forceHardware (bool): guarantees sending to hardware Returns: (bool): did any require hardware write? ''' if len(newValArr) != len(self.modules): raise ChannelError('Wrong number of channels in array. ' + 'Got {}, '.format(len(newValArr)) + 'Expected {}.'.format(len(self.useChans))) bankWroteToHardware = False for module, val in zip(self.modules, newValArr): moduleWroteToHardware = module.setConfigParam( cStr, val, forceHardware=forceHardware) bankWroteToHardware = bankWroteToHardware or moduleWroteToHardware return bankWroteToHardware
def validateChannel(self, channel): ''' Raises an error with info if not a valid channel ''' if channel not in self.channelDescriptions.keys(): raise ChannelError( 'Not a valid PowerMeter channel. Use ' + ' '.join( ('{} ({})'.format(k, v) for k, v in self.channelDescriptions)))
def __init__(self, useChans=None, **kwargs): if useChans is None: logger.warning('No useChans specified for MultichannelSource') useChans = list() self.useChans = useChans self.stateDict = dict([ch, 0] for ch in self.useChans) # Check that the requested channels are available to be blocked out if self.maxChannel is not None: if any(ch > self.maxChannel - 1 for ch in self.useChans): raise ChannelError( 'Requested channel is more than there are available') super().__init__(**kwargs)
def setConfigDict(self, cStr, newValDict, forceHardware=False): ''' Args: cStr (str): parameter name newValDict (array): dict keyed by channel number forceHardware (bool): guarantees sending to hardware Returns: (bool): did any require hardware write? ''' for chan in newValDict.keys(): if chan not in self.useChans: raise ChannelError('Channel index not blocked out. ' + 'Requested {}, '.format(chan) + 'Available {}.'.format(self.useChans)) setArrayBuilder = self.getConfigArray(cStr) for iCh, chan in enumerate(self.useChans): if chan in newValDict.keys(): setArrayBuilder[iCh] = newValDict[chan] return self.setConfigArray(cStr, setArrayBuilder, forceHardware=forceHardware)
def setChannelTuning(self, chanValDict): ''' Sets a number of channel values and updates hardware Args: chanValDict (dict): A dictionary specifying {channel: value} waitTime (float): time in ms to wait after writing, default (None) is defined in the class Returns: (bool): was there a change in value ''' if type(chanValDict) is not dict: raise TypeError( 'The argument for setChannelTuning must be a dictionary') # Check channels for chan in chanValDict.keys(): if chan not in self.stateDict.keys(): raise ChannelError('Channel index not blocked out. ' + 'Requested ' + str(chan) + ', Available ' + str(self.stateDict.keys())) # Change our *internal* state self.stateDict.update(chanValDict)