int main(int argc, char* argv[]) { tPvErr errCode; // initialize the PvAPI if((errCode = PvInitialize()) != ePvErrSuccess) printf("PvInitialize err: %u\n", errCode); else { //IMPORTANT: Initialize camera structure. See tPvFrame in PvApi.h for more info. memset(&GCamera,0,sizeof(tCamera)); // set the CTRL-C handler SetConsoleCtrlHandler(&CtrlCHandler, TRUE); printf("Waiting for camera discovery...\n"); // register camera plugged in callback if((errCode = PvLinkCallbackRegister(CameraEventCB,ePvLinkAdd,NULL)) != ePvErrSuccess) printf("PvLinkCallbackRegister err: %u\n", errCode); // register camera unplugged callback if((errCode = PvLinkCallbackRegister(CameraEventCB,ePvLinkRemove,NULL)) != ePvErrSuccess) printf("PvLinkCallbackRegister err: %u\n", errCode); // wait until ctrl+c break printf("Ctrl+C to break.\n"); WaitForEver(); CameraStop(); CameraUnsetup(); // If thread spawned (see HandleCameraPlugged), wait to finish if(GCamera.ThHandle) WaitThread(); if((errCode = PvLinkCallbackUnRegister(CameraEventCB,ePvLinkAdd)) != ePvErrSuccess) printf("PvLinkCallbackUnRegister err: %u\n", errCode); if((errCode = PvLinkCallbackUnRegister(CameraEventCB,ePvLinkRemove)) != ePvErrSuccess) printf("PvLinkCallbackUnRegister err: %u\n", errCode); // uninitialize the API PvUnInitialize(); } return 0; }
int main(int argc, char* argv[]) { tPvErr errCode; // initialize the PvAPI if((errCode = PvInitialize()) != ePvErrSuccess) printf("PvInitialize err: %u\n", errCode); else { //IMPORTANT: Initialize camera structure. See tPvFrame in PvApi.h for more info. memset(&GCamera,0,sizeof(tCamera)); // set the CTRL-C handler SetConsoleCtrlHandler(&CtrlCHandler, TRUE); printf("Waiting for camera discovery...\n"); // register camera plugged in callback if((errCode = PvLinkCallbackRegister(CameraLinkCallback,ePvLinkAdd,NULL)) != ePvErrSuccess) printf("PvLinkCallbackRegister err: %u\n", errCode); // register camera unplugged callback if((errCode = PvLinkCallbackRegister(CameraLinkCallback,ePvLinkRemove,NULL)) != ePvErrSuccess) printf("PvLinkCallbackRegister err: %u\n", errCode); // All camera setup, event setup, streaming, handled in ePvLinkAdd callback // wait until ctrl+c break or failure printf("***Ctrl+C to break***\n"); WaitForEver(); CameraStop(); EventUnsetup(); CameraUnsetup(); if((errCode = PvLinkCallbackUnRegister(CameraLinkCallback,ePvLinkAdd)) != ePvErrSuccess) printf("PvLinkCallbackUnRegister err: %u\n", errCode); if((errCode = PvLinkCallbackUnRegister(CameraLinkCallback,ePvLinkRemove)) != ePvErrSuccess) printf("PvLinkCallbackUnRegister err: %u\n", errCode); // uninitialize the API PvUnInitialize(); } return 0; }