Search in sources :

Example 1 with IMalcolmDevice

use of org.eclipse.scanning.api.malcolm.IMalcolmDevice in project gda-core by openGDA.

the class EditMappingStageDialog method findMappingStageOptions.

private void findMappingStageOptions() {
    // may be null if not configured for this beamline
    options = getService(MappingStageOptions.class);
    if (malcolmDeviceName.isPresent()) {
        try {
            final URI jmsURI = new URI(LocalProperties.getActiveMQBrokerURI());
            final IEventService eventService = getService(IEventService.class);
            IRunnableDeviceService runnableDeviceService = eventService.createRemoteService(jmsURI, IRunnableDeviceService.class);
            IMalcolmDevice malcolmDevice = (IMalcolmDevice) (IRunnableDevice<?>) runnableDeviceService.getRunnableDevice(malcolmDeviceName.get());
            List<String> availableAxes = new ArrayList<>(malcolmDevice.getAvailableAxes());
            List<String> associatedAxes = null;
            if (options != null) {
                // Currently these are not Malcolm related
                associatedAxes = options.getAssociatedAxes();
            }
            options = new MappingStageOptions();
            options.setFastAxes(availableAxes);
            options.setSlowAxes(availableAxes);
            if (associatedAxes != null)
                options.setAssociatedAxes(associatedAxes);
        } catch (Exception e) {
            MessageDialog.openError(getShell(), "", "Could not get available axes for malcolm device ''" + malcolmDeviceName.get() + "''");
        }
    }
}
Also used : IRunnableDeviceService(org.eclipse.scanning.api.device.IRunnableDeviceService) ArrayList(java.util.ArrayList) MappingStageOptions(uk.ac.diamond.daq.mapping.impl.MappingStageOptions) IMalcolmDevice(org.eclipse.scanning.api.malcolm.IMalcolmDevice) IEventService(org.eclipse.scanning.api.event.IEventService) URI(java.net.URI)

Example 2 with IMalcolmDevice

use of org.eclipse.scanning.api.malcolm.IMalcolmDevice in project gda-core by openGDA.

the class FocusScanSetupPage method getMalcolmAxes.

private List<String> getMalcolmAxes(IMalcolmModel malcolmModel) throws ScanningException {
    final String deviceName = malcolmModel.getName();
    final IMalcolmDevice malcolmDevice = (IMalcolmDevice) (IRunnableDevice<?>) getRunnableDeviceService().getRunnableDevice(deviceName);
    return malcolmDevice.getAvailableAxes();
}
Also used : IMalcolmDevice(org.eclipse.scanning.api.malcolm.IMalcolmDevice)

Example 3 with IMalcolmDevice

use of org.eclipse.scanning.api.malcolm.IMalcolmDevice in project gda-core by openGDA.

the class ProcessingSelectionWizardPage method getDetectorDatasetNameForMalcolm.

/**
 * Get the name of the dataset to use for the malcolm device with the given name. This is the
 * first dataset of type 'primary' in the {@link MalcolmTable} of the {@link MalcolmConstants#ATTRIBUTE_NAME_DATASETS}
 * attribute.
 * @param malcolmModel
 * @return
 */
private Optional<String> getDetectorDatasetNameForMalcolm(IMalcolmModel malcolmModel) {
    if (malcolmDetectorDatasetNames != null && malcolmDetectorDatasetNames.containsKey(malcolmModel.getName())) {
        return Optional.of(malcolmDetectorDatasetNames.get(malcolmModel.getName()));
    }
    Optional<String> datasetName = Optional.empty();
    try {
        final IRunnableDevice<IMalcolmModel> malcolmDevice = getRunnableDeviceService().getRunnableDevice(malcolmModel.getName());
        if (malcolmDevice.getDeviceState() != DeviceState.READY) {
            throw new ScanningException("The malcolm device is not ready. A scan may be running.");
        }
        try {
            // configure the malcolm device, puts it in 'Armed' state
            malcolmDevice.configure(malcolmModel);
            if (malcolmDevice instanceof IMalcolmDevice) {
                final MalcolmTable datasetsTable = ((IMalcolmDevice) malcolmDevice).getDatasets();
                if (datasetsTable != null) {
                    datasetName = getPrimaryDatasetNameForMalcolm(datasetsTable);
                }
            }
            if (datasetName.isPresent()) {
                // if we found the dataset name, cache it
                logger.debug("Got ''{}'' as dataset for processing for malcolm device ''{}''", datasetName.get(), malcolmModel.getName());
                if (malcolmDetectorDatasetNames == null) {
                    malcolmDetectorDatasetNames = new HashMap<>(4);
                }
                malcolmDetectorDatasetNames.put(malcolmModel.getName(), datasetName.get());
            } else {
                logger.error("Could not get primary dataset for malcolm device ''{}''. The dataset for the malcolm device may not be set correctly.", malcolmModel.getName());
            }
        } finally {
            // Reset the malcolm device back to the 'Ready' state
            malcolmDevice.reset();
        }
    } catch (Exception e) {
        logger.error("Could not get primary dataset for malcolm device: " + malcolmModel.getName(), e);
    }
    return datasetName;
}
Also used : MalcolmTable(org.eclipse.scanning.api.malcolm.MalcolmTable) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) IMalcolmDevice(org.eclipse.scanning.api.malcolm.IMalcolmDevice) URISyntaxException(java.net.URISyntaxException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) EventException(org.eclipse.scanning.api.event.EventException)

Aggregations

IMalcolmDevice (org.eclipse.scanning.api.malcolm.IMalcolmDevice)3 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 IRunnableDeviceService (org.eclipse.scanning.api.device.IRunnableDeviceService)1 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)1 EventException (org.eclipse.scanning.api.event.EventException)1 IEventService (org.eclipse.scanning.api.event.IEventService)1 MalcolmTable (org.eclipse.scanning.api.malcolm.MalcolmTable)1 ScanningException (org.eclipse.scanning.api.scan.ScanningException)1 MappingStageOptions (uk.ac.diamond.daq.mapping.impl.MappingStageOptions)1