VmbError_t SynchronousGrab( const char* pCameraID, const char* pFileName ) { VmbError_t err = VmbStartup(); // Initialize the Vimba API VmbCameraInfo_t *pCameras = NULL; // A list of camera details VmbUint32_t nCount = 0; // Number of found cameras VmbUint32_t nFoundCount = 0; // Change of found cameras const VmbUint32_t nTimeout = 2000; // Timeout for Grab VmbAccessMode_t cameraAccessMode = VmbAccessModeFull;// We open the camera with full access VmbHandle_t cameraHandle = NULL; // A handle to our camera VmbBool_t bIsCommandDone = VmbBoolFalse; // Has a command finished execution VmbFrame_t frame; // The frame we capture const char* pPixelFormat = NULL; // The pixel format we use for acquisition VmbInt64_t nPayloadSize = 0; // The size of one frame AVTBitmap bitmap; // The bitmap we create PrintVimbaVersion(); if ( VmbErrorSuccess == err ) { // Is Vimba connected to a GigE transport layer? DiscoverGigECameras(); // If no camera ID was provided use the first camera found if ( NULL == pCameraID ) { // Get the amount of known cameras err = VmbCamerasList( NULL, 0, &nCount, sizeof *pCameras ); if ( VmbErrorSuccess == err && 0 < nCount ) { pCameras = (VmbCameraInfo_t*)malloc( nCount * sizeof( *pCameras )); if ( NULL != pCameras ) { // Actually query all static details of all known cameras without having to open the cameras // If a new camera was connected since we queried the amount of cameras (nFoundCount > nCount) we can ignore that one err = VmbCamerasList( pCameras, nCount, &nFoundCount, sizeof *pCameras ); if ( VmbErrorSuccess != err && VmbErrorMoreData != err ) { printf( "Could not list cameras. Error code: %d\n", err ); } else { // Use the first camera if( nFoundCount != 0) { pCameraID = pCameras[0].cameraIdString; } else { pCameraID = NULL; err = VmbErrorNotFound; printf( "Camera lost.\n" ); } } free( pCameras ); pCameras = NULL; } else { printf( "Could not allocate camera list.\n" ); } } else { printf( "Could not list cameras or no cameras present. Error code: %d\n", err ); } } if ( NULL != pCameraID ) { // Open camera err = VmbCameraOpen( pCameraID, cameraAccessMode, &cameraHandle ); if ( VmbErrorSuccess == err ) { printf( "Camera ID: %s\n\n", pCameraID ); // Set the GeV packet size to the highest possible value // (In this example we do not test whether this cam actually is a GigE cam) if ( VmbErrorSuccess == VmbFeatureCommandRun( cameraHandle, "GVSPAdjustPacketSize" )) { do { if ( VmbErrorSuccess != VmbFeatureCommandIsDone( cameraHandle, "GVSPAdjustPacketSize", &bIsCommandDone )) { break; } } while ( VmbBoolFalse == bIsCommandDone ); } if ( VmbErrorSuccess == err ) { // Set pixel format. For the sake of simplicity we only support Mono and RGB in this example. err = VmbFeatureEnumSet( cameraHandle, "PixelFormat", "RGB8Packed" ); if ( VmbErrorSuccess != err ) { // Fall back to Mono err = VmbFeatureEnumSet( cameraHandle, "PixelFormat", "Mono8" ); } // Read back pixel format VmbFeatureEnumGet( cameraHandle, "PixelFormat", &pPixelFormat ); if ( VmbErrorSuccess == err ) { // Evaluate frame size err = VmbFeatureIntGet( cameraHandle, "PayloadSize", &nPayloadSize ); if ( VmbErrorSuccess == err ) { frame.buffer = (unsigned char*)malloc( (VmbUint32_t)nPayloadSize ); frame.bufferSize = (VmbUint32_t)nPayloadSize; // Announce Frame err = VmbFrameAnnounce( cameraHandle, &frame, (VmbUint32_t)sizeof( VmbFrame_t )); if ( VmbErrorSuccess == err ) { // Start Capture Engine err = VmbCaptureStart( cameraHandle ); if ( VmbErrorSuccess == err ) { // Queue Frame err = VmbCaptureFrameQueue( cameraHandle, &frame, NULL ); if ( VmbErrorSuccess == err ) { // Start Acquisition err = VmbFeatureCommandRun( cameraHandle,"AcquisitionStart" ); if ( VmbErrorSuccess == err ) { // Capture one frame synchronously err = VmbCaptureFrameWait( cameraHandle, &frame, nTimeout ); if ( VmbErrorSuccess == err ) { // Convert the captured frame to a bitmap and save to disk if ( VmbFrameStatusComplete == frame.receiveStatus ) { bitmap.bufferSize = frame.imageSize; bitmap.width = frame.width; bitmap.height = frame.height; // We only support Mono and RGB in this example if ( 0 == strcmp( "RGB8Packed", pPixelFormat )) { bitmap.colorCode = ColorCodeRGB24; } else { bitmap.colorCode = ColorCodeMono8; } // Create the bitmap if ( 0 == AVTCreateBitmap( &bitmap, frame.buffer )) { printf( "Could not create bitmap.\n" ); } else { // Save the bitmap if ( 0 == AVTWriteBitmapToFile( &bitmap, pFileName )) { printf( "Could not write bitmap to file.\n" ); } else { printf( "Bitmap successfully written to file \"%s\"\n", pFileName ); // Release the bitmap's buffer if ( 0 == AVTReleaseBitmap( &bitmap )) { printf( "Could not release the bitmap.\n" ); } } } } else { printf( "Frame not successfully received. Error code: %d\n", frame.receiveStatus ); } } else { printf( "Could not capture frame. Error code: %d", err ); } // Stop Acquisition err = VmbFeatureCommandRun( cameraHandle,"AcquisitionStop" ); if ( VmbErrorSuccess != err ) { printf( "Could not stop acquisition. Error code: %d\n", err ); } } else { printf( "Could not start acquisition. Error code: %d", err ); } } else { printf( "Could not queue frame. Error code: %d\n", err ); } // Stop Capture Engine err = VmbCaptureEnd( cameraHandle ); if ( VmbErrorSuccess != err ) { printf( "Could not end capture. Error code: %d\n", err ); } } else { printf( "Could not start capture. Error code: %d\n", err ); } // Revoke frame err = VmbFrameRevoke( cameraHandle, &frame ); if ( VmbErrorSuccess != err ) { printf( "Could not revoke frame. Error code: %d\n", err ); } } else { printf( "Could not announce frame. Error code: %d\n", err ); } free( frame.buffer ); frame.buffer = NULL; } } else { printf( "Could not set pixel format to either RGB or Mono. Error code: %d\n", err ); } } else { printf( "Could not adjust packet size. Error code: %d\n", err ); } err = VmbCameraClose ( cameraHandle ); if ( VmbErrorSuccess != err ) { printf( "Could not close camera. Error code: %d\n", err ); } } else { printf( "Could not open camera. Error code: %d\n", err ); } } VmbShutdown(); } else { printf( "Could not start system. Error code: %d\n", err ); } return err; }
void ListCameras() { VmbError_t err = VmbErrorSuccess; VmbCameraInfo_t * pCameras = NULL; VmbUint32_t i = 0; VmbUint32_t nCount = 0; VmbUint32_t nFoundCount = 0; err = VmbStartup(); // Initialize the Vimba API PrintVimbaVersion(); // Print Vimba Version if ( VmbErrorSuccess == err ) { DiscoverGigECameras(); err = VmbCamerasList( NULL, 0, &nCount, sizeof *pCameras ); // Get the amount of known cameras if ( VmbErrorSuccess == err && nCount != 0 ) { printf( "Cameras found: %d\n\n", nCount ); pCameras = (VmbCameraInfo_t*)malloc( sizeof *pCameras * nCount ); if ( NULL != pCameras ) { err = VmbCamerasList( pCameras, nCount, &nFoundCount, sizeof *pCameras ); // Query all static details of all known cameras // Without having to open the cameras if( VmbErrorSuccess == err || VmbErrorMoreData == err ) { if( nFoundCount < nCount) // If a new camera was connected since we queried { // the amount of cameras, we can ignore that one nCount = nFoundCount; } for ( i=0; i<nCount; ++i ) // And print them out { printf( "/// Camera Name: %s\n/// Model Name: %s\n/// Camera ID: %s\n/// Serial Number: %s\n/// @ Interface ID: %s\n\n\n", pCameras[i].cameraName, pCameras[i].modelName, pCameras[i].cameraIdString, pCameras[i].serialString, pCameras[i].interfaceIdString ); } } else { printf( "Could not retrieve camera list. Error code: %d\n", err ); } free( pCameras ); pCameras = NULL; } else { printf( "Could not allocate camera list.\n" ); } } else { printf( "Could not list cameras or no cameras present. Error code: %d\n", err ); } VmbShutdown(); // Close Vimba } else { printf( "Could not start system. Error code: %d\n", err ); } }
BOOL CAVTCameraManipulateApp::InitInstance() { // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); // 创建 shell 管理器,以防对话框包含 // 任何 shell 树视图控件或 shell 列表视图控件。 CShellManager *pShellManager = new CShellManager; // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); vmbError = VmbStartup(); if (VmbErrorSuccess != vmbError) { AfxMessageBox(_T("Vimba Startup Error!")); } CAVTCameraManipulateDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: 在此放置处理何时用 // “确定”来关闭对话框的代码 } else if (nResponse == IDCANCEL) { // TODO: 在此放置处理何时用 // “取消”来关闭对话框的代码 } // 删除上面创建的 shell 管理器。 if (pShellManager != NULL) { delete pShellManager; } // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; }
void ForceIP( char* strMAC, char* strIP, char* strSubnet, char* strGateway ) { VmbError_t err = VmbErrorSuccess; VmbBool_t bIsGigE = 0; VmbHandle_t hCam = NULL; unsigned long long nMAC = 0; unsigned long nIP = 0; unsigned long nSubnet = 0; unsigned long nGateway = 0; err = VmbStartup(); // Initialize the Vimba API PrintVimbaVersion(); // Print Vimba Version nMAC = mac_addr( strMAC ); // The MAC address of the camera nIP = inet_addr( strIP ); // The future IP address of the camera nSubnet = inet_addr( strSubnet ); // The future subnet mask of the camera nGateway = strGateway != NULL ? inet_addr( strGateway ) : 0; // A possible gateway if ( VmbErrorSuccess == err ) { err = VmbFeatureBoolGet( gVimbaHandle, "GeVTLIsPresent", &bIsGigE ); // Is Vimba connected to a GigE transport layer? if ( VmbErrorSuccess == err ) { if( bIsGigE ) { if ( 0 != nMAC ) { err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressMAC", nMAC ); // Send MAC address to TL if ( VmbErrorSuccess == err ) { err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressIP", nIP ); // Send new IP address to TL if ( VmbErrorSuccess == err ) { err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressSubnetMask", nSubnet ); // Send new subnet mask to TL if ( VmbErrorSuccess == err ) { if( 0 != nGateway ) { err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressGateway", nGateway ); // Send gateway address to TL if ( VmbErrorSuccess != err ) { printf( "Could not prepare the gateway settings. Reason: %d\n\n", err ); } } if ( VmbErrorSuccess == err ) { err = VmbFeatureCommandRun( gVimbaHandle, "GeVForceIPAddressSend" ); // Finally execute the command to write all settings to cam if ( VmbErrorSuccess == err ) { printf( "IP address successfully changed to %s (%s).\n\n", strIP, strSubnet ); } else { printf( "Could not set a new IP address. Reason: %d\n\n", err ); } } } else { printf( "Could not prepare the subnet settings. Reason: %d\n\n", err ); } } else { printf( "Could not prepare the IP address settings. Reason: %d\n\n", err ); } } else { printf( "Could not prepare the MAC address settings. Reason: %d\n\n", err ); } } else { printf( "Malformed MAC address.\n\n" ); } } else { printf( "No GigE transport layer present.\n\n" ); } } else { printf( "Could not query Vimba for the presence of a GigE transport layer. Reason: %d\n\n", err ); } VmbShutdown(); // Close Vimba } else { printf( "Could not start system. Error code: %d\n\n", err ); } }