Example #1
0
    def __init__(self, mnemonic, address):
        """
        **Constructor**
        See :class:`py4syn.epics.StandardDevice`

        Parameters
        ----------
        mnemonic : `string`
            Camera mnemonic
        address : `tuple`
            Camera host server Internet address
        """
        super().__init__(mnemonic)
        self.socket = socket(AF_INET, SOCK_STREAM)
        self.socket.connect(address)
        self.counting = False
        self.timer = Timer(1)
        self.subScan = False
        self.subScanStep = 0

        # Force clearing busy and error flags. Both busy and error flags
        # May get stuck after exceptional conditions.
        try:
            state = self.waitWhile(self.STATE_MASK_BUSY, self.URGENT_TIMEOUT)
        except RuntimeError:
            self.socket.send(b'abort\n')

            try:
                self.setState(0, self.URGENT_TIMEOUT)
            except RuntimeError as e:
                self.socket.close()
                raise e from None
Example #2
0
    def stateRequest(self, request, timeout=TIMEOUT):
        """
        Helper method used to get or set camera state.

        Parameters
        ----------
        request : `string`
            Command to be passed to the camera
        timeout : `float`
            Time to wait for camera answer

        Returns
        -------
        `int`
        """

        self.socket.send(request)
        timer = Timer(timeout)

        r = b''
        while b'\n' not in r and timer.wait(self.socket):
            r += self.socket.recv(1)

        if timer.expired():
            raise RuntimeError('Camera is not answering')

        r = r.strip(b'\x00\n')

        return int(r, 0)
Example #3
0
    def __init__(self,
                 mnemonic,
                 address,
                 shutterType,
                 shutter=None,
                 shutterReadBack=None):
        """
        **Constructor**
        See :class:`py4syn.epics.StandardDevice`

        Parameters
        ----------
        mnemonic : `string`
            Camera mnemonic
        address : `tuple`
            Camera host server Internet address
        shutterType : `string`
            The type of software controlled shutter. The type can be "simple", "toggle"
            or "null". The null shutter completely disables software controlled shutter.
            The simple shutter is an EPICS PV that must be set to 0 to open the shutter
            and 1 to close the shutter. The toggle shutter uses two PVs, one that
            changes the shutter state whenever written to and another to read back the
            current shutter state.
        shutter :  `string`
            The shutter PV name. Only meaningful if the shutter type is not null.
        shutterReadBack : `string`
            The toggle shutter read back PV.
        """
        super().__init__(mnemonic)
        self.socket = socket(AF_INET, SOCK_STREAM)
        self.socket.connect(address)
        self.counting = False
        self.timer = Timer(1)
        self.subScan = False
        self.subScanStep = 0

        shutterName = mnemonic + '_shutter'

        if shutterType == 'toggle':
            self.shutter = ToggleShutter(shutterName, shutter, shutterReadback)
        elif shutterType == 'simple':
            self.shutter = SimpleShutter(shutterName, shutter)
        else:
            self.shutter = NullShutter(shutterName)

        self.shutter.close(wait=True)

        # Force clearing busy and error flags. Both busy and error flags
        # May get stuck after exceptional conditions.
        try:
            state = self.waitWhile(self.STATE_MASK_BUSY, self.URGENT_TIMEOUT)
        except RuntimeError:
            self.socket.send(b'abort\n')

            try:
                self.setState(0, self.URGENT_TIMEOUT)
            except RuntimeError as e:
                self.socket.close()
                raise e from None
