diff --git a/pom.xml b/pom.xml index 7fca234..a889679 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,11 @@ pshell 1.14.0 + + ${project.groupId} + jcae + 2.9.7 + diff --git a/src/main/java/Scienta.java b/src/main/java/Scienta.java index e4018c2..087e62d 100644 --- a/src/main/java/Scienta.java +++ b/src/main/java/Scienta.java @@ -1,4 +1,5 @@ +import ch.psi.jcae.ChannelException; import ch.psi.pshell.device.AccessType; import ch.psi.pshell.device.ArrayCalibration; import ch.psi.pshell.device.CameraImageDescriptor; @@ -11,6 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import ch.psi.pshell.epics.*; +import java.util.concurrent.ExecutionException; +import java.util.logging.Logger; /** * Implementation of Scienta spectrometer analyser. @@ -19,11 +22,11 @@ public class Scienta extends AreaDetector { final ChannelInteger slices, frames; final ChannelDouble lowEnergy, centerEnergy, highEnergy, stepSize, stepTime, energyWidth; - final ChannelDoubleArray spectrum, image, extio; + final ChannelDoubleArray spectrum, image, extio, spectrumX; final ChannelDouble currentChannel, totalPoints; final ChannelDouble channelBegin, channelEnd, sliceBegin, sliceEnd; final ChannelString lensMode, acquisitionMode, passEnergy; - final ChannelInteger numChannels, numSlices; + final ChannelInteger numChannels, numSlices, totalDataPoints; final ChannelDouble acquisitionTime; final Stats[] stats; final String channelCtrl; @@ -61,12 +64,16 @@ public class Scienta extends AreaDetector { numChannels.setAccessType(AccessType.Read); numSlices = new ChannelInteger(name + " num slices", channelCtrl + ":SLICES_RBV", false); numSlices.setAccessType(AccessType.Read); - numChannels.addListener(new DeviceAdapter() { + totalDataPoints = new ChannelInteger(name + " total points", channelCtrl + ":TOTAL_DATA_POINTS_RBV", false); + totalDataPoints.setAccessType(AccessType.Read); + + totalDataPoints.addListener(new DeviceAdapter() { @Override public void onValueChanged(Device device, Object value, Object former) { try { if (value != null) { - spectrum.setSize((Integer) value); + spectrum.setSize(((Number) value).intValue()); + spectrumX.setSize(((Number) value).intValue()); } } catch (IOException ex) { getLogger().log(Level.WARNING, null, ex); @@ -92,7 +99,9 @@ public class Scienta extends AreaDetector { image.setAccessType(AccessType.Read); extio = new ChannelDoubleArray(name + " extio", channelCtrl + ":EXTIO", 8, -1, false); extio.setAccessType(AccessType.Read); - + spectrumX = new ChannelDoubleArray(name + " spectrumX", channelCtrl + ":CHANNEL_SCALE_RBV"); + spectrumX.setAccessType(AccessType.Read); + currentChannel = new ChannelDouble(name + " current channel", channelCtrl + ":CURRENT_CHANNEL_RBV", 0, false); currentChannel.setAccessType(AccessType.Read); totalPoints = new ChannelDouble(name + " total points", channelCtrl + ":TOTAL_POINTS_RBV", 0, false); @@ -100,8 +109,8 @@ public class Scienta extends AreaDetector { addChildren(new Device[]{slices, frames, lowEnergy, centerEnergy, highEnergy, stepSize, stepTime, energyWidth, - spectrum, image, extio, - currentChannel, totalPoints, + spectrum, image, extio, spectrumX, + currentChannel, totalPoints, totalDataPoints, channelBegin, channelEnd, sliceBegin, sliceEnd, passEnergy, lensMode, acquisitionMode, numChannels, numSlices, acquisitionTime @@ -125,7 +134,7 @@ public class Scienta extends AreaDetector { @Override protected double[] doRead() throws IOException, InterruptedException { - numChannels.getValue(); + totalDataPoints.getValue(); return super.doRead(); } @@ -137,7 +146,7 @@ public class Scienta extends AreaDetector { List channelRange = getChannelRange(); Double cb = channelRange.get(0); Double ce = channelRange.get(1); - scale = (ce - cb) / Math.max(numChannels.getValue() - 1, 1); + scale = (ce - cb) / Math.max(totalDataPoints.getValue() - 1, 1); offset = cb; } catch (Exception ex) { } @@ -155,8 +164,10 @@ public class Scienta extends AreaDetector { setCache(numChannels, 100); setCache(numSlices, 10); setCache(spectrum, new double[100]); + setCache(spectrumX, new double[100]); //TODO setCache(currentChannel, 0.0); setCache(totalPoints, 100.0); + setCache(totalDataPoints, 100); setCache(passEnergy, String.valueOf(PASS_ENERGY_VALUES[0])); setCache(lensMode, LensMode.Transmission.toString()); setCache(acquisitionMode, AcquisitionMode.Fixed.toString()); @@ -184,6 +195,7 @@ public class Scienta extends AreaDetector { stepSize.update(); stepTime.update(); totalPoints.update(); + totalDataPoints.update(); passEnergy.update(); lensMode.update(); acquisitionMode.update(); @@ -207,10 +219,12 @@ public class Scienta extends AreaDetector { stepSize.setMonitored(value); stepTime.setMonitored(value); totalPoints.setMonitored(value); + totalDataPoints.setMonitored(value); passEnergy.setMonitored(value); lensMode.setMonitored(value); acquisitionMode.setMonitored(value); acquisitionTime.setMonitored(value); + spectrumX.setMonitored(value); //channelBegin.setMonitored(value); //channelEnd.setMonitored(value); //sliceBegin.setMonitored(value); @@ -359,6 +373,17 @@ public class Scienta extends AreaDetector { } public double[] getSpectrumX() throws IOException, InterruptedException { + return spectrumX.read(); + /* + try { + //spectrumX = Epics.("NAPP-SCIENTA:cam1:CHANNEL_SCALE_RBV", size=int(scienta.getTotalDataPoints().read())) + return Epics.get(channelCtrl + ":CHANNEL_SCALE_RBV", double[].class, getTotalDataPoints().read()); + } catch (ChannelException | java.util.concurrent.TimeoutException | ExecutionException ex) { + throw new IOException(ex); + } + */ + + /* List range = getChannelRange(); Double begin = range.get(0); Double end = range.get(1); @@ -373,6 +398,7 @@ public class Scienta extends AreaDetector { x[i] = begin + step * i; } return x; + */ } //Direct register access @@ -412,6 +438,10 @@ public class Scienta extends AreaDetector { return spectrum; } + public ChannelDoubleArray getSpectrumScale() { + return spectrumX; + } + public ChannelDoubleArray getImage() { return image; } @@ -442,6 +472,13 @@ public class Scienta extends AreaDetector { public List getChannelRange() throws IOException, InterruptedException { ArrayList ret = new ArrayList<>(); + + double[] spectrumZ = getSpectrumX(); + if (spectrumZ.length>0){ + ret.add(spectrumZ[0]); + ret.add(spectrumZ[spectrumZ.length-1]); + } + /* //ret.add(getChannelBegin().getValue()); //ret.add(getChannelEnd().getValue()); switch (getAcquisitionMode()) { @@ -460,6 +497,7 @@ public class Scienta extends AreaDetector { break; } + */ return ret; } @@ -506,6 +544,10 @@ public class Scienta extends AreaDetector { return totalPoints; } + public ChannelInteger getTotalDataPoints() { + return totalDataPoints; + } + public ChannelDouble getCurrentChannel() { return currentChannel; }