int main(int /*argc*/, char** /*argv*/) { PrintBuildInfo(); Error error; // Since this application saves images in the current folder // we must ensure that we have permission to write to this folder. // If we do not have permission, fail right away. FILE* tempFile = fopen("test.txt", "w+"); if (tempFile == NULL) { printf("Failed to create file in current folder. Please check permissions.\n"); return -1; } fclose(tempFile); remove("test.txt"); BusManager busMgr; CameraInfo camInfo[10]; unsigned int numCamInfo = 10; error = BusManager::DiscoverGigECameras( camInfo, &numCamInfo ); if (error != PGRERROR_OK) { PrintError( error ); return -1; } printf( "Number of cameras discovered: %u\n", numCamInfo ); for (unsigned int i=0; i < numCamInfo; i++) { PrintCameraInfo( &camInfo[i] ); } unsigned int numCameras; error = busMgr.GetNumOfCameras(&numCameras); if (error != PGRERROR_OK) { PrintError( error ); return -1; } printf( "Number of cameras enumerated: %u\n", numCameras ); for (unsigned int i=0; i < numCameras; i++) { PGRGuid guid; error = busMgr.GetCameraFromIndex(i, &guid); if (error != PGRERROR_OK) { PrintError( error ); return -1; } InterfaceType interfaceType; error = busMgr.GetInterfaceTypeFromGuid( &guid, &interfaceType ); if ( error != PGRERROR_OK ) { PrintError( error ); return -1; } if ( interfaceType == INTERFACE_GIGE ) { RunSingleCamera(guid); } } printf( "Done! Press Enter to exit...\n" ); getchar(); return 0; }
BOOL CFlyCap2MFCDoc::OnNewDocument() { Error error; if (!CDocument::OnNewDocument()) { return FALSE; } // Set the default image processing parameters Image::SetDefaultColorProcessing( NEAREST_NEIGHBOR ); Image::SetDefaultOutputFormat( PIXEL_FORMAT_BGRU ); // If entering this function from File->New Camera, stop the grab thread // first before doing anything else if ( m_continueGrabThread == true ) { m_continueGrabThread = false; DWORD dwRet = WaitForSingleObject( m_heventThreadDone, 5000 ); if ( dwRet == WAIT_TIMEOUT ) { // Timed out while waiting for thread to exit } m_camCtlDlg.Hide(); m_camCtlDlg.Disconnect(); m_pCamera->Disconnect(); } // Let the user select a camera bool okSelected; PGRGuid arGuid[64]; unsigned int size = 64; CameraSelectionDlg camSlnDlg; camSlnDlg.ShowModal( &okSelected, arGuid, &size ); if ( okSelected != true ) { return FALSE; } BusManager busMgr; InterfaceType ifType; error = busMgr.GetInterfaceTypeFromGuid( &arGuid[0], &ifType ); if ( error != PGRERROR_OK ) { return FALSE; } if ( ifType == INTERFACE_GIGE ) { m_pCamera = new GigECamera; } else { m_pCamera = new Camera; } // Connect to the 0th selected camera error = m_pCamera->Connect( &arGuid[0] ); if( error != PGRERROR_OK ) { CString csMessage; csMessage.Format( "Connect Failure: %s", error.GetDescription() ); AfxMessageBox( csMessage, MB_ICONSTOP ); return FALSE; } error = m_pCamera->GetCameraInfo( &m_cameraInfo ); if( error != PGRERROR_OK ) { CString csMessage; csMessage.Format( "CameraInfo Failure: %s", error.GetDescription() ); AfxMessageBox( csMessage, MB_ICONSTOP ); return FALSE; } // Connect the camera control dialog to the camera object m_camCtlDlg.Connect( m_pCamera ); // Start the grab thread m_continueGrabThread = true; AfxBeginThread( ThreadGrabImage, this ); return TRUE; }