Permalink
Browse files

When a RLE-enabled capture was ongoing, the cancel acquisition didn't…

… finish properly. This won't work however when a basic trigger is set which not yet fired. It appears that advanced triggers should work.
  • Loading branch information...
1 parent 1c6f05e commit 6d8326ffcf7709b7575d1cdc4b53f5bd90b0fe80 @jawi committed Dec 5, 2011
@@ -36,10 +36,15 @@
/**
* Signals that the current acquisition should be cancelled.
*
+ * @param aDevice
+ * the device from which data should be acquired, cannot be
+ * <code>null</code>;
+ * @throws IOException
+ * in case of I/O problems during the acquisition of data;
* @throws IllegalStateException
* in case no acquisition is in progress.
*/
- public void cancelAcquisition() throws IllegalStateException;
+ public void cancelAcquisition( Device aDevice ) throws IOException, IllegalStateException;
/**
* Returns whether or not this device controller is acquiring data.
@@ -53,13 +58,13 @@
/**
* Acquires data from the given device.
*
- * @param aDeviceController
- * the device controller from which data should be acquired, cannot
- * be <code>null</code>;
+ * @param aDevice
+ * the device from which data should be acquired, cannot be
+ * <code>null</code>;
* @throws IOException
* in case of I/O problems during the acquisition of data;
* @throws IllegalArgumentException
* in case the given device was <code>null</code>.
*/
- void acquireData( Device aDeviceController ) throws IOException;
+ void acquireData( Device aDevice ) throws IOException;
}
@@ -21,35 +21,17 @@
package nl.lxtreme.ols.api.devices;
-import java.io.*;
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.task.*;
/**
- * Denotes a device that we can talk to by calling {@link #call()} on it. The
- * implementation of that method should do all necessary tasks to acquire data
- * from the device and return that data in the form of an
+ * Denotes an acquisition task that we can talk to by calling {@link #call()} on
+ * it. The implementation of that method should do all necessary tasks to
+ * acquire data from the device and return that data in the form of an
* {@link AcquisitionResult} object.
*/
-public interface AcquisitionTask extends Task<AcquisitionResult>, Closeable
+public interface AcquisitionTask extends Task<AcquisitionResult>
{
- // METHODS
-
- /**
- * Closes the device.
- *
- * @throws IOException
- * in case of I/O problems closing the device.
- */
- void close() throws IOException;
-
- /**
- * Opens the device for acquisition.
- *
- * @throws IOException
- * in case of I/O problems closing the device.
- */
- void open() throws IOException;
-
+ // No additional methods
}
@@ -0,0 +1,36 @@
+/*
+ * OpenBench LogicSniffer / SUMP project
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+ *
+ * Copyright (C) 2006-2010 Michael Poppitz, www.sump.org
+ * Copyright (C) 2010 J.W. Janssen, www.lxtreme.nl
+ */
+package nl.lxtreme.ols.api.devices;
+
+
+import nl.lxtreme.ols.api.task.*;
+
+
+/**
+ * Denotes a task that talk to by calling {@link #call()} on it. The
+ * implementation of that method should cause the device to stop acquiring data,
+ * if possible. If the device already finished its acquisition task, this task
+ * should not lead to unpredictable results.
+ */
+public interface CancelTask extends Task<Void>
+{
+ // No additional methods
+}
@@ -30,7 +30,7 @@
* Interface for implementing device controllers. Each supported device must
* implement at least this interface.
*/
-public interface Device
+public interface Device extends Closeable
{
// METHODS
@@ -40,13 +40,26 @@
* @param aProgressListener
* the acquisition progress listener the acquisition task can use to
* report its progress, cannot be <code>null</code>.
+ * @return a new acquisition task, never <code>null</code>.
* @throws IOException
* in case of I/O problems during the creation of the acquisition
* task.
*/
public AcquisitionTask createAcquisitionTask( AcquisitionProgressListener aProgressListener ) throws IOException;
/**
+ * Creates a new {@link CancelTask} for canceling the current acquisition from
+ * the device, if the device needs something special to do this.
+ *
+ * @return a new cancel task, if <code>null</code> the running acquisition is
+ * simply cancelled.
+ * @throws IOException
+ * in case of I/O problems during the creating of the cancellation
+ * task.
+ */
+ public CancelTask createCancelTask() throws IOException;
+
+ /**
* Returns a descriptive name of this device controller.
*
* @return name of the controller, cannot be <code>null</code>.
@@ -430,12 +430,34 @@ public void addTool( final Tool<?> aTool )
public void cancelCapture()
{
final DataAcquisitionService acquisitionService = getDataAcquisitionService();
- if ( acquisitionService != null )
+ final Device device = getDevice();
+ if ( ( device == null ) || ( acquisitionService == null ) )
{
- acquisitionService.cancelAcquisition();
+ return;
}
- updateActionsOnEDT();
+ try
+ {
+ acquisitionService.cancelAcquisition( device );
+ }
+ catch ( final IllegalStateException exception )
+ {
+ setStatusOnEDT( "No acquisition in progress!" );
+ }
+ catch ( final IOException exception )
+ {
+ setStatusOnEDT( "I/O problem: " + exception.getMessage() );
+
+ // Make sure to handle IO-interrupted exceptions properly!
+ if ( !HostUtils.handleInterruptedException( exception ) )
+ {
+ exception.printStackTrace();
+ }
+ }
+ finally
+ {
+ updateActionsOnEDT();
+ }
}
/**
@@ -23,6 +23,7 @@
import java.awt.*;
import java.io.*;
+
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.devices.*;
@@ -48,12 +49,32 @@
* {@inheritDoc}
*/
@Override
- public AcquisitionTask createAcquisitionTask( final AcquisitionProgressListener aProgressListener ) throws IOException
+ public void close() throws IOException
+ {
+ // No-op...
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public AcquisitionTask createAcquisitionTask( final AcquisitionProgressListener aProgressListener )
+ throws IOException
{
return new GenericDeviceAcquisitionTask( this.deviceConfig, aProgressListener );
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public CancelTask createCancelTask() throws IOException
+ {
+ // Nothing special is needed...
+ return null;
+ }
+
+ /**
* @see nl.lxtreme.ols.api.devices.Device#getName()
*/
@Override
@@ -83,6 +83,8 @@ public AcquisitionResult call() throws IOException
final int[] values = new int[count];
final long[] timestamps = new long[count];
+ this.inputStream = new FileInputStream( this.deviceConfig.getDevicePath() );
+
try
{
int idx = 0;
@@ -109,24 +111,10 @@ public AcquisitionResult call() throws IOException
// Rethrow the caught exception...
throw exception;
}
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void close() throws IOException
- {
- HostUtils.closeResource( this.inputStream );
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void open() throws IOException
- {
- this.inputStream = new FileInputStream( this.deviceConfig.getDevicePath() );
+ finally
+ {
+ HostUtils.closeResource( this.inputStream );
+ }
}
/**
Oops, something went wrong.

0 comments on commit 6d8326f

Please sign in to comment.