41 #include <arpa/inet.h> 45 #define CHECK_ERR(fnc, amsg) \ 48 if (err != ePvErrSuccess) { \ 50 snprintf(msg, 256, "%s: %s", amsg, errorStrings[err]); \ 51 throw ProsilicaException(err, msg); \ 58 static const char*
autoValues[] = {
"Manual",
"Auto",
"AutoOnce"};
59 static const char*
triggerModes[] = {
"Freerun",
"SyncIn1",
"SyncIn2",
"FixedRate",
"Software"};
60 static const char*
acquisitionModes[] = {
"Continuous",
"SingleFrame",
"MultiFrame",
"Recorder"};
62 "Unexpected camera fault",
63 "Unexpected fault in PvApi or driver",
64 "Camera handle is invalid",
65 "Bad parameter to API call",
66 "Sequence of API calls is incorrect",
67 "Camera or attribute not found",
68 "Camera cannot be opened in the specified mode",
69 "Camera was unplugged",
70 "Setup is invalid (an attribute is invalid)",
71 "System/network resources or memory not available",
72 "1394 bandwidth not available",
73 "Too many frames on queue",
74 "Frame buffer is too small",
75 "Frame cancelled by user",
76 "The data for the frame was lost",
77 "Some data in the frame is missing",
78 "Timeout during wait",
79 "Attribute value is out of the expected range",
80 "Attribute is not this type (wrong access function)",
81 "Attribute write forbidden at this time",
82 "Attribute is not available at this time",
83 "A firewall is blocking the traffic"};
100 cameraNum =
PvCameraList(cameraList, MAX_CAMERA_LIST, NULL);
106 assert(i < MAX_CAMERA_LIST);
114 std::vector<CameraInfo> cameras;
116 unsigned long cameraNum = 0;
118 cameraNum =
PvCameraList(cameraList, MAX_CAMERA_LIST, NULL);
120 if (cameraNum < MAX_CAMERA_LIST)
130 for(
unsigned long i=0; i <
cameraNum; i++)
138 addr.s_addr = Conf.CurrentIpAddress;
142 cameras.push_back(camInfo);
153 addr.s_addr = Conf.CurrentIpAddress;
154 std::stringstream ip;
163 cameraNum =
PvCameraList(cameraList, MAX_CAMERA_LIST, NULL);
165 CHECK_ERR( info_fn(&info),
"Unable to find requested camera" );
169 "Unable to open camera as master. " 170 "Another process is already using it.");
176 : bufferSize_(bufferSize), FSTmode_(
None)
187 unsigned long addr = inet_addr(ip_address);
198 tPvUint32 maxPacketSize = 9000;
204 ROS_WARN(
"Detected max data rate is %lu bytes/s, typical maximum data rate for a " 205 "GigE port is %lu bytes/s. Are you using a GigE network card and cable?\n",
216 "Unable to retrieve frame size" );
252 "Could not set frame rate");
285 "Could not set acquisition mode" );
287 "Could not set trigger mode" );
289 "Could not start acquisition" );
299 "Could not set frame rate");
338 boost::this_thread::sleep(boost::posix_time::millisec(50));
342 throw std::runtime_error(
"Unknown error grabbing frame");
350 "Couldn't set exposure mode" );
354 "Couldn't set exposure value" );
364 "Couldn't set gain mode" );
369 "Couldn't set gain value" );
377 "Couldn't set white balance mode" );
385 "Couldn't set white balance blue value" );
390 "Couldn't set white balance red value" );
396 unsigned int width,
unsigned int height)
399 "Couldn't set region x (left edge)" );
401 "Couldn't set region y (top edge)" );
403 "Couldn't set region width" );
405 "Couldn't set region height" );
410 tPvUint32 min_val, max_val;
412 "Couldn't set region x (left edge)" );
414 "Couldn't set region y (top edge)" );
416 "Couldn't get range of Width attribute" );
418 "Couldn't set region width" );
420 "Couldn't get range of Height attribute" );
422 "Couldn't set region height" );
428 if (!
hasAttribute(
"BinningX") && binning_x == 1 && binning_y == 1)
432 "Couldn't set horizontal binning" );
434 "Couldn't set vertical binning" );
443 boost::function<
tPvErr (
char*,
unsigned long,
unsigned long*)> get_fn)
445 if (value.size() == 0)
448 unsigned long actual_size;
449 CHECK_ERR( get_fn(&value[0], value.size(), &actual_size),
450 "Couldn't get attribute" );
452 if (actual_size >= value.size()) {
453 value.resize(actual_size + 1);
454 CHECK_ERR( get_fn(&value[0], value.size(), &actual_size),
455 "Couldn't get attribute" );
467 std::string err_msg =
"Couldn't get attribute " + name;
475 std::string err_msg =
"Couldn't get attribute " + name;
488 std::string err_msg =
"Couldn't get attribute " + name;
495 std::string err_msg =
"Couldn't set attribute " + name;
502 std::string err_msg =
"Couldn't set attribute " + name;
509 std::string err_msg =
"Couldn't set attribute " + name;
516 std::string err_msg =
"Couldn't run command " + name;
524 "Couldn't retrieve unique id" );
530 tPvUint32 min_data_rate, max_data_rate;
532 "Couldn't get range of attribute StreamBytesPerSecond" );
533 return max_data_rate;
543 memcpy(buffer, data, size);
545 unsigned long written;
547 "Couldn't write to user memory" );
557 "Couldn't read from user memory" );
559 memcpy(data, buffer, size);
568 boost::lock_guard<boost::mutex> guard(camPtr->
frameMutex_);
584 unsigned long UniqueId)
void getAttributeEnum(const std::string &name, std::string &value)
General get/set attribute functions.
tPvErr PVDECL PvCaptureQueueFrame(tPvHandle Camera, tPvFrame *pFrame, tPvFrameCallback Callback)
tPvErr PVDECL PvCameraOpen(unsigned long UniqueId, tPvAccessFlags AccessFlag, tPvHandle *pCamera)
unsigned long PermittedAccess
static unsigned long cameraNum
void readUserMemory(char *data, size_t size)
tPvErr PVDECL PvAttrRangeUint32(tPvHandle Camera, const char *Name, tPvUint32 *pMin, tPvUint32 *pMax)
void setRoiToWholeFrame()
tPvErr PVDECL PvCaptureStart(tPvHandle Camera)
void setExposure(unsigned int val, AutoSetting isauto=Manual)
unsigned long PVDECL PvCameraList(tPvCameraInfo *pList, unsigned long ListLength, unsigned long *pConnectedNum)
void setRoi(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
std::string getIPAddress(uint64_t guid)
tPvErr PVDECL PvAttrFloat32Get(tPvHandle Camera, const char *Name, tPvFloat32 *pValue)
tPvErr PVDECL PvCaptureAdjustPacketSize(tPvHandle Camera, unsigned long MaximumPacketSize)
tPvErr PVDECL PvCaptureWaitForFrameDone(tPvHandle Camera, const tPvFrame *pFrame, unsigned long Timeout)
Camera(unsigned long guid, size_t bufferSize=DEFAULT_BUFFER_SIZE)
tPvErr PVDECL PvAttrStringGet(tPvHandle Camera, const char *Name, char *pBuffer, unsigned long BufferSize, unsigned long *pSize)
FrameStartTriggerMode FSTmode_
tPvFrame * grab(unsigned long timeout_ms=PVINFINITE)
uint64_t getGuid(size_t i)
tPvErr PVDECL PvAttrFloat32Set(tPvHandle Camera, const char *Name, tPvFloat32 Value)
tPvErr PVDECL PvCaptureQueueClear(tPvHandle Camera)
static tPvCameraInfo cameraList[MAX_CAMERA_LIST]
void setAttribute(const std::string &name, tPvUint32 value)
static const char * errorStrings[]
void runCommand(const std::string &name)
unsigned long getMaxDataRate()
static const size_t USER_MEMORY_SIZE
Data must have size <= USER_MEMORY_SIZE bytes.
static const char * autoValues[]
tPvErr PVDECL PvAttrUint32Get(tPvHandle Camera, const char *Name, tPvUint32 *pValue)
std::vector< CameraInfo > listCameras()
static const unsigned int MAX_CAMERA_LIST
#define CHECK_ERR(fnc, amsg)
static const unsigned long GIGE_MAX_DATA_RATE
tPvErr PVDECL PvLinkCallbackUnRegister(tPvLinkCallback Callback, tPvLinkEvent Event)
tPvErr PVDECL PvCommandRun(tPvHandle Camera, const char *Name)
void setKillCallback(boost::function< void(unsigned long)> callback)
static void getStringValuedAttribute(std::string &value, boost::function< tPvErr(char *, unsigned long, unsigned long *)> get_fn)
tPvErr PVDECL PvAttrStringSet(tPvHandle Camera, const char *Name, const char *Value)
static const char * triggerModes[]
static void openCamera(boost::function< tPvErr(tPvCameraInfo *)> info_fn, boost::function< tPvErr(tPvAccessFlags)> open_fn)
unsigned long PVDECL PvCameraListUnreachable(tPvCameraInfo *pList, unsigned long ListLength, unsigned long *pConnectedNum)
std::string to_string(const T &t)
void setGain(unsigned int val, AutoSetting isauto=Manual)
void removeEvents()
remove callback
tPvHandle handle()
Get raw PvApi camera handle.
tPvErr PVDECL PvAttrEnumSet(tPvHandle Camera, const char *Name, const char *Value)
void setAttributeEnum(const std::string &name, const std::string &value)
tPvErr PVDECL PvCameraOpenByAddr(unsigned long IpAddr, tPvAccessFlags AccessFlag, tPvHandle *pCamera)
tPvErr PVDECL PvCaptureEnd(tPvHandle Camera)
bool hasAttribute(const std::string &name)
Returns true if camera supports the attribute.
tPvErr PVDECL PvInitialize(void)
void setFrameRate(tPvFloat32 frame_rate)
boost::function< void(tPvFrame *)> userCallback_
void setFrameCallback(boost::function< void(tPvFrame *)> callback)
Must be used before calling start() in a non-triggered mode.
tPvErr PVDECL PvLinkCallbackRegister(tPvLinkCallback Callback, tPvLinkEvent Event, void *Context)
tPvErr PVDECL PvAttrUint32Set(tPvHandle Camera, const char *Name, tPvUint32 Value)
static void kill(void *Context, tPvInterface Interface, tPvLinkEvent Event, unsigned long UniqueId)
void getAttribute(const std::string &name, tPvUint32 &value)
tPvErr PVDECL PvAttrIsAvailable(tPvHandle Camera, const char *Name)
void writeUserMemory(const char *data, size_t size)
void setBinning(unsigned int binning_x=1, unsigned int binning_y=1)
void start(FrameStartTriggerMode=Freerun, tPvFloat32 frame_rate=30, AcquisitionMode=Continuous)
Start capture.
void setWhiteBalance(unsigned int blue, unsigned int red, AutoSetting isauto=Manual)
unsigned long ImageBufferSize
static const char * acquisitionModes[]
static const unsigned long USER_ADDRESS
void PVDECL PvUnInitialize(void)
tPvErr PVDECL PvCameraInfo(unsigned long UniqueId, tPvCameraInfo *pInfo)
tPvErr PVDECL PvCameraClose(tPvHandle Camera)
tPvErr PVDECL PvCameraIpSettingsGet(unsigned long UniqueId, tPvIpSettings *pSettings)
tPvErr PVDECL PvAttrEnumGet(tPvHandle Camera, const char *Name, char *pBuffer, unsigned long BufferSize, unsigned long *pSize)
tPvErr PVDECL PvCameraInfoByAddr(unsigned long IpAddr, tPvCameraInfo *pInfo, tPvIpSettings *pIpSettings)
boost::function< void(unsigned long UniqueId)> killCallback_
static void frameDone(tPvFrame *frame)