Exemple #1
0
    def __newScan(self, scanParams):
        if DEBUG: print("SpecScanA.__newScan", scanParams)

        if not scanParams:
            if self.scanning:
                # receive 0 when scan ends normally
                self.__status = 'ready'
                self.scanFinished()
            return

        if not self.ready:
            # a new scan was started before the old one completed
            # lets provide an opportunity to clean up
            self.scanAborted()

        self.__status = 'scanning'

        self.scanParams = simple_eval(scanParams)

        if not isinstance(self.scanParams, dict):
            return

        self.newScan(self.scanParams)

        self.scanCounterMne = self.scanParams.get('counter')
        if (not self.scanCounterMne) or self.scanCounterMne == '?':
            log.error("No counter selected for scan.")
            self.scanCounterMne = None
            return

        self.scanStarted()  # A.B
Exemple #2
0
def SpecArray(data, datatype = ARRAY_CHAR, rows = 0, cols = 0):

    if isinstance(data, SpecArrayData):
        # create a SpecArrayData from a SpecArrayData ("copy" constructor)
        return SpecArrayData(data.data, data.type, data.shape)

    if datatype == ARRAY_STRING:
        # a list of strings
        newArray = filter(None, [x != chr(0) and x or None for x in data.split(chr(0))])
        return newArray
    else:
        newArray = None

    if isinstance(data,numpy.ndarray) :
        # convert from a Num* array to a SpecArrayData instance
        # (when you send)
        if len(data.shape) > 2:
            raise SpecArrayError("Spec arrays cannot have more than 2 dimensions")

        try:
            if type(data) == numpy.ndarray:
                numtype = data.dtype.type
                datatype = NUM_TO_SPEC[numtype]
            else:
                numtype = data.typecode()
                datatype = NUM_TO_SPEC[numtype]
        except KeyError:
            data = ''
            datatype = ARRAY_CHAR
            rows = 0
            cols = 0
            log.error("Numerical type '%s' not supported" , numtype)
        else:
            if len(data.shape) == 2:
                rows, cols = data.shape
            else:
                rows, cols = 1, data.shape[0]
            data = data.tostring()

        newArray = SpecArrayData(data, datatype, (rows, cols))
    else:
        # return a new Num* array from data
        # (when you receive)
        try:
            numtype = SPEC_TO_NUM[datatype]
        except:
            raise SpecArrayError('Invalid Spec array type')
        else:
            if is_python3(): 
                newArray = numpy.frombuffer(data, dtype=numtype)
            else:
                newArray = numpy.fromstring(data, dtype=numtype)

            if rows==1:
              newArray.shape = (cols, )
            else:
              newArray.shape = (rows, cols)

    return newArray
    def send_msg_func(self, cmd):
        """Send a command message to the remote Spec server using the new 'func' feature

        Arguments:
        cmd -- command string
        """
        if self.serverVersion < 3:
            log.error(
                'Cannot execute command in Spec : feature is available since Spec server v3 only'
            )
        else:
            if self.isSpecConnected():
                self.__send_msg_no_reply(
                    SpecMessage.msg_func(cmd, version=self.serverVersion))
            else:
                raise SpecClientNotConnectedError
Exemple #4
0
    def move(self, absolutePosition):
        """Move the motor to the required position

        Arguments:
        absolutePosition -- position to move to
        """
        if not isinstance(absolutePosition, float) and not isinstance(
                absolutePosition, int):
            log.error("Cannot move %s: position '%s' is not a number",
                      self.specName, absolutePosition)

        self.__changeMotorState(MOVESTARTED)

        c = self.connection.getChannel(self.chanNamePrefix % 'start_one')

        c.write(absolutePosition)
    def send_msg_func_with_return(self, cmd):
        """Send a command message to the remote Spec server using the new 'func' feature, and return the reply id.

        Arguments:
        cmd -- command string
        """
        if self.serverVersion < 3:
            log.error(
                'Cannot execute command in Spec : feature is available since Spec server v3 only'
            )
        else:
            if self.isSpecConnected():
                try:
                    caller = sys._getframe(1).f_locals['self']
                except KeyError:
                    caller = None

                message = SpecMessage.msg_func_with_return(
                    cmd, version=self.serverVersion)
                return self.__send_msg_with_reply(replyReceiverObject=caller,
                                                  *message)
            else:
                raise SpecClientNotConnectedError
    def error(self, error):
        """Emit the 'error' signal when the remote Spec version signals an error."""
        log.error('Error from Spec: %s', error)

        SpecEventsDispatcher.emit(self, 'error', (error, ))