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 key =
"";
286 for (MapCameraInterface::iterator it =
map_camera_.begin();
290 if (it->first.compare(key) == 0)
296 if (it->first.compare(key) == 0)
302 if (!found) key =
"";
312 StApi::IStDeviceReleasable *dev = p_iface->CreateIStDevice(
313 GenICam::gcstring(device_id.c_str()),
314 GenTL::DEVICE_ACCESS_CONTROL);
316 if (p_devinfo->GetTLType().compare(TLTypeU3VName) == 0)
322 else if (p_devinfo->GetTLType().compare(TLTypeGEVName) == 0)
336 omronsentech_camera::DeviceConnection msg =
338 ->GetIStSystemInfo(), dev->GetIStInterface(),
339 dev->GetIStDeviceInfo(), key,
true);
345 ROS_INFO(
"%s %s %d: %s (%s) is successfully initialized as %s",
346 __FILE__,__func__,__LINE__,
347 device_id.c_str(), device_displayname.c_str(), key.c_str());
350 catch(GenICam::GenericException &x)
352 ROS_ERROR(
"%s %s %d: Unable to open device %s (%s): %s",
353 __FILE__,__func__,__LINE__, device_id.c_str(),
354 device_displayname.c_str(), x.GetDescription());
360 omronsentech_camera::GetDeviceList::Request &req,
361 omronsentech_camera::GetDeviceList::Response &res)
369 size_t ifcount = p_tl->GetInterfaceCount();
370 for (
size_t j = 0; j < ifcount; j++)
372 StApi::IStInterface *p_iface = p_tl->GetIStInterface(j);
373 p_iface->UpdateDeviceList();
374 size_t devcount = p_iface->GetDeviceCount();
375 for (
size_t k = 0; k < devcount; k++)
377 const StApi::IStDeviceInfo *p_devinfo =
378 p_iface->GetIStDeviceInfo(k);
379 std::string device_id = std::string(p_devinfo->GetID());
380 std::string device_sn = std::string(p_devinfo->GetDisplayName());
390 res.device_list.push_back(it->second);
393 omronsentech_camera::DeviceConnection msg =
396 res.device_list.push_back(msg);
409 omronsentech_camera::GetModuleList::Request &req,
410 omronsentech_camera::GetModuleList::Response &res)
412 res.module_name_list.push_back(
"System");
413 res.module_name_list.push_back(
"Interface");
414 res.module_name_list.push_back(
"LocalDevice");
415 res.module_name_list.push_back(
"RemoteDevice");
416 res.module_name_list.push_back(
"DataStream");
423 omronsentech_camera::GetSDKInfo::Request &req,
424 omronsentech_camera::GetSDKInfo::Response &res)
426 res.sdk_version = StApi::GetStApiVersionText();
430 omronsentech_camera::GenTLInfo data;
431 const StApi::IStSystemInfo *info =
434 snprintf(gentl_ver,8,
"%d.%d", info->GetGenTLVersionMajor(),
435 info->GetGenTLVersionMinor());
436 data.vendor = info->GetVendor();
437 data.version = gentl_ver;
438 data.producer_version = info->GetVersion();
439 data.tltype = info->GetTLType();
440 data.full_path = info->GetPathName();
441 res.gentl_info_list.push_back(data);
447 omronsentech_camera::GetGigEIPi::Request &req,
448 omronsentech_camera::GetGigEIPi::Response &res)
455 for (
size_t j = 0; j < p_tl->GetInterfaceCount(); j++)
457 StApi::IStInterface *p_iface = p_tl->GetIStInterface(j);
458 if (p_iface->GetIStInterfaceInfo()->GetTLType()
459 .compare(TLTypeGEVName) != 0)
464 p_iface->UpdateDeviceList();
465 GenApi::CNodeMapPtr p_nodemap(p_iface->GetIStPort()->GetINodeMap());
466 GenApi::CIntegerPtr p_integer_ip(
467 p_nodemap->GetNode(
"GevInterfaceSubnetIPAddress"));
468 GenApi::CIntegerPtr p_integer_subnet(
469 p_nodemap->GetNode(
"GevInterfaceSubnetMask"));
470 GenApi::CIntegerPtr p_integer_gw(
471 p_nodemap->GetNode(
"GevInterfaceGateway"));
472 res.if_ip_address = p_integer_ip->ToString();
473 res.if_ip_mask = p_integer_subnet->ToString();
474 res.if_ip_gateway = p_integer_gw->ToString();
476 GenApi::CIntegerPtr pDeviceSelector(
477 p_nodemap->GetNode(
"DeviceSelector"));
478 const int64_t nMaxIndex = pDeviceSelector->GetMax();
479 for (int64_t k = 0; k <= nMaxIndex; k++)
481 pDeviceSelector->SetValue(k);
482 GenApi::CStringPtr pIStringDeviceID(p_nodemap->GetNode(
"DeviceID"));
483 GenICam::gcstring strDeviceID = pIStringDeviceID->GetValue();
485 if (strDeviceID.compare(req.camera_id.c_str()) != 0)
489 GenApi::CIntegerPtr p_integer_ip(
490 p_nodemap->GetNode(
"GevDeviceIPAddress"));
491 GenApi::CIntegerPtr p_integer_subnet(
492 p_nodemap->GetNode(
"GevDeviceSubnetMask"));
493 GenApi::CIntegerPtr p_integer_gw(
494 p_nodemap->GetNode(
"GevDeviceGateway"));
495 res.dev_ip_address = p_integer_ip->ToString();
496 res.dev_ip_mask = p_integer_subnet->ToString();
497 res.dev_ip_gateway = p_integer_gw->ToString();
502 ROS_ERROR(
"The Camera with the given ID %s could not be found.",
503 req.camera_id.c_str());
510 omronsentech_camera::SetGigEIPi::Request &req,
511 omronsentech_camera::SetGigEIPi::Response &res)
518 for (
size_t j = 0; j < p_tl->GetInterfaceCount(); j++)
520 StApi::IStInterface *p_iface = p_tl->GetIStInterface(j);
521 if (p_iface->GetIStInterfaceInfo()->GetTLType()
522 .compare(TLTypeGEVName) != 0)
527 p_iface->UpdateDeviceList();
528 GenApi::CNodeMapPtr p_nodemap(p_iface->GetIStPort()->GetINodeMap());
529 GenApi::CIntegerPtr pDeviceSelector(
530 p_nodemap->GetNode(
"DeviceSelector"));
531 const int64_t nMaxIndex = pDeviceSelector->GetMax();
532 for (int64_t k = 0; k <= nMaxIndex; k++)
534 pDeviceSelector->SetValue(k);
535 GenApi::CStringPtr pIStringDeviceID(p_nodemap->GetNode(
"DeviceID"));
536 GenICam::gcstring strDeviceID = pIStringDeviceID->GetValue();
538 if (strDeviceID.compare(req.camera_id.c_str()) != 0)
543 GenApi::CIntegerPtr p_integer_ip(
544 p_nodemap->GetNode(
"GevDeviceForceIPAddress"));
545 GenApi::CIntegerPtr p_integer_subnet(
546 p_nodemap->GetNode(
"GevDeviceForceSubnetMask"));
547 GenApi::CIntegerPtr p_integer_gw(
548 p_nodemap->GetNode(
"GevDeviceForceGateway"));
549 GenApi::CCommandPtr pCommand(
550 p_nodemap->GetNode(
"GevDeviceForceIP"));
552 p_integer_ip->SetValue(ntohl(inet_addr(req.ip_address.c_str())));
553 p_integer_subnet->SetValue(ntohl(inet_addr(req.ip_mask.c_str())));
554 p_integer_gw->SetValue(ntohl(inet_addr(req.ip_gateway.c_str())));
560 ROS_ERROR(
"The Camera with the given ID %s could not be found.",
561 req.camera_id.c_str());
568 const StApi::IStSystemInfo *p_tlinfo, StApi::IStInterface* p_iface,
569 const StApi::IStDeviceInfo *p_devinfo, std::string device_namespace,
572 omronsentech_camera::DeviceConnection msg;
575 msg.device_id = p_devinfo->GetID().c_str();
576 msg.device_model = p_devinfo->GetModel().c_str();
577 msg.device_serial = p_devinfo->GetSerialNumber().c_str();
578 msg.device_namespace = device_namespace;
579 msg.device_tltype = p_devinfo->GetTLType().c_str();
581 if (msg.device_tltype.compare(TLTypeGEVName) == 0)
585 GenApi::CNodeMapPtr p_nodemap(p_iface->GetIStPort()->GetINodeMap());
586 GenApi::CIntegerPtr p_integer_ip(
587 p_nodemap->GetNode(
"GevInterfaceSubnetIPAddress"));
588 GenApi::CIntegerPtr p_integer_subnet(
589 p_nodemap->GetNode(
"GevInterfaceSubnetMask"));
590 GenApi::CIntegerPtr p_integer_gw(
591 p_nodemap->GetNode(
"GevInterfaceGateway"));
592 msg.device_tl_specific_field.push_back(
"if_ip_address");
593 msg.device_tl_specific_value.push_back(
594 p_integer_ip->ToString().c_str());
595 msg.device_tl_specific_field.push_back(
"if_ip_mask");
596 msg.device_tl_specific_value.
597 push_back(p_integer_subnet->ToString().c_str());
598 msg.device_tl_specific_field.push_back(
"if_ip_gateway");
599 msg.device_tl_specific_value.push_back(
600 p_integer_gw->ToString().c_str());
602 GenApi::CIntegerPtr pDeviceSelector(
603 p_nodemap->GetNode(
"DeviceSelector"));
604 const int64_t nMaxIndex = pDeviceSelector->GetMax();
605 for (int64_t k = 0; k <= nMaxIndex; k++)
607 pDeviceSelector->SetValue(k);
608 GenApi::CStringPtr pIStringDeviceID(p_nodemap->GetNode(
"DeviceID"));
609 GenICam::gcstring strDeviceID = pIStringDeviceID->GetValue();
611 if (strDeviceID.compare(msg.device_id.c_str()) != 0)
615 GenApi::CIntegerPtr p_integer_ip(
616 p_nodemap->GetNode(
"GevDeviceIPAddress"));
617 GenApi::CIntegerPtr p_integer_subnet(
618 p_nodemap->GetNode(
"GevDeviceSubnetMask"));
619 GenApi::CIntegerPtr p_integer_gw(
620 p_nodemap->GetNode(
"GevDeviceGateway"));
621 msg.device_tl_specific_field.push_back(
"dev_ip_address");
622 msg.device_tl_specific_value.
623 push_back(p_integer_ip->ToString().c_str());
624 msg.device_tl_specific_field.push_back(
"dev_ip_mask");
625 msg.device_tl_specific_value.
626 push_back(p_integer_subnet->ToString().c_str());
627 msg.device_tl_specific_field.push_back(
"dev_ip_gateway");
628 msg.device_tl_specific_value.
629 push_back(p_integer_gw->ToString().c_str());
637 msg.connected = connected;
641 snprintf(gentl_ver,8,
"%d.%d", p_tlinfo->GetGenTLVersionMajor(),
642 p_tlinfo->GetGenTLVersionMinor());
643 msg.device_gentl_info.vendor = p_tlinfo->GetVendor();
644 msg.device_gentl_info.version = gentl_ver;
645 msg.device_gentl_info.producer_version = p_tlinfo->GetVersion();
646 msg.device_gentl_info.tltype = p_tlinfo->GetTLType();
647 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.
void publish(const boost::shared_ptr< M > &message) const
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)
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.