From 4f7a4c33aa7cf613c723f4524fa5d8a24b1f4513 Mon Sep 17 00:00:00 2001 From: Haakan T Johansson Date: Mon, 10 Jul 2023 08:19:58 +0200 Subject: [PATCH] Tell USB bus and address when ftdi open fails, when bus and addr both non-zero. --- src/ftdipp_mpsse.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ftdipp_mpsse.cpp b/src/ftdipp_mpsse.cpp index 646bc37a6d..c3b6abc0a5 100644 --- a/src/ftdipp_mpsse.cpp +++ b/src/ftdipp_mpsse.cpp @@ -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); #endif if (ret < 0) { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", - ret, ftdi_get_error_string(_ftdi)); + char description[256]; + 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); throw std::runtime_error("unable to open ftdi device"); }