34 #include <omronsentech_camera/DeviceConnection.h> 41 #define CATCH_GIGECALL_ERR() catch(const StApi::CStGenTLErrorException &x) \ 43 ROS_ERROR("%s %s %d: \n\tGenTL error: %d %s", \ 44 __FILE__,__func__,__LINE__, \ 45 x.GetError(), x.GetDescription());\ 48 catch(GenICam::GenericException &x)\ 50 ROS_ERROR("%s %s %d: \n\tGenICam error: %s", \ 51 __FILE__,__func__,__LINE__, \ 59 msg_device_connection_(nh_.advertise<omronsentech_camera::DeviceConnection>(
61 srv_get_device_list_(nh_.advertiseService(
64 srv_get_module_list_(nh_.advertiseService(
67 srv_get_sdk_info_(nh_.advertiseService(
70 srv_get_gige_ip_i_(nh_.advertiseService(
73 srv_set_gige_ip_i_(nh_.advertiseService(
107 for (MapCameraInterface::iterator it =
map_camera_.begin();
110 if (it->second !=
nullptr)
120 std::vector<std::string> camera_to_connect;
123 std::string allowed=
"Allowed camera: ";
130 allowed +=
"First found camera";
137 for (
size_t i = 0; i < camera_to_connect.size(); i++)
141 allowed += camera_to_connect[i] +
" ";
144 ROS_DEBUG(
"Allowed to connect: %s", allowed.c_str());
146 for (uint32_t i = StApi::StSystemVendor_Sentech;
147 i < StApi::StSystemVendor_Count; i++)
149 StApi::EStSystemVendor_t vendor = (StApi::EStSystemVendor_t)i;
153 StApi::CreateIStSystem(vendor, StApi::StInterfaceType_All));
155 catch(
const GenICam::GenericException &x)
157 if (vendor == StApi::StSystemVendor_Sentech)
160 "%s %s %d: Unable to initialize OMRON SENTECH GenTL Producer: %s",
161 __FILE__,__func__,__LINE__, x.GetDescription());
169 p_tl->UpdateInterfaceList();
178 for (MapCameraInterface::iterator it =
map_camera_.begin();
190 it2->second.connected =
false;
195 ROS_INFO(
"Device %s is disconnected.", it2->first.c_str());
206 if (connect_first_camera_only)
215 bool all_connected =
true;
216 for (MapCameraInterface::iterator it =
map_camera_.begin();
219 if (it->second ==
nullptr)
221 all_connected =
false;
239 size_t ifcount = p_tl->GetInterfaceCount();
240 for (
size_t j = 0; j < ifcount; j++)
242 StApi::IStInterface *p_iface = p_tl->GetIStInterface(j);
243 p_iface->UpdateDeviceList();
245 size_t devcount = p_iface->GetDeviceCount();
246 for (
size_t k = 0; k < devcount; k++)
248 if (p_iface->IsDeviceAvailable(k, GenTL::DEVICE_ACCESS_CONTROL))
250 const StApi::IStDeviceInfo *p_devinfo =
251 p_iface->GetIStDeviceInfo(k);
253 if (init_ok && connect_first_camera_only)
269 const StApi::IStDeviceInfo *p_devinfo)
271 if (p_iface ==
nullptr || p_devinfo ==
nullptr)
276 std::string device_id = std::string(p_devinfo->GetID());
277 std::string device_displayname = std::string(p_devinfo->GetDisplayName());
278 std::string device_userdefinedname = std::string(p_devinfo->GetUserDefinedName() );
279 std::string key =
"";
287 for (MapCameraInterface::iterator it =
map_camera_.begin();
291 if (it->first.compare(key) == 0)
297 if (it->first.compare(key) == 0)
303 if (it->first.compare(key) == 0)
309 if (!found) key =
"";
319 StApi::IStDeviceReleasable *dev = p_iface->CreateIStDevice(
320 GenICam::gcstring(device_id.c_str()),
321 GenTL::DEVICE_ACCESS_CONTROL);
323 if (p_devinfo->GetTLType().compare(TLTypeU3VName) == 0)
329 else if (p_devinfo->GetTLType().compare(TLTypeGEVName) == 0)
343 omronsentech_camera::DeviceConnection msg =
345 ->GetIStSystemInfo(), dev->GetIStInterface(),
346 dev->GetIStDeviceInfo(), key,
true);
352 ROS_INFO(
"%s %s %d: %s (%s) is successfully initialized as %s",
353 __FILE__,__func__,__LINE__,
354 device_id.c_str(), device_displayname.c_str(), key.c_str());
357 catch(GenICam::GenericException &x)
359 ROS_ERROR(
"%s %s %d: Unable to open device %s (%s): %s",
360 __FILE__,__func__,__LINE__, device_id.c_str(),
361 device_displayname.c_str(), x.GetDescription());
367 omronsentech_camera::GetDeviceList::Request &req,
368 omronsentech_camera::GetDeviceList::Response &res)
376 size_t ifcount = p_tl->GetInterfaceCount();
377 for (
size_t j = 0; j < ifcount; j++)
379 StApi::IStInterface *p_iface = p_tl->GetIStInterface(j);
380 p_iface->UpdateDeviceList();
381 size_t devcount = p_iface->GetDeviceCount();
382 for (
size_t k = 0; k < devcount; k++)
384 const StApi::IStDeviceInfo *p_devinfo =
385 p_iface->GetIStDeviceInfo(k);
386 std::string device_id = std::string(p_devinfo->GetID());
387 std::string device_sn = std::string(p_devinfo->GetDisplayName());
397 res.device_list.push_back(it->second);
400 omronsentech_camera::DeviceConnection msg =
403 res.device_list.push_back(msg);
416 omronsentech_camera::GetModuleList::Request &req,
417 omronsentech_camera::GetModuleList::Response &res)
419 res.module_name_list.push_back(
"System");
420 res.module_name_list.push_back(
"Interface");
421 res.module_name_list.push_back(
"LocalDevice");
422 res.module_name_list.push_back(
"RemoteDevice");
423 res.module_name_list.push_back(
"DataStream");
430 omronsentech_camera::GetSDKInfo::Request &req,
431 omronsentech_camera::GetSDKInfo::Response &res)
433 res.sdk_version = StApi::GetStApiVersionText();
437 omronsentech_camera::GenTLInfo data;
438 const StApi::IStSystemInfo *info =
441 snprintf(gentl_ver,8,
"%d.%d", info->GetGenTLVersionMajor(),
442 info->GetGenTLVersionMinor());
443 data.vendor = info->GetVendor();
444 data.version = gentl_ver;
445 data.producer_version = info->GetVersion();
446 data.tltype = info->GetTLType();
447 data.full_path = info->GetPathName();
448 res.gentl_info_list.push_back(data);
454 omronsentech_camera::GetGigEIPi::Request &req,
455 omronsentech_camera::GetGigEIPi::Response &res)
462 for (
size_t j = 0; j < p_tl->GetInterfaceCount(); j++)
464 StApi::IStInterface *p_iface = p_tl->GetIStInterface(j);
465 if (p_iface->GetIStInterfaceInfo()->GetTLType()
466 .compare(TLTypeGEVName) != 0)
471 p_iface->UpdateDeviceList();
472 GenApi::CNodeMapPtr p_nodemap(p_iface->GetIStPort()->GetINodeMap());
473 GenApi::CIntegerPtr p_integer_ip(
474 p_nodemap->GetNode(
"GevInterfaceSubnetIPAddress"));
475 GenApi::CIntegerPtr p_integer_subnet(
476 p_nodemap->GetNode(
"GevInterfaceSubnetMask"));
477 GenApi::CIntegerPtr p_integer_gw(
478 p_nodemap->GetNode(
"GevInterfaceGateway"));
479 res.if_ip_address = p_integer_ip->ToString();
480 res.if_ip_mask = p_integer_subnet->ToString();
481 res.if_ip_gateway = p_integer_gw->ToString();
483 GenApi::CIntegerPtr pDeviceSelector(
484 p_nodemap->GetNode(
"DeviceSelector"));
485 const int64_t nMaxIndex = pDeviceSelector->GetMax();
486 for (int64_t k = 0; k <= nMaxIndex; k++)
488 pDeviceSelector->SetValue(k);
489 GenApi::CStringPtr pIStringDeviceID(p_nodemap->GetNode(
"DeviceID"));
490 GenICam::gcstring strDeviceID = pIStringDeviceID->GetValue();
492 if (strDeviceID.compare(req.camera_id.c_str()) != 0)
496 GenApi::CIntegerPtr p_integer_ip(
497 p_nodemap->GetNode(
"GevDeviceIPAddress"));
498 GenApi::CIntegerPtr p_integer_subnet(
499 p_nodemap->GetNode(
"GevDeviceSubnetMask"));
500 GenApi::CIntegerPtr p_integer_gw(
501 p_nodemap->GetNode(
"GevDeviceGateway"));
502 res.dev_ip_address = p_integer_ip->ToString();
503 res.dev_ip_mask = p_integer_subnet->ToString();
504 res.dev_ip_gateway = p_integer_gw->ToString();
509 ROS_ERROR(
"The Camera with the given ID %s could not be found.",
510 req.camera_id.c_str());
517 omronsentech_camera::SetGigEIPi::Request &req,
518 omronsentech_camera::SetGigEIPi::Response &res)
525 for (
size_t j = 0; j < p_tl->GetInterfaceCount(); j++)
527 StApi::IStInterface *p_iface = p_tl->GetIStInterface(j);
528 if (p_iface->GetIStInterfaceInfo()->GetTLType()
529 .compare(TLTypeGEVName) != 0)
534 p_iface->UpdateDeviceList();
535 GenApi::CNodeMapPtr p_nodemap(p_iface->GetIStPort()->GetINodeMap());
536 GenApi::CIntegerPtr pDeviceSelector(
537 p_nodemap->GetNode(
"DeviceSelector"));
538 const int64_t nMaxIndex = pDeviceSelector->GetMax();
539 for (int64_t k = 0; k <= nMaxIndex; k++)
541 pDeviceSelector->SetValue(k);
542 GenApi::CStringPtr pIStringDeviceID(p_nodemap->GetNode(
"DeviceID"));
543 GenICam::gcstring strDeviceID = pIStringDeviceID->GetValue();
545 if (strDeviceID.compare(req.camera_id.c_str()) != 0)
550 GenApi::CIntegerPtr p_integer_ip(
551 p_nodemap->GetNode(
"GevDeviceForceIPAddress"));
552 GenApi::CIntegerPtr p_integer_subnet(
553 p_nodemap->GetNode(
"GevDeviceForceSubnetMask"));
554 GenApi::CIntegerPtr p_integer_gw(
555 p_nodemap->GetNode(
"GevDeviceForceGateway"));
556 GenApi::CCommandPtr pCommand(
557 p_nodemap->GetNode(
"GevDeviceForceIP"));
559 p_integer_ip->SetValue(ntohl(inet_addr(req.ip_address.c_str())));
560 p_integer_subnet->SetValue(ntohl(inet_addr(req.ip_mask.c_str())));
561 p_integer_gw->SetValue(ntohl(inet_addr(req.ip_gateway.c_str())));
567 ROS_ERROR(
"The Camera with the given ID %s could not be found.",
568 req.camera_id.c_str());
575 const StApi::IStSystemInfo *p_tlinfo, StApi::IStInterface* p_iface,
576 const StApi::IStDeviceInfo *p_devinfo, std::string device_namespace,
579 omronsentech_camera::DeviceConnection msg;
582 msg.device_id = p_devinfo->GetID().c_str();
583 msg.device_model = p_devinfo->GetModel().c_str();
584 msg.device_serial = p_devinfo->GetSerialNumber().c_str();
585 msg.device_namespace = device_namespace;
586 msg.device_tltype = p_devinfo->GetTLType().c_str();
588 if (msg.device_tltype.compare(TLTypeGEVName) == 0)
592 GenApi::CNodeMapPtr p_nodemap(p_iface->GetIStPort()->GetINodeMap());
593 GenApi::CIntegerPtr p_integer_ip(
594 p_nodemap->GetNode(
"GevInterfaceSubnetIPAddress"));
595 GenApi::CIntegerPtr p_integer_subnet(
596 p_nodemap->GetNode(
"GevInterfaceSubnetMask"));
597 GenApi::CIntegerPtr p_integer_gw(
598 p_nodemap->GetNode(
"GevInterfaceGateway"));
599 msg.device_tl_specific_field.push_back(
"if_ip_address");
600 msg.device_tl_specific_value.push_back(
601 p_integer_ip->ToString().c_str());
602 msg.device_tl_specific_field.push_back(
"if_ip_mask");
603 msg.device_tl_specific_value.
604 push_back(p_integer_subnet->ToString().c_str());
605 msg.device_tl_specific_field.push_back(
"if_ip_gateway");
606 msg.device_tl_specific_value.push_back(
607 p_integer_gw->ToString().c_str());
609 GenApi::CIntegerPtr pDeviceSelector(
610 p_nodemap->GetNode(
"DeviceSelector"));
611 const int64_t nMaxIndex = pDeviceSelector->GetMax();
612 for (int64_t k = 0; k <= nMaxIndex; k++)
614 pDeviceSelector->SetValue(k);
615 GenApi::CStringPtr pIStringDeviceID(p_nodemap->GetNode(
"DeviceID"));
616 GenICam::gcstring strDeviceID = pIStringDeviceID->GetValue();
618 if (strDeviceID.compare(msg.device_id.c_str()) != 0)
622 GenApi::CIntegerPtr p_integer_ip(
623 p_nodemap->GetNode(
"GevDeviceIPAddress"));
624 GenApi::CIntegerPtr p_integer_subnet(
625 p_nodemap->GetNode(
"GevDeviceSubnetMask"));
626 GenApi::CIntegerPtr p_integer_gw(
627 p_nodemap->GetNode(
"GevDeviceGateway"));
628 msg.device_tl_specific_field.push_back(
"dev_ip_address");
629 msg.device_tl_specific_value.
630 push_back(p_integer_ip->ToString().c_str());
631 msg.device_tl_specific_field.push_back(
"dev_ip_mask");
632 msg.device_tl_specific_value.
633 push_back(p_integer_subnet->ToString().c_str());
634 msg.device_tl_specific_field.push_back(
"dev_ip_gateway");
635 msg.device_tl_specific_value.
636 push_back(p_integer_gw->ToString().c_str());
644 msg.connected = connected;
648 snprintf(gentl_ver,8,
"%d.%d", p_tlinfo->GetGenTLVersionMajor(),
649 p_tlinfo->GetGenTLVersionMinor());
650 msg.device_gentl_info.vendor = p_tlinfo->GetVendor();
651 msg.device_gentl_info.version = gentl_ver;
652 msg.device_gentl_info.producer_version = p_tlinfo->GetVersion();
653 msg.device_gentl_info.tltype = p_tlinfo->GetTLType();
654 msg.device_gentl_info.full_path = p_tlinfo->GetPathName();
bool getSDKInfoCallback(omronsentech_camera::GetSDKInfo::Request &req, omronsentech_camera::GetSDKInfo::Response &res)
Class to control a connected GigEVision camera.
ros::Publisher msg_device_connection_
ros::ServiceServer srv_get_gige_ip_i_
bool getModuleListCallback(omronsentech_camera::GetModuleList::Request &req, omronsentech_camera::GetModuleList::Response &res)
Class to control a connected GigEVision camera.
bool setGigEIPCallback(omronsentech_camera::SetGigEIPi::Request &req, omronsentech_camera::SetGigEIPi::Response &res)
Class implementation for stcamera_node.
Class to control a connected USB3Vision camera.
bool getGigEIPCallback(omronsentech_camera::GetGigEIPi::Request &req, omronsentech_camera::GetGigEIPi::Response &res)
bool initializeCamera(StApi::IStInterface *p_iface, const StApi::IStDeviceInfo *p_devinfo)
void publish(const boost::shared_ptr< M > &message) const
MapCameraInterface map_camera_
StApi::CIStSystemPtrArray stapi_systems_
ros::ServiceServer srv_get_sdk_info_
bool connectFirstCameraOnly()
void loadCameraList(const ros::NodeHandle &nh, std::vector< std::string > &camera_to_connect)
Base class to control a connected camera.
Class implementation for stcamera_node.
bool getDeviceListCallback(omronsentech_camera::GetDeviceList::Request &req, omronsentech_camera::GetDeviceList::Response &res)
MapDeviceConnection map_connection_
std::string getNamespace(std::string camera_id)
std::mutex mtx_update_device_list_
#define STSRV_G_module_list
std::mutex mtx_map_camera_
ros::ServiceServer srv_get_device_list_
omronsentech_camera::DeviceConnection fillDeviceConnectionData(const StApi::IStSystemInfo *p_tlinfo, StApi::IStInterface *p_iface, const StApi::IStDeviceInfo *p_devinfo, std::string device_namespace="", bool connected=false)
#define CATCH_GIGECALL_ERR()
#define STMSG_device_connection
#define STSRV_G_device_list
ros::ServiceServer srv_set_gige_ip_i_
ros::ServiceServer srv_get_module_list_
Class to control a connected GigEVision camera.