Beispiel #1
0
    def set_file_writing(self, writing):
        self.file_writing = writing
        # send command to Odin Data
        command = "config/hdf/file/path"
        request = ApiAdapterRequest(self.file_dir, content_type="application/json")
        self.adapters["fp"].put(command, request)

        command = "config/hdf/file/name"
        request.body = self.file_name
        self.adapters["fp"].put(command, request)

        command = "config/hdf/write"
        request.body = "{}".format(writing)
        self.adapters["fp"].put(command, request)
Beispiel #2
0
    def monitor_fem_progress(self):
        """Check fem hardware progress.

        Busy either:
        -Initialising from cold (2 fudge frames)
        -Normal initialisation
        -Waiting for data collection to complete, either single/multi run
        """
        if (self.fem.hardware_busy):
            # Still sending data
            IOLoop.instance().call_later(0.5, self.monitor_fem_progress)
            return
        else:
            # Current collection completed; Do we have all the requested frames?
            if self.extended_acquisition:
                if (self.frames_already_acquired < self.number_frames):
                    # Need further bias window(s)
                    IOLoop.instance().add_callback(self.acquisition)
                    return

        # Issue reset to summed_image
        command = "config/summed_image/reset_image"
        request = ApiAdapterRequest(self.file_dir,
                                    content_type="application/json")
        request.body = "{}".format(1)
        self.adapters["fp"].put(command, request)

        rc = self.daq.prepare_odin()
        if not rc:
            message = "Prepare Odin failed!"
            self.fem._set_status_error(message)
            self.status_error = message

        self.reset_state_variables()
Beispiel #3
0
    def acquisition(self, put_data=None):
        """Instruct DAQ and FEM to acquire data."""
        # Synchronise first_initialisation status (i.e. collect 2 fudge frames) with FEM
        if self.first_initialisation:
            self.first_initialisation = self.fem.first_initialisation
        else:
            # Clear (any previous) daq error
            self.daq.in_error = False

        if self.extended_acquisition is False:
            if self.daq.in_progress:
                logging.warning("Cannot Start Acquistion: Already in progress")
                self.fem._set_status_error(
                    "Cannot Start Acquistion: Already in progress")
                return

        self.total_delay = 0
        self.number_frames_to_request = self.number_frames

        if self.fem.bias_voltage_refresh:
            # Did the acquisition coincide with bias dead time?
            if self.bias_blocking_acquisition:
                IOLoop.instance().call_later(0.1, self.acquisition)
                return

            # Work out how many frames can be acquired before next bias refresh
            time_into_window = time.time() - self.bias_init_time
            time_available = self.fem.bias_refresh_interval - time_into_window

            if time_available < 0:
                IOLoop.instance().call_later(0.09, self.acquisition)
                return

            frames_before_bias = self.fem.frame_rate * time_available
            number_frames_before_bias = int(round(frames_before_bias))

            self.number_frames_to_request = self.number_frames - self.frames_already_acquired

            # Can we obtain all required frames within current bias window?
            if (number_frames_before_bias < self.number_frames_to_request):
                # Need >1 bias window to fulfil acquisition
                self.extended_acquisition = True
                self.number_frames_to_request = number_frames_before_bias

            self.total_delay = time_available + self.fem.bias_voltage_settle_time + \
                self.fem.time_refresh_voltage_held

        # # TODO: Remove once Firmware made to reset on each new acquisition
        # # TODO: WILL BE NON 0 VALUE IN THE FUTURE - TO SUPPORT BIAS REFRESH INTV
        # #       BUT, if nonzero then won't FP's Acquisition time out before processing done?????
        # #
        # Reset Reorder plugin's frame_number (to current frame number, for multi-window acquire)
        command = "config/reorder/frame_number"
        request = ApiAdapterRequest(self.file_dir,
                                    content_type="application/json")
        request.body = "{}".format(self.frames_already_acquired)
        self.adapters["fp"].put(command, request)
        # TODO: To be removed once firmware updated? FP may be slow to process frame_number reset
        time.sleep(0.5)

        # Reset histograms, call DAQ's prepare_daq() once per acquisition
        if self.initial_acquisition:
            # Issue reset to histogram
            command = "config/histogram/reset_histograms"
            request = ApiAdapterRequest(self.file_dir,
                                        content_type="application/json")
            request.body = "{}".format(1)
            self.adapters["fp"].put(command, request)

            self.daq_target = time.time()
            self.daq.prepare_daq(self.number_frames)
            self.initial_acquisition = False
            # Acquisition (whether single/multi-run) starts here
            self.acquisition_in_progress = True

        # Wait for DAQ (i.e. file writer) to be enabled before FEM told to collect data
        # IOLoop.instance().call_later(0.1, self.await_daq_ready)
        IOLoop.instance().add_callback(self.await_daq_ready)