Search in sources :

Example 21 with ScanningException

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

the class AreaDetectorRunnableDevice method run.

@Override
public void run(IPosition position) throws ScanningException, InterruptedException {
    setDeviceState(DeviceState.RUNNING);
    try {
        adDetector.collectData();
        adDetector.waitWhileBusy();
    } catch (Exception e) {
        setDeviceState(DeviceState.FAULT);
        throw new ScanningException("Acquiring from detector failed", e);
    }
    setDeviceState(DeviceState.ARMED);
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) DeviceException(gda.device.DeviceException) NexusException(org.eclipse.dawnsci.nexus.NexusException) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Example 22 with ScanningException

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

the class AreaDetectorRunnableDevice method write.

@Override
public boolean write(IPosition pos) throws ScanningException {
    if (firstPointInScan) {
        firstFrame();
        firstPointInScan = false;
    }
    try {
        // Get the data from the detector array plugin
        final Object image = adDetector.getNdArray().getImageData(imageDimensions[0] * imageDimensions[1]);
        // Create a dataset from the data
        final Dataset dataset = DatasetFactory.createFromObject(image);
        // Write the image data
        IScanSlice scanSlice = IScanRankService.getScanRankService().createScanSlice(pos, imageDimensions);
        SliceND sliceND = new SliceND(data.getShape(), data.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
        data.setSlice(null, dataset, sliceND);
        // Write the total data
        scanSlice = IScanRankService.getScanRankService().createScanSlice(pos);
        sliceND = new SliceND(total.getShape(), total.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
        total.setSlice(null, DatasetFactory.createFromObject(dataset.sum()), sliceND);
    } catch (Exception e) {
        setDeviceState(DeviceState.FAULT);
        throw new ScanningException("Getting the data from the detector failed", e);
    }
    setDeviceState(DeviceState.ARMED);
    // saying I failed?
    return true;
}
Also used : ILazyWriteableDataset(org.eclipse.january.dataset.ILazyWriteableDataset) Dataset(org.eclipse.january.dataset.Dataset) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IScanSlice(org.eclipse.scanning.api.scan.rank.IScanSlice) SliceND(org.eclipse.january.dataset.SliceND) DeviceException(gda.device.DeviceException) NexusException(org.eclipse.dawnsci.nexus.NexusException) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Example 23 with ScanningException

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

the class AreaDetectorRunnableDevice method scanStart.

/**
 * add call to {@link ADDetector#atScanStart()} so decorators in collection strategy work to save detector state.
 */
@Override
@ScanStart
public void scanStart(ScanInformation info) throws ScanningException {
    super.scanStart(info);
    try {
        adDetector.atScanStart();
        firstPointInScan = true;
    } catch (DeviceException e) {
        throw new ScanningException("Error calling atScanStart", e);
    }
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) DeviceException(gda.device.DeviceException) ScanStart(org.eclipse.scanning.api.annotation.scan.ScanStart)

Example 24 with ScanningException

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

the class AreaDetectorRunnableDeviceWaitForArray method write.

@Override
public boolean write(IPosition pos) throws ScanningException {
    try {
        final long startTime = System.currentTimeMillis();
        int currentCounter = getArrayCounter();
        logger.trace("write(): currentCounter = {}, timeout = {}", currentCounter, timeout);
        while (currentCounter <= arrayCounter) {
            final long elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
            if (elapsedTime >= timeout) {
                throw new ScanningException(String.format("Wait for array counter timed out after %d s", elapsedTime));
            }
            logger.debug("Waiting {} ms for array data", writeDelay);
            Thread.sleep(writeDelay);
            currentCounter = getArrayCounter();
            logger.trace("write(): currentCounter = {}", currentCounter);
        }
    } catch (Exception e) {
        final String message = "Exception waiting for array counter to increment";
        logger.error(message, e);
        throw new ScanningException(message, e);
    }
    return super.write(pos);
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Example 25 with ScanningException

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

the class MScanSubmitterTest method rejectsTypeWithNoMappedProcessor.

@Test
public void rejectsTypeWithNoMappedProcessor() throws Exception {
    Object[] arr = { scannable, new ScanningException() };
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("Your command contains an invalid argument at position 1");
    builder.buildAndSubmitBlockingScanRequest(arr);
    verify(eventSubscriber, never()).addListener(any(IScanListener.class));
    verify(submitter, never()).blockingSubmit(any(ScanBean.class));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) ScanningException(org.eclipse.scanning.api.scan.ScanningException) Test(org.junit.Test)

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