36 #include <prosilica_gige_sdk/PvRegIo.h>
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"};
90 CHECK_ERR( PvInitialize(),
"Failed to initialize Prosilica API" );
114 std::vector<CameraInfo> cameras;
130 for(
unsigned long i=0; i <
cameraNum; i++)
137 PvCameraIpSettingsGet(
cameraList[i].UniqueId,&Conf);
138 addr.s_addr = Conf.CurrentIpAddress;
140 camInfo.
access =
cameraList[i].PermittedAccess & ePvAccessMaster ? true :
false;
142 cameras.push_back(camInfo);
152 CHECK_ERR(PvCameraIpSettingsGet(guid, &Conf),
"Unable to retrieve IP address");
153 addr.s_addr = Conf.CurrentIpAddress;
154 std::stringstream ip;
160 static void openCamera(boost::function<tPvErr (tPvCameraInfo*)> info_fn,
161 boost::function<tPvErr (tPvAccessFlags)> open_fn)
165 CHECK_ERR( info_fn(&info),
"Unable to find requested camera" );
167 if (!(info.PermittedAccess & ePvAccessMaster))
169 "Unable to open camera as master. "
170 "Another process is already using it.");
172 CHECK_ERR( open_fn(ePvAccessMaster),
"Unable to open requested camera" );
176 : bufferSize_(bufferSize), FSTmode_(
None)
185 : bufferSize_(bufferSize), FSTmode_(
None)
187 unsigned long addr = inet_addr(ip_address);
188 tPvIpSettings settings;
189 openCamera(boost::bind(PvCameraInfoByAddr, addr, _1, &settings),
190 boost::bind(PvCameraOpenByAddr, addr, _1, &
handle_));
198 tPvUint32 maxPacketSize = 9000;
199 PvCaptureAdjustPacketSize(
handle_, maxPacketSize);
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" );
225 frames_[i].Context[0] = (
void*)
this;
228 PvLinkCallbackRegister(
Camera::kill, ePvLinkRemove,
this);
241 delete[] (
char*)
frames_[i].ImageBuffer;
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");
307 PvCommandRun(
handle_,
"AcquisitionStop");
316 PvAttrUint32Set(
handle_,
"EventsEnable1", 0);
324 CHECK_ERR( PvCommandRun(
handle_,
"FrameStartTriggerSoftware"),
"Couldn't trigger capture" );
325 CHECK_ERR( PvCaptureWaitForFrameDone(
handle_, frame, timeout_ms),
"couldn't capture frame");
327 if (frame->Status == ePvErrUnplugged || frame->Status == ePvErrCancelled )
331 CHECK_ERR( PvCaptureQueueFrame(
handle_, frame, NULL),
"Couldn't queue frame");
333 if (frame->Status == ePvErrSuccess)
335 if (frame->Status == ePvErrDataMissing || frame->Status == ePvErrTimeout)
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" );
361 if (PvAttrIsAvailable(
handle_,
"GainMode") == ePvErrSuccess)
364 "Couldn't set gain mode" );
369 "Couldn't set gain value" );
374 if (PvAttrIsAvailable(
handle_,
"WhitebalMode") == ePvErrSuccess)
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" );
439 return (PvAttrIsAvailable(
handle_, name.c_str()) == ePvErrSuccess);
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" );
462 boost::bind(PvAttrEnumGet,
handle_, name.c_str(), _1, _2, _3));
467 std::string err_msg =
"Couldn't get attribute " + name;
475 std::string err_msg =
"Couldn't get attribute " + name;
483 boost::bind(PvAttrStringGet,
handle_, name.c_str(), _1, _2, _3));
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;
531 CHECK_ERR( PvAttrRangeUint32(
handle_,
"StreamBytesPerSecond", &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_);
573 if (frame->Status == ePvErrUnplugged || frame->Status == ePvErrCancelled)
582 tPvInterface Interface,
584 unsigned long UniqueId)