Buffer Interface
BiSimplePlusPlus.cpp

This is an example of how to use the SequenceInterface class.

/***************************************************************************
*
* BiSimplePlusPlus.cpp
*
* This application uses the SequenceInterface class to acquire a sequence
* of images. This application is equivalent to the BiSeqSimpleDisp.c
* application, the difference being the BiSeqSimpleDisp.c application
* uses the Bi API and this application uses the SequenceInterface class.
* There are several advantages to using the SequenceInterface class
* that are demonstrated in this application.
* The advantages being:
* 1. Fewer method/function calls to accomplish sequence capture.
* 2. No need to call cleanup methods/functions.
* 3. Fewer method/function parameters.
* 4. Improved error handling by throwing exceptions.
*
* We encouraged you to compare this application to the BiSeqSimpleDisp
* application to see the advantages for yourself.
*
* This example demonstrates the use of SequenceInterface class.
*
* Copyright (C) 2004 by BitFlow, Inc. All Rights Reserved.
*
***************************************************************************/
#include "stdafx.h"
#include "BiSimplePlusPlus.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
using namespace BufferAcquisition;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(BFNULL), BFNULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
PBFVOID bitmap;
int hDspSrf = -1; // handle to display surface
BFU32 i;
MSG Msg;
char ch;
BFBOOL LoopContin = FALSE;
// Control variables
BFU32 numBuffers = 10; // Allocate 10 buffers
BFU32 setupOptions = 0; // Use default setup options.
// prompt user for the board to open
BFU32 BoardType, BrdNum, Init, SerNum;
if( DoBrdOpenDialog(BOD_BRD_NUM_NON_FAMILY|BOD_HIDEJUSTOPEN, FF_BITFLOW_MODERN, &BoardType, &BrdNum, &Init, &SerNum) )
{
return -1;
}
try
{
// Create Instatance of the sequence interface class
cout << "Creating instance of sequence interface." << endl;
SequenceInterface board(BrdNum, numBuffers, setupOptions);
// Get the array of buffer pointers
PBFU32* pBufferArray= board.getBufferArrayPointers();
// Start sequence acquisition
cout << "Starting Acquisition" << endl;
// Wait here until the sequence has been captured.
cout << "Waiting for sequence to be acquired" << endl;
board.seqWaitDone(10000);
// Verify that all frames have been captured and no frames have been missed.
cout << "\nCaptured " << (int) board.getNumFramesCaptured() << " Frames" << endl;
cout << "Missed " << (int) board.getNumFramesMissed() << " Frames.\n" << endl;
// Create display surface to view sequence.
if(!DispSurfCreate((PBFS32)&hDspSrf, board.getBrdInfo(BiCamInqXSize),
{
cout << "Couldn't create display surface" << endl;
return 1;
}
// Get pointer to bitmap data memory.
if(!DispSurfGetBitmap(hDspSrf, &bitmap))
{
cout << "No display surface available" << endl;
return 1;
}
// Offset Display surface.
DispSurfOffset(hDspSrf,100,100);
// Loop through all buffers and display each one.
cout << "Press L to loop continuously, X to exit, and any other key"
" for next frame." << endl;
for(i=0; i<numBuffers; i++)
{
// What frame are we displaying
cout << "Displaying frame " << (int) i << "\r";
// This new function will format the image data for display,
// then display the image. This reduces a lot of code. (See
// BiSeqSimpleDisp.c)
if(!DispSurfFormatBlit(hDspSrf, pBufferArray[i],
board.getBrdInfo(BiCamInqBitsPerPix), BFDISP_FORMAT_NORMAL))
{
cout << "Could not update the display surface" << endl;
return 1;
}
if(!LoopContin)
{
// Wait here for a keyboard stroke
while(!BFkbhit())
{
if(PeekMessage(&Msg,BFNULL,0,0,PM_REMOVE))
DispatchMessage(&Msg);
else
Sleep(10);
}
ch = BFgetch();
if(toupper(ch) == 'X')
i = numBuffers; // Lets get out of here
else if(toupper(ch) == 'L')
LoopContin = TRUE;
}
else
{
Sleep(50); // slowdown playback when looping
}
// needed for display window
if(PeekMessage(&Msg,BFNULL,0,0,PM_REMOVE))
DispatchMessage(&Msg);
}
// Save the sequence to disk
cout << "Saving sequence to disk." << endl;
BFCHAR FileName[128] = "BiSimplePlusPlus.tif";
BFU32 WriteOptions = 0; // No write options
board.writeSeqBuffer(FileName, sizeof(FileName), 0, numBuffers, WriteOptions);
cout << "\nPress Any Key to Continue." << endl;
while(!BFkbhit())
{
// needed for display window
if(PeekMessage(&Msg,BFNULL,0,0,PM_REMOVE))
DispatchMessage(&Msg);
else
Sleep(0);
}
// absorb key stroke
if (BFkbhit()) BFgetch();
// Close Display window
DispSurfClose(hDspSrf);
}
catch(BFException e)
{
nRetCode = 1;
}
}
return nRetCode;
}