// open the camera tPvHandle CameraOpen(unsigned long IP) { tPvHandle Handle; if(PvCameraOpenByAddr(IP,ePvAccessMaster,&Handle) == ePvErrSuccess) return Handle; else return NULL; }
// open the camera bool CameraOpen(unsigned long IP) { if(!PvCameraOpenByAddr(IP,ePvAccessMonitor,&(GCamera.Handle))) { printf("Camera open : %s\n",GCamera.Info.SerialString); return true; } else return false; }
int main(int argc, char* argv[]) { int err = 0; // initialise the Prosilica API if(!PvInitialize()) { int c; unsigned long uid = 0; unsigned long addr = 0; bool bLoad = false; bool bSave = false; while ((c = getopt (argc, argv, "u:i:ls:h?")) != -1) { switch(c) { case 'u': { if(optarg) uid = atol(optarg); break; } case 'i': { if(optarg) addr = inet_addr(optarg); break; } case 'l': { bLoad = true; break; } case 's': { bSave = true; break; } case '?': case 'h': { ShowUsage(); break; } default: break; } } if((uid || addr) && (bSave || bLoad)) { tPvHandle Camera; tPvAccessFlags Flags = (bLoad ? ePvAccessMaster : ePvAccessMonitor); tPvErr Err; bool Done = false; if(uid) { // wait a bit to leave some time to the API to detect any camera Sleep(500); // and open the camera Err = PvCameraOpen(uid,Flags,&Camera); } else Err = PvCameraOpenByAddr(addr,Flags,&Camera); if(!Err) { if(bLoad) // load the camera setup Done = SetupLoad(Camera,argv[argc-1]); else if(bSave) // save the camera setup Done = SetupSave(Camera,argv[argc-1]); if(!Done) fprintf(stderr,"sorry, an error occured\n"); err = 1; // close the camera PvCameraClose(Camera); } else { if(Err == ePvErrNotFound || Err == ePvErrUnplugged) fprintf(stderr,"sorry, couldn't found the camera\n"); else if(Err == ePvErrAccessDenied) fprintf(stderr,"sorry, this camera is already in use\n"); else fprintf(stderr,"sorry, couldn't open the camera for some reason\n"); err = 1; } } else { ShowUsage(); err = 1; } // uninitialise the API PvUnInitialize(); } else { err = 1; fprintf(stderr,"failed to initialise the API\n"); } return err; }
int main(int argc, char* argv[]) { tPvErr errCode; int err = 0; // initialize the PvAPI if((errCode = PvInitialize()) != ePvErrSuccess) { printf("PvInitialize err: %u\n", errCode); } else { int c; unsigned long uid = 0; unsigned long addr = 0; bool bGet = false; bool bSet = false; while ((c = getopt (argc, argv, "u:i:gs:h?")) != -1) { switch(c) { case 'u': { if(optarg) uid = atol(optarg); break; } case 'i': { if(optarg) addr = inet_addr(optarg); break; } case 'g': { bGet = true; break; } case 's': { bSet = true; break; } case '?': case 'h': { ShowUsage(); break; } default: break; } } if(uid || ((addr != INADDR_NONE) && (addr != INADDR_ANY))) { tPvHandle Camera; tPvAccessFlags Flags = (bSet ? ePvAccessMaster : ePvAccessMonitor); if(uid) { // wait a bit to leave some time to the API to detect any camera Sleep(500); // and open the camera errCode = PvCameraOpen(uid,Flags,&Camera); } else errCode = PvCameraOpenByAddr(addr,Flags,&Camera); if(errCode == ePvErrSuccess) { if(bGet) // get value errCode = MemRead(Camera); else if(bSet) // set value errCode = MemWrite(Camera,argv[argc-1]); if(errCode != ePvErrSuccess) fprintf(stderr,"Error: %u\n",errCode); err = 1; // close the camera PvCameraClose(Camera); } else { if(errCode == ePvErrNotFound || errCode == ePvErrUnplugged) fprintf(stderr,"No camera detected.\n"); else if(errCode == ePvErrAccessDenied) fprintf(stderr,"Camera already in use.\n"); else fprintf(stderr,"PvCameraOpen fail: %u\n", errCode); err = 1; } } else { ShowUsage(); err = 1; } PvUnInitialize(); } return err; }
bool CameraGigE::onInit() { LOG(LTRACE) << "CameraGigE::initialize\n"; h_onTrigger.setup(this, &CameraGigE::onTrigger); registerHandler("onTrigger", &h_onTrigger); newImage = registerEvent("newImage"); endOfSequence = registerEvent("endOfSequence"); registerStream("out_img", &out_img); if (!props.address.empty()) { unsigned long ip = inet_addr(props.address.c_str()); if (PvCameraOpenByAddr(ip, ePvAccessMaster, &cHandle) != ePvErrSuccess) { LOG(LERROR) << "Unable to open camera on adress " << props.address << " \n"; return false; } } else if (props.uid != 0) { if (PvCameraOpen(props.uid, ePvAccessMaster, &cHandle) != ePvErrSuccess) { LOG(LERROR) << "Unable to open camera with uid " << props.uid << " \n"; return false; } } else { return false; } // Set parameters tPvErr err; /// Exposure if (!props.exposureMode.empty()) { if ((err = PvAttrEnumSet(cHandle, "ExposureMode", props.exposureMode.c_str())) == ePvErrSuccess) { if (props.exposureMode == "Manual") { if ((err = PvAttrUint32Set(cHandle, "ExposureValue", props.exposureValue / 1000000.0)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "ExposureValue", &min, &max); LOG(LWARNING) << "ExposureValue : " << props.exposureValue << " is out of range, valid range [ " << (double) min / 1000000.0 << " , " << (double) max / 1000000.0 << " ]\n"; } } } } else { LOG(LWARNING) << "Unable to set ExposureMode \n"; } } /// Gain if (!props.gainMode.empty()) { if ((err = PvAttrEnumSet(cHandle, "GainMode", props.gainMode.c_str())) == ePvErrSuccess) { if (props.gainMode == "Manual") { if ((err = PvAttrUint32Set(cHandle, "gainValue", props.gainValue)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "GainValue", &min, &max); LOG(LWARNING) << "GainValue : " << props.gainValue << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } } } else { LOG(LWARNING) << "Unable to set GainMode \n"; } } /// White Balance if (!props.whitebalMode.empty()) { if ((err = PvAttrEnumSet(cHandle, "WhitebalMode", props.gainMode.c_str())) == ePvErrSuccess) { if (props.whitebalMode == "Manual") { if ((err = PvAttrUint32Set(cHandle, "WhitebalValueRed", props.whitebalValueRed)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "WhitebalValueRed", &min, &max); LOG(LWARNING) << "WhitebalValueRed : " << props.whitebalValueRed << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } if ((err = PvAttrUint32Set(cHandle, "WhitebalValueBlue", props.whitebalValueBlue)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "WhitebalValueBlue", &min, &max); LOG(LWARNING) << "WhitebalValueBlue : " << props.whitebalValueBlue << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } } } else { LOG(LWARNING) << "Unable to set WhitebalMode" << err << "\n"; } } if ((err = PvAttrEnumSet(cHandle, "MirrorX", props.mirrorX ? "On" : "Off")) != ePvErrSuccess) { } if ((err = PvAttrEnumSet(cHandle, "PixelFormat", props.pixelFormat.c_str())) != ePvErrSuccess) { LOG(LERROR) << "Unable to set pixelformat " << err; } if ((err = PvAttrUint32Set(cHandle, "Height", props.height)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "Height", &min, &max); LOG(LWARNING) << "Height : " << props.height << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]"; } } if ((err = PvAttrUint32Set(cHandle, "Width", props.width)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "Width", &min, &max); LOG(LWARNING) << "Width : " << props.width << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } if ((err = PvAttrUint32Set(cHandle, "RegionX", props.regionX)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "RegionX", &min, &max); LOG(LWARNING) << "RegionX : " << props.regionX << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } if ((err = PvAttrUint32Set(cHandle, "RegionY", props.regionY)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "RegionY", &min, &max); LOG(LWARNING) << "RegionY : " << props.regionY << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } if ((err = PvAttrUint32Set(cHandle, "BinningX", props.binningX)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "BinningX", &min, &max); LOG(LWARNING) << "BinningX : " << props.binningX << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } if ((err = PvAttrUint32Set(cHandle, "BinningY", props.binningY)) != ePvErrSuccess) { if (err == ePvErrOutOfRange) { tPvUint32 min, max; PvAttrRangeUint32(cHandle, "BinningY", &min, &max); LOG(LWARNING) << "BinningY : " << props.binningY << " is out of range, valid range [ " << (double) min << " , " << (double) max << " ]\n"; } } // ---------------- PvAttrEnumSet(cHandle, "FrameStartTriggerMode", "Freerun"); unsigned long frameSize = 0; if (PvAttrUint32Get(cHandle, "TotalBytesPerFrame", &frameSize) != ePvErrSuccess) { return false; } frame.ImageBuffer = new char[frameSize]; frame.ImageBufferSize = frameSize; return true; }