def generateChannels(self, inout): Inout = inout.capitalize() print "Generating channels for "+str(Inout)+"put" for i in xrange(self.instrument['main'][inout+'putchannels']): dev = self.parser.getint(Inout+'putchannel'+str(i),'device') typ = self.parser.get(Inout+'putchannel'+str(i),'type') num = self.parser.getint(Inout+'putchannel'+str(i),'number') rang = self.parser.get(Inout+'putchannel'+str(i),'vrange') if dev in self.instrument['devices']: device = self.instrument['devices'][dev] if typ == 'a': if device['analog'][inout] is None: raise PySICMError( 'An analog channel has been specified for '+inout+'put channel '+str(i)+ ', but the device does not have an analog '+inout+'put subdevice.') else: self.instrument[inout+'putchannels'][i] = self.registerAnalogChannel(device['analog']['in'], num, rang) elif typ == 'd': if device['digital'][inout] is None: raise PySICMError( 'A digital channel has been specified for '+inout+'put channel '+str(i)+ ', but the device does not have a digital '+inout+'put subdevice.')
def axes(self, **kwargs): '''Specify the different axes for this control Params (optional): ------------------ x: PiezoControl for x-axis y: PiezoControl for y-axis z: ZPiezoControl for z-axis ''' if ('x' in kwargs): self._axes['x'] = kwargs['x'] if ('y' in kwargs): self._axes['y'] = kwargs['y'] if ('z' in kwargs): try: kwargs['z'].approach self._axes['z'] = kwargs['z'] except AttributeError: raise PySICMError( "Z-Axis' PiezoControl does not implement method 'approach'" ) if ('zcoarse' in kwargs): try: kwargs['zcoarse'].up kwargs['zcoarse'].down self._axes['zcoarse'] = kwargs['zcoarse'] except AttributeError: raise PySICMError( "coarse Z-Axis ' does not implement methods 'up' and 'down'" ) if ('xcoarse' in kwargs): try: kwargs['xcoarse'].up kwargs['xcoarse'].down self._axes['xcoarse'] = kwargs['xcoarse'] except AttributeError: raise PySICMError( "coarse X-Axis ' does not implement methods 'up' and 'down'" ) if ('ycoarse' in kwargs): try: kwargs['ycoarse'].up kwargs['ycoarse'].down self._axes['zcoarse'] = kwargs['ycoarse'] except AttributeError: PySICMError( "coarse Y-Axis ' does not implement methods 'up' and 'down'" ) if ('zfine' in kwargs): self._axes['zfine'] = kwargs['zfine']
def addCommand(self, command): try: command.getCommandString except: raise PySICMError('Command does not have the method `getCommandString`. Might be the wrong type.') self.commands[command.getCommandString()] = command
def execute(self, param, _id = None): print "Trying to call "+str(self.command)+" with param: "+str(param) # print "The callback is "+ str(self.params[param]) if param in self.params: print "Param is known" return self._execute(self.params[param](), _id = _id) else: PySICMError('Parameter '+str(param)+' not defined for command '+str(self.command))
def handle(self, comstring, _id = None): com, param = self.splitCommand(comstring) if not self.hasCommand(com): print "Unknown command" PySICMError('Command '+com+' unknown') else: print "Trying to execute "+str(com.upper()) return self.commands[com.upper()].execute(param, _id = _id)
def _getTypAndNum(self, string): res = re.match('[A-Za-z]+', string) try: typ = res.group() except AttributeError: PySICMError('Cannot parse string '+ string) return typ, string[len(typ):]
def __init__(self, mode): if mode not in [self.SERVER, self.CLIENT]: raise PySICMError( 'Core initialized with unknown mode. Mode was: ' + str(mode)) self._mode = mode sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) if mode == self.SERVER: self._initServer() elif mode == self.CLIENT: self._initClient()
def registerAnalogChannel(self, sdev, num, rang): print ("registering an analog channel with number " +str(num)) chan = sdev.channel( num, factory = AnalogChannel, aref=CONSTANTS.AREF.ground) r = rang.split(",",1) r_min = float(r[0]) r_max = float(r[1]) tmp_range = chan.find_range(CONSTANTS.UNIT.volt,r_min, r_max) if tmp_range < 0: raise PySICMError( 'No suitable range was found for channel '+str(num)) del chan return sdev.channel( num, factory = AnalogChannel, aref=CONSTANTS.AREF.ground, range=tmp_range)
def openScanModeWin(self, mode): istool = False if mode.startswith('__tool__'): mode = "tool" + mode[8].capitalize() + mode[9:] istool = True widgetfile = os.path.join( os.path.dirname(__file__), 'widget' + mode[0].capitalize() + mode[1:] + '.py') if os.path.exists(widgetfile): pymod = imp.load_source(mode, widgetfile) instance = getattr(pymod, 'Widget' + mode[0].capitalize() + mode[1:]) if istool: self._addWindow(instance(self), None, None) else: self._addWindow(instance(self), 800, 600) else: raise PySICMError('No widget found for scan mode %s' % mode)
def handleError(self, error): print str(error) raise PySICMError('An error occured!')