Tell USB bus and address when ftdi open fails, when bus and addr both non-zero.

This commit is contained in:
Haakan T Johansson 2023-07-10 08:19:58 +02:00
parent 3955a70843
commit 4f7a4c33aa
1 changed files with 12 additions and 2 deletions

View File

@ -156,8 +156,18 @@ void FTDIpp_MPSSE::open_device(const std::string &serial, unsigned int baudrate)
ret = ftdi_usb_open_bus_addr(_ftdi, _bus, _addr); ret = ftdi_usb_open_bus_addr(_ftdi, _bus, _addr);
#endif #endif
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "unable to open ftdi device: %d (%s)\n", char description[256];
ret, ftdi_get_error_string(_ftdi)); if (_bus == 0 || _addr == 0)
snprintf(description, sizeof(description), "");
else
#if (FTDI_VERSION < 104)
snprintf(description, sizeof(description), "");
#else
snprintf(description, sizeof(description), " (USB bus %d addr %d)",
_bus, _addr);
#endif
fprintf(stderr, "unable to open ftdi device: %d (%s)%s\n",
ret, ftdi_get_error_string(_ftdi), description);
ftdi_free(_ftdi); ftdi_free(_ftdi);
throw std::runtime_error("unable to open ftdi device"); throw std::runtime_error("unable to open ftdi device");
} }