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();
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations