Search in sources :

Example 16 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class StageMoveHandler method moveTo.

private void moveTo(final double xLocation, final double yLocation, final Double associatedLocation) {
    Map<String, Object> position = getPositionMap(xLocation, yLocation, associatedLocation);
    String moveSummary = summarise(position);
    // request confirmation to move
    boolean userConfirmedMove = confirmMove("Go here?", moveSummary);
    if (!userConfirmedMove)
        return;
    // Do the move
    try {
        getPositioner().setPosition(new MapPosition(position));
    } catch (ScanningException e) {
        logger.error("Could not perform stage move", e);
    } catch (InterruptedException interrupted) {
        logger.error("Stage move interrupted!", interrupted);
        Thread.currentThread().interrupt();
    }
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) MapPosition(org.eclipse.scanning.api.points.MapPosition)

Example 17 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class NexusSlitsWrapper method abort.

@Override
public void abort() throws ScanningException, InterruptedException {
    // Must catch if either Scannable threw an exception but want to request both stop.
    StringBuilder sb = new StringBuilder();
    Exception cachedException = null;
    for (Scannable scan : Arrays.asList(x_gap, y_gap)) {
        try {
            scan.stop();
        } catch (Exception e) {
            // If both Scannables except it's probably the same exception
            cachedException = e;
            sb.append(String.format("%s threw Exception %s ", scan.getName(), e.getMessage()));
        }
    }
    if (cachedException != null) {
        throw new ScanningException("Device exception while stopping scannable(s) " + sb.toString(), cachedException);
    }
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) AbstractScannable(org.eclipse.scanning.api.AbstractScannable) Scannable(gda.device.Scannable) DeviceException(gda.device.DeviceException) NexusException(org.eclipse.dawnsci.nexus.NexusException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) DatasetException(org.eclipse.january.DatasetException)

Example 18 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class NexusSlitsWrapper method setPosition.

@Override
public DeviceValueMultiPosition setPosition(DeviceValueMultiPosition value, IPosition position) throws ScanningException {
    logger.debug("setPosition({}, {}) called on {}", value, position, getName());
    if (value != null) {
        logger.warn("non null setPosition() not expected on {}, ignoring...", getName());
    }
    if (position != null) {
        try {
            DeviceValueMultiPosition currentLocation = getPosition();
            write(value, currentLocation, position);
            return currentLocation;
        } catch (DatasetException e) {
            throw new ScanningException("Could not set position of scannable: " + getName(), e);
        }
    }
    return null;
}
Also used : DeviceValueMultiPosition(org.eclipse.scanning.api.event.scan.DeviceValueMultiPosition) ScanningException(org.eclipse.scanning.api.scan.ScanningException) DatasetException(org.eclipse.january.DatasetException)

Example 19 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class ScannableNexusWrapper method setPosition.

@Override
public Object setPosition(Object value, IPosition scanPosition) throws ScanningException {
    try {
        final Scannable scannable = getScannable();
        if (value != null) {
            final int index = (scanPosition == null ? -1 : scanPosition.getIndex(getName()));
            final IPosition position = new Scalar<Object>(getName(), index, value);
            positionDelegate.firePositionWillPerform(position);
            logger.debug("Moving scannable {} to position {} at {}", scannable.getName(), value, scanPosition);
            scannable.moveTo(value);
            positionDelegate.firePositionPerformed(getLevel(), position);
        } else {
            logger.debug("Ignoring request to move scannable {} to position {} at {}", scannable.getName(), value, scanPosition);
        }
        if (scanPosition != null && getScannableNexusDevice(false) != null) {
            // It stops it being read again.
            return getScannableNexusDevice(false).writePosition(value, scanPosition);
        }
    } catch (Exception e) {
        throw new ScanningException("Could not set position of scannable " + getName(), e);
    }
    // new position.
    return null;
}
Also used : IPosition(org.eclipse.scanning.api.points.IPosition) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IScannable(org.eclipse.scanning.api.IScannable) AbstractScannable(org.eclipse.scanning.api.AbstractScannable) Scannable(gda.device.Scannable) DeviceException(gda.device.DeviceException) NexusException(org.eclipse.dawnsci.nexus.NexusException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) Scalar(org.eclipse.scanning.api.points.Scalar)

Example 20 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class CalibrationFrameCollector method configureCollection.

@Override
void configureCollection(ScanModel model) throws ScanningException {
    // If no detector is set for the "main" scan, we can't do anything here
    if (model.getDetectors().isEmpty()) {
        throw new ScanningException("No detector selected for scan - cannot collect calibration frame");
    }
    // At this point in the scan, the detector models directly in the ScanModel are not up-to-date, especially as
    // regards their exposure time. However, the models in the ScanRequest are correct, so copy the exposure
    // time from there.
    final IRunnableDevice<? extends IDetectorModel> mainScanDetector = model.getDetectors().get(0);
    final String mainScanDetectorName = mainScanDetector.getName();
    final IDetectorModel modelFromRequest = model.getBean().getScanRequest().getDetectors().get(mainScanDetectorName);
    if (modelFromRequest == null) {
        logger.error("Cannot find detector model for {}", mainScanDetectorName);
        return;
    }
    final double exposureTime = modelFromRequest.getExposureTime();
    // If no detector has been explicitly configured, use the "main scan" detector
    final IRunnableDevice<? extends IDetectorModel> acquisitionDetector = getSnapshotDetector(mainScanDetector);
    logger.debug("Setting exposure time on {} to {}", acquisitionDetector.getName(), exposureTime);
    var frameRequestDocument = new FrameRequestDocument.Builder().withExposure(exposureTime).withName(acquisitionDetector.getName()).withMalcolmDetectorName(getMalcolmDetectorName(acquisitionDetector)).build();
    setFrameRequestDocument(frameRequestDocument);
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Aggregations

ScanningException (org.eclipse.scanning.api.scan.ScanningException)41 DeviceException (gda.device.DeviceException)13 NexusException (org.eclipse.dawnsci.nexus.NexusException)7 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)4 EventException (org.eclipse.scanning.api.event.EventException)4 Scannable (gda.device.Scannable)3 CAException (gov.aps.jca.CAException)3 TimeoutException (gov.aps.jca.TimeoutException)3 DatasetException (org.eclipse.january.DatasetException)3 Dataset (org.eclipse.january.dataset.Dataset)3 ILazyWriteableDataset (org.eclipse.january.dataset.ILazyWriteableDataset)3 SliceND (org.eclipse.january.dataset.SliceND)3 IScanSlice (org.eclipse.scanning.api.scan.rank.IScanSlice)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AbstractScannable (org.eclipse.scanning.api.AbstractScannable)2