Example #4
0
    def __init__(self,
                 mnemonic,
                 pv=None,
                 responseTimeout=15,
                 output="./out",
                 numPoints=1044,
                 mcas=False):
        """Constructor
        responseTimeout : how much time to wait qe65000 answer
        numPoints : how many points are collected each time
        """
        super().__init__(mnemonic, numPoints, output, 'ocean')
        self.acquireChanged = Event()
        self.acquiring = False

        try:
            # determines the start of counting
            self.pvStart = PV(pv + ":Acquire")
            # determines mode of Acquisition (Single,Continous, Dark Spectrum)
            self.pvAcquireMode = PV(pv + ":AcquisitionMode")

            # use darkcorrection
            self.pvDarkCorrection = PV(pv + ":ElectricalDark")

            # spectrum
            self.pvSpectrum = PV(pv + ":Spectra")
            self.pvSpectrumCorrected = PV(pv + ":DarkCorrectedSpectra")

            # set Acquire Time
            self.pvAcquireTime = PV(pv + ":SetIntegration")

            # integration Time
            self.pvTime = PV(pv + ":IntegrationTime:Value")

            # control the end of acquire process
            self.pvAcquire = PV(pv + ":Acquiring")
            self.pvAcquire.add_callback(self.statusChange)

            # acquisition mode
            self.pvAcMode = PV(pv + ":AcquisitionMode")
            # set to single mode
            self.pvAcMode.put("Single")

            # axis Spectra
            pvAxis = PV(pv + ":SpectraAxis")
            self.axis = pvAxis.get(as_numpy=True)[:self.numPoints]

            # regions of interest
            self.ROIS = []

            self.mcas = mcas

            self.responseTimeout = responseTimeout
            self.timer = Timer(self.responseTimeout)
        except TypeError:
            raise RuntimeError('PV not found')
        except ValueError:
            raise RuntimeError('Device is offline')
Example #5
0
    def __init__(self,
                 mnemonic,
                 numberOfChannels=4,
                 numberOfRois=32,
                 pv=None,
                 dxpType="mca",
                 responseTimeout=15,
                 output="./out",
                 numPoints=2048):
        """ Constructor
        responseTimeout : how much time to wait dxp answer
        imageDeep : how many points are collected each time
        """
        super().__init__(mnemonic, numPoints, output, dxpType)

        self.dxpType = dxpType
        self.acquireChanged = Event()
        self.acquiring = False

        # determines the start of counting
        self.pvDxpEraseStart = PV(pv + ":EraseStart.VAL")
        # determines mode of counting (Live Time, Real Time, ...)
        self.pvDxpPresetMode = PV(pv + ":PresetMode.VAL")

        self.pvDxpStop = PV(pv + ":StopAll.VAL")
        # store all channels
        self.pvDxpChannels = []
        # store ROIs
        self.pvDxpRois = []

        # store Acquire Time for each channel
        self.pvDxpAcquireTime = []
        self.pvDxpRealTime = []

        for c in range(0, numberOfChannels):
            # store each channel
            self.pvDxpChannels.append(PV(pv + ":" + dxpType + str(c + 1)))
            # for each channel store the PV for AcquireTime
            self.pvDxpAcquireTime.append(
                PV(pv + ":" + dxpType + "%d.PLTM" % (c + 1)))
            # real time
            self.pvDxpRealTime.append(
                PV(pv + ":" + dxpType + "%d.ERTM" % (c + 1)))
            self.pvDxpRois.append([])
            # storeing each ROI in your channel
            for r in range(0, numberOfRois):
                self.pvDxpRois[c].append(
                    PV(pv + ":" + dxpType + str(c + 1) + '.R' + str(r)))

        self.pvDxpAcquire = PV(pv + ":Acquiring")
        self.pvDxpAcquire.add_callback(self.statusChange)
        self.channels = numberOfChannels
        self.rois = numberOfRois

        self.responseTimeout = responseTimeout
        self.timer = Timer(self.responseTimeout)
Example #6
0
    def setCountTime(self, t):
        """
        Sets the image acquisition time.

        Parameters
        ----------
        t : `float`
            Acquisition time
        """
        self.timer = Timer(t)
Example #7
0
    def setCountTime(self, t):
        """
        Sets the image acquisition time.

        Parameters
        ----------
        t : `float`
            Acquisition time
        """
        self.pvAcquireTime.put(t, wait=True)
        self.timer = Timer(t + self.RESPONSE_TIMEOUT)
Example #8
0
    def setCountTime(self, time):
        """
        Method to set the count time of a scaler device.

        Parameters
        ----------
        time : `float`
            Count time to set to scaler device .

        Returns
        -------
        out : None
        """
        self.pvTime.put(time, wait=True)
        self.timer = Timer(time + self.responseTimeout)
