31 const std::string & vendor,
32 const std::string & product,
33 const std::string & serial
36 typedef mx::verbose::vvv verboseT;
38 std::vector<std::string> devNames;
41 mx_error_check_rv(mx::ioutils::getFileNames(devNames,
"/sys/class/tty/",
"ttyUSB",
"",
""),-1);
52 for(
size_t i=0; i< devNames.size(); ++i)
54 struct udev_device *dev0;
56 dev0 = udev_device_new_from_syspath(udev, devNames[i].c_str());
60 std::cerr <<
"udev_device_new_from_syspath failed: " << strerror(errno) <<
"\n";
65 struct udev_device *dev;
67 dev = udev_device_get_parent_with_subsystem_devtype( dev0,
"usb",
"usb_device");
71 std::cerr <<
"udev_device_get_parent_with_subsystem_devtype failed: " << strerror(errno) <<
"\n";
73 udev_device_unref(dev0);
77 const char * idVendor = udev_device_get_sysattr_value( dev,
"idVendor" );
79 if(idVendor ==
nullptr)
81 udev_device_unref(dev0);
85 if( strcmp( idVendor, vendor.c_str()) != 0)
87 udev_device_unref(dev0);
91 const char * idProduct = udev_device_get_sysattr_value( dev,
"idProduct" );
93 if(idProduct ==
nullptr)
95 udev_device_unref(dev0);
99 if( strcmp( idProduct, product.c_str()) != 0)
101 udev_device_unref(dev0);
105 const char * dserial = udev_device_get_sysattr_value( dev,
"serial" );
107 if(dserial ==
nullptr)
111 udev_device_unref(dev0);
115 else if( strcmp( dserial, serial.c_str()) != 0 )
117 udev_device_unref(dev0);
122 boost::filesystem::path p(devNames[i]);
123 devName =
"/dev/" + p.filename().string();
125 udev_device_unref(dev0);
140 const std::string & vendor,
141 const std::string & product
144 std::vector<std::string> pdevNames;
148 typedef mx::verbose::vvv verboseT;
149 mx_error_check_rv(mx::ioutils::getFileNames(pdevNames,
"/sys/class/tty/",
"ttyUSB",
"",
""), -1);
159 for(
size_t i=0; i< pdevNames.size(); ++i)
161 struct udev_device *dev0;
163 dev0 = udev_device_new_from_syspath(udev, pdevNames[i].c_str());
170 struct udev_device * dev;
171 dev = udev_device_get_parent_with_subsystem_devtype( dev0,
"usb",
"usb_device");
175 udev_device_unref(dev0);
179 const char * idVendor = udev_device_get_sysattr_value( dev,
"idVendor" );
181 if(idVendor ==
nullptr)
183 udev_device_unref(dev0);
187 if( strcmp( idVendor, vendor.c_str()) != 0)
189 udev_device_unref(dev0);
193 const char * idProduct = udev_device_get_sysattr_value( dev,
"idProduct" );
195 if(idProduct ==
nullptr)
197 udev_device_unref(dev0);
201 if( strcmp( idProduct, product.c_str()) != 0)
203 udev_device_unref(dev0);
208 boost::filesystem::path p(pdevNames[i]);
209 devNames.push_back(
"/dev/" + p.filename().string());
211 udev_device_unref(dev0);
int ttyUSBDevName(std::string &devName, const std::string &vendor, const std::string &product, const std::string &serial)
Get the ttyUSB device name for a specific device.
int ttyUSBDevNames(std::vector< std::string > &devNames, const std::string &vendor, const std::string &product)
Get the ttyUSB device name for a set of devices specified by their vendor and product ids.