import mvIMPACT.acquire.*;
public class CaptureThread extends Thread
{
private static final boolean isWindows_ = System.getProperty( "os.name" ).startsWith( "Windows" );
private Device pDev_;
private boolean terminated_ = false;
public CaptureThread( Device pDev )
{
pDev_ = pDev;
}
public void run()
{
if( isWindows_ )
{
System.out.println( "\n\nSince you are running on a Windows platform you could use the display module belonging to this SDK. To try this simply remove the comments wherever the 'window_' variable is used. As Java does not support something like '#ifdef' we did not come up with anything smarter. Suggestions welcome!!!\n\n" );
}
EventControl ec = new EventControl( pDev_ );
ec.getEventSelector().writeS( "ExposureEnd" );
ec.getEventNotification().writeS( "On" );
FunctionInterface fi = new FunctionInterface( pDev_ );
int result = TDMR_ERROR.DMR_NO_ERROR;
while ( ( result = fi.imageRequestSingle() ) == TDMR_ERROR.DMR_NO_ERROR ) { };
if( result != TDMR_ERROR.DEV_NO_FREE_REQUEST_AVAILABLE )
{
System.out.println( String.format( "'FunctionInterface.imageRequestSingle' returned with an unexpected result: %d(%s)", result, ImpactAcquireException.getErrorCodeAsString( result ) ) );
}
mvIMPACT.acquire.examples.helper.DeviceAccess.manuallyStartAcquisitionIfNeeded( pDev_, fi );
Request pRequest = null;
Request pPreviousRequest = null;
int timeout_ms = 500;
int cnt = 0;
int requestNr = acquire.getINVALID_ID();
EventCallback eventCallback = new EventCallback( "", ec );
eventCallback.registerComponent( ec.getEventExposureEndTimestamp() );
while ( !terminated_ )
{
requestNr = fi.imageRequestWaitFor( timeout_ms );
pRequest = fi.isRequestNrValid( requestNr ) ? fi.getRequest( requestNr ) : null;
if( pRequest != null )
{
if( pRequest.isOK() )
{
}
else
{
System.out.println( "Error: " + pRequest.getRequestResult().readS() );
}
if( pPreviousRequest != null )
{
pPreviousRequest.unlock();
}
pPreviousRequest = pRequest;
fi.imageRequestSingle();
}
}
mvIMPACT.acquire.examples.helper.DeviceAccess.manuallyStopAcquisitionIfNeeded( pDev_, fi );
eventCallback.unregisterComponent( ec.getEventExposureEndTimestamp() );
if( pRequest != null )
{
pRequest.unlock();
}
fi.imageRequestReset( 0, 0 );
}
public void terminate()
{
terminated_ = true;
}
}