Example #9
0
    def setCountTime(self, time):
        """
        Method to set the count time of a scaler device.

        Parameters
        ----------
        time : `float`
            Count time to set to scaler device .

        Returns
        -------
        out : None
        """
        for i in range(0, self.channels):
            self.pvDxpAcquireTime[i].put(time, wait=True)
        self.timer = Timer(time + self.responseTimeout)
Example #10
0
 def waitForIdle(self):
     """
     Blocks until the camera server is completely idle. This is required because
     the camera and the server are slow and certain operations, in particular,
     multiple sequential acquisitions would fail without waiting for some
     time. Acquiring two images and dezingering them only works with
     this method being called between the acquisitions.
     """
     # Minimum reliable wait time between two acquisitions was empirically found
     # to be 1.3 seconds. For wait times smaller than this, the camera server may
     # return it's ready even though it's not.
     timer = Timer(1.3)
     self.waitWhile(self.STATE_MASK_ACQUIRING | self.STATE_MASK_READING
                    | self.STATE_MASK_CORRECTING | self.STATE_MASK_WRITING
                    | self.STATE_MASK_DEZINGERING | self.STATE_MASK_BUSY)
     timer.wait()
Example #11
0
    def waitWhileOrUntil(self, condition, timeout=TIMEOUT, until=False):
        """
        Helper method that implements :meth:`waitWhile` and :meth:`waitUntil`
        """

        state = self.getState(timeout)
        timer = Timer(timeout)

        while until ^ bool(state & condition) and timer.check():
            state = self.getState(timeout)

            if state & self.STATE_MASK_ERROR:
                raise RuntimeError('Camera returned error: %x' % state)

        if timer.expired():
            raise RuntimeError('Camera got stuck condition: %x, state: %x' %
                               (condition, state))
Example #12
0
    def wait(self):
        """
        Blocks until the requested temperature is achieved.
        """
        if not self.pending:
            return

        # Waiting is done in two steps. First step waits until the IOC deasserts
        # the pending flag to indicate a complete operation. Second step waits util the
        # measured temperature reaches the requested temperature.
        ca.flush_io()
        self.done.wait()

        self.newTemperature.clear()
        timeout = Timer(7)
        while self.getValue() != self.requestedValue and timeout.check():
            self.newTemperature.wait(1)
            self.newTemperature.clear()
Example #13
0
    def __init__(self, mnemonic, pv):
        """
        **Constructor**
        See :class:`py4syn.epics.StandardDevice`

        Parameters
        ----------
        mnemonic : `string`
            A mnemonic for the camera
        pv : `string`
            Base name of the EPICS process variable
        """
        super().__init__(mnemonic)
        self.acquireChanged = Event()
        self.acquiring = False
        self.pvAcquire = PV(pv + ':Acquire')
        self.pvAcquire.add_callback(self.statusChange)

        caput(pv + ':FileTemplate', '%s%s\0')
        caput(pv + ':FilePath', '\0')

        self.pvAcquireTime = PV(pv + ':AcquireTime')
        self.pvAcquirePeriod = PV(pv + ':AcquirePeriod')
        self.pvFilePath = PV(pv + ':FilePath')
        self.pvFileName = PV(pv + ':FileName')
        self.pvFileTemplate = PV(pv + ':FileTemplate')
        self.pvThreshold = PV(pv + ':ThresholdEnergy')
        self.pvBeamX = PV(pv + ':BeamX')
        self.pvBeamY = PV(pv + ':BeamY')
        self.pvWavelength = PV(pv + ':Wavelength')
        self.pvStartAngle = PV(pv + ':StartAngle')
        self.pvAngleIncr = PV(pv + ':AngleIncr')
        self.pvDetDist = PV(pv + ':DetDist')
        self.pvNumImages = PV(pv + ':NumImages')
        self.pvDelayTime = PV(pv + ':DelayTime')
        self.pvTriggerMode = PV(pv + ':TriggerMode')
        self.pvDet2Theta = PV(pv + ':Det2theta')
        self.pvCamserverConnectStatus = PV(pv + ':CamserverAsyn.CNCT')
        self.pvLastFileName = PV(pv + ":FullFileName_RBV")

        self.timer = Timer(self.RESPONSE_TIMEOUT)