예제 #1
0
파일: pie.py 프로젝트: reneurossance/acq4
    def __init__(self, man, config, name):
        Device.__init__(self, man, config, name)
        index = config.get('index', 0)
        devs = getDevices()
        if len(devs) == 0:
            raise Exception("No X-Keys devices found.")
        try:
            self.dev = devs[index]
        except IndexError:
            devstr = ", ".join(
                ["%d: %s" % (i, devs[i].model) for i in range(len(devs))])
            raise ValueError(
                "No X-Keys with device index %d. Options are: %s" %
                (index, devstr))
        self.model = self.dev.model
        self.keyshape = self.dev.keyshape
        self.capabilities = self.dev.capabilities

        if PIE32_BRIDGE:
            self._callback = mp.proxy(self._stateChanged, callSync='off')
            self.dev.setCallback(self._callback)
        else:
            self.dev.setCallback(self._stateChanged)

        self.dev.setIntensity(255, 255)
예제 #2
0
    def __init__(self, man, config, name):
        Device.__init__(self, man, config, name)
        index = config.get('index', 0)
        devs = getDevices()
        if len(devs) == 0:
            raise Exception("No X-Keys devices found.")
        try:
            self.dev = devs[index]
        except IndexError:
            devstr = ", ".join(["%d: %s" % (i, devs[i].model) for i in range(len(devs))])
            raise ValueError("No X-Keys with device index %d. Options are: %s" % (index, devstr))
        self.model = self.dev.model
        self.keyshape = self.dev.keyshape
        self.capabilities = self.dev.capabilities

        if PIE32_BRIDGE:
            self._callback = mp.proxy(self._stateChanged, callSync='off')
            self.dev.setCallback(self._callback)
        else:
            self.dev.setCallback(self._stateChanged)

        self.dev.setIntensity(255,255)

        self._callbacks = {}
        # use queued signal here to ensure events are processed in GUI thread
        self.sigStateChanged.connect(self._handleCallbacks, Qt.Qt.QueuedConnection)
예제 #3
0
    def __init__(self, dm, config, name):
        Device.__init__(self, dm, config, name)
        self.config = config
        self.lock = Mutex(Mutex.Recursive)
        self.index = None
        self.devRackGui = None
        self.mc = None

        self.stateLock = Mutex(
            Mutex.Recursive
        )  ## only for locking self.lastState and self.lastMode
        self.lastState = {}
        self.lastMode = None
        self._switchingToMode = None

        # default holding state
        self.holding = {'VC': -50e-3, 'IC': 0.0, 'I=0': 0.0}

        # Get a handle to the multiclamp driver object, whether that is hosted locally or in a remote process.
        executable = self.config.get('pythonExecutable', None)
        if executable is not None:
            # Run a remote python process to connect to the MC commander.
            # This is used on 64-bit systems where the MC connection must be run with
            # 32-bit python.
            if MultiClamp.proc is False:
                raise Exception(
                    "Already connected to multiclamp locally; cannot connect via remote process at the same time."
                )
            if MultiClamp.proc is None:
                MultiClamp.proc = multiprocess.Process(executable=executable,
                                                       copySysPath=False)
                try:
                    self.proc.mc_mod = self.proc._import(
                        'acq4.drivers.MultiClamp')
                    self.proc.mc_mod._setProxyOptions(deferGetattr=False)
                except:
                    MultiClamp.proc.close()
                    MultiClamp.proc = None
                    raise
            mc = self.proc.mc_mod.MultiClamp.instance()
        else:
            if MultiClamp.proc not in (None, False):
                raise Exception(
                    "Already connected to multiclamp via remote process; cannot connect locally at the same time."
                )
            else:
                # don't allow remote process to be used for other channels.
                MultiClamp.proc = False

            try:
                from acq4.drivers.MultiClamp import MultiClamp as MultiClampDriver
            except RuntimeError as exc:
                if "32-bit" in exc.message:
                    raise Exception(
                        "MultiClamp commander does not support access by 64-bit processes. To circumvent this problem, "
                        "Use the 'pythonExecutable' device configuration option to connect via a 32-bit python instead."
                    )
                else:
                    raise
            mc = MultiClampDriver.instance()

        # get a handle to our specific multiclamp channel
        if executable is not None:
            self.mc = mc.getChannel(
                self.config['channelID'],
                multiprocess.proxy(self.mcUpdate, callSync='off'))
        else:
            self.mc = mc.getChannel(self.config['channelID'], self.mcUpdate)

        ## wait for first update..
        start = time.time()
        while self.mc.getState() is None:
            time.sleep(0.1)
            if time.time() - start > 10:
                raise Exception(
                    "Timed out waiting for first update from multi clamp commander."
                )

        print "Created MultiClamp device", self.config['channelID']

        ## set configured holding values
        if 'vcHolding' in self.config:
            self.holding['VC'] = self.config['vcHolding']
        if 'icHolding' in self.config:
            self.holding['IC'] = self.config['icHolding']

        ## Set up default MC settings for each mode, then leave MC in I=0 mode
        # look for 'defaults', followed by 'settings' (for backward compatibility)
        defaults = self.config.get('defaults',
                                   self.config.get('settings', None))
        for mode in ['IC', 'VC']:
            self.setMode(
                mode)  # Set mode even if we have no parameters to set;
            # this ensures that self.lastState is filled.
            if defaults is not None and mode in defaults:
                self.mc.setParams(defaults[mode])
        self.setMode('I=0')  ## safest mode to leave clamp in

        dm.declareInterface(name, ['clamp'], self)