diff --git a/README.md b/README.md index 8291366..0d91ecf 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ aka Use with Multiple Devices By default, the ublox_dgnss node will search for and connect to the first device which matches the ublox USB ID's (vendor ID of 0x1546 and product ID of 0x01a9). If multiple devices are connected simultaneously, the remaining devices will be ignored. In this situation you have no control over which device is used, since the order in which they are found may depend on the order in which they were physically attached to the host. -If you have multiple ublox devices attached simultaneously and wish to connect to a specific device, you can specify a launch parameter "DEVICE_SERIAL_STRING". The node will then search for and connect to the first device with this matching serial string. The device serial string itself should be programmed into the ublox device beforehand using u-center software. +If you have multiple ublox devices attached simultaneously and wish to connect to a specific device, you can specify a launch parameter "DEVICE_SERIAL_STRING". The node will then search for and connect to the first device with this matching serial string. The device serial string "CFG-USB-SERIAL_NO_STRx" itself should be programmed into the ublox device beforehand using u-center software. The frame ID used in ROS2 messages for that device can also be specified using the launch parameter "FRAME_ID". diff --git a/ublox_dgnss_node/include/ublox_dgnss_node/usb.hpp b/ublox_dgnss_node/include/ublox_dgnss_node/usb.hpp index b2500ab..e283b8f 100644 --- a/ublox_dgnss_node/include/ublox_dgnss_node/usb.hpp +++ b/ublox_dgnss_node/include/ublox_dgnss_node/usb.hpp @@ -115,7 +115,7 @@ class Connection private: libusb_device_handle * open_device_with_serial_string( libusb_context * ctx, int vendor_id, - int product_id, std::string serial_str); + int product_id, std::string serial_str, char * serial_num_string); // this is called after the out transfer to USB from HOST has been received by libusb void callback_out(struct libusb_transfer * transfer); // this is called when the stat for in is available - from USB in HOST diff --git a/ublox_dgnss_node/src/usb.cpp b/ublox_dgnss_node/src/usb.cpp index 2b6455a..77ef3ff 100644 --- a/ublox_dgnss_node/src/usb.cpp +++ b/ublox_dgnss_node/src/usb.cpp @@ -93,7 +93,8 @@ void Connection::init() libusb_device_handle * Connection::open_device_with_serial_string( libusb_context * ctx, int vendor_id, int product_id, - std::string serial_str) + std::string serial_str, + char *serial_num_string) { libusb_device_handle * devHandle = nullptr; int rc = 0; @@ -129,7 +130,7 @@ libusb_device_handle * Connection::open_device_with_serial_string( throw std::string("Error opening device: ") + libusb_error_name(rc); } - char serial_num_string[256]; + // Read the serial number string rc = libusb_get_string_descriptor_ascii( devHandle, desc.iSerialNumber, @@ -162,13 +163,15 @@ libusb_device_handle * Connection::open_device_with_serial_string( bool Connection::open_device() { - devh_ = open_device_with_serial_string(ctx_, vendor_id_, product_id_, serial_str_); + char serial_num_string[256]; + devh_ = open_device_with_serial_string(ctx_, vendor_id_, product_id_, serial_str_, serial_num_string); if (!devh_) { if (serial_str_.empty()) { throw std::string("Error finding USB device"); // std::cerr << "Error finding ublox USB device (no serial string supplied)"; } else { - throw std::string("Error finding USB device with specified serial string"); + throw std::string("Error finding USB device with specified serial string, looking for \"") + + serial_str_ + "\" however \"" + serial_num_string + "\" was found."; // std::cerr << "Error finding ublox USB device with specified serial string"; } return false;