diff --git a/pom.xml b/pom.xml index e2958d6..ca39486 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 ch.psi prosilica - 1.0.2 + 1.0.3 jar UTF-8 diff --git a/src/main/java/ch/psi/pshell/prosilica/Prosilica.java b/src/main/java/ch/psi/pshell/prosilica/Prosilica.java index 2891154..d6b972f 100644 --- a/src/main/java/ch/psi/pshell/prosilica/Prosilica.java +++ b/src/main/java/ch/psi/pshell/prosilica/Prosilica.java @@ -115,7 +115,7 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { if (hasCamera(uid)){ openCamera(uid); writePars(); - start(); + start(); setState(State.Ready); getLogger().info("Successfully restarted camera"); } @@ -195,6 +195,7 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { writePars(); setState(State.Ready); camera.initialize(); + start(); } catch (IOException ex) { getLogger().warning("Error opening the camera: " + ex.getMessage()); throw ex; @@ -204,10 +205,15 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { @Override protected void doSetMonitored(boolean value) { try { + setTimeout(-1); if (value) { - start(); + writeParameter("AcquisitionMode", "Continuous"); + if (Pv.CommandRun(handle, "AcquisitionStart") != Pv.tError.eSuccess) { + throw new IOException("Error starting acquisition"); + } + setTimeout(10000); } else { - stop(); + writeParameter("AcquisitionMode", "SingleFrame"); } } catch (Exception ex) { getLogger().log(Level.WARNING, null, ex); @@ -223,10 +229,6 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { synchronized(instances){ instances.remove(this); } - try { - stop(); - } catch (Exception ex) { - } try { closeCamera(); } catch (Exception ex) { @@ -306,16 +308,26 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { break; } } - - if (Pv.CommandRun(handle, "AcquisitionStart") != Pv.tError.eSuccess) { - throw new IOException("Error startic acquisition"); + doSetMonitored(isMonitored()); + started = true; + } + + + @Override + protected void doUpdate() throws IOException, InterruptedException { + if ("SingleFrame".equals(readParameter("AcquisitionMode"))){ + if (Pv.CommandRun(handle, "AcquisitionStart") != Pv.tError.eSuccess) { + throw new IOException("Error starting acquisition"); + } } - started = true; - setTimeout(10000); } public void stop() throws IOException { assertInitialized(); + doStop(); + } + + protected void doStop() throws IOException { setTimeout(-1); started = false; if (isStreaming()) { @@ -323,7 +335,7 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { Pv.CaptureQueueClear(handle); Pv.CaptureEnd(handle); } - } + } public boolean isStarted() { return started; @@ -448,7 +460,7 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { if (handle != null) { getLogger().info("Close camera " + String.valueOf(this.currentUid)); try { - stop(); + doStop(); } catch (Exception ex) { getLogger().log(Level.WARNING, null, ex); } @@ -921,12 +933,15 @@ public class Prosilica extends SourceBase implements EmbeddedCameraSource { String acquisitionMode; switch (value) { case Continuous: + Prosilica.this.setMonitored(true); acquisitionMode = "Continuous"; break; case Single: + Prosilica.this.setMonitored(false); acquisitionMode = "SingleFrame"; break; case Multiple: + Prosilica.this.setMonitored(false); acquisitionMode = "MultiFrame"; break; default: