The brand-new PN400 Phase Noise Test System is available for purchase! →

SM API: smGetDeviceList() & smNetworkConfigGetDeviceList() bug

Forums › SM Series Discussions › SM API: smGetDeviceList() & smNetworkConfigGetDeviceList() bug

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #254690
    tschmitz
    Participant

    Hello, I think I discovered a bug with device discovery.

    When I run the following code with an SM200C connected (both USB-2.0 and 10GbE SFP+ connected), I get no devices found.

    
        int serial_numbers[SM_MAX_DEVICES], count;
        int net_serials[SM_MAX_DEVICES], net_count;
        int all_serials[SM_MAX_DEVICES * 2] = {0}, all_count = 0;
    
        SmStatus status = smGetDeviceList(serial_numbers, &count);
        LOG_DBG("Fetched %d serial numbers from <code>smGetDeviceList</code>", count);
    
        if (status != smNoError) {
            throw std::runtime_error(smGetErrorString(status));
        }
    
        status = smNetworkConfigGetDeviceList(net_serials, &net_count);
        LOG_DBG("Fetched %d serial numbers from <code>smNetworkConfigGetDeviceList</code>",
                net_count);
    
        if (status != smNoError) {
            throw std::runtime_error(smGetErrorString(status));
        }
    
        for (size_t i = 0; i < count; i++) {
            all_serials[all_count] = serial_numbers[i];
            all_count++;
        }
    
        for (size_t i = 0; i < net_count; i++) {
            all_serials[all_count] = net_serials[i];
            all_count++;
        }
    

    I also found if I add a delay of roughly 1.5 seconds between the two API calls, it correctly finds the SM200C. Reversing the API calls also works, but I have a feeling that it breaks discovery for the SM200B/SM435B.

    OS: Ubuntu 22.04
    API Version: 2.3.8
    C++ Standard: C++11
    CPU: AMD Ryzen 9 9955HX

    • This topic was modified 8 months ago by tschmitz. Reason: Additional info
    • This topic was modified 8 months ago by tschmitz. Reason: Formatting
    #254723
    Justin CrooksJustin Crooks
    Moderator

    Thanks for pointing this out. I’ll make sure the software department sees this.

    #254724
    RogerRoger
    Moderator

    Hi tschmitz,

    The issue appears to be that the net_count variable is uninitialized. The smNetworkConfigGetDeviceList function uses its pararameter deviceCount to determine how large the serials array is, so it can return a maximum of that many devices (zero in this case).

    In other words, the second line of code should be: int net_serials[SM_MAX_DEVICES], net_count = SM_MAX_DEVICES;

    I know it is odd that the seemingly equivalent function for USB devices (SM200B/SM435B) does not have this requirement.

    Let me know if this doesn’t fix it.

    – Roger

    • This reply was modified 7 months, 4 weeks ago by RogerRoger.
    #254727
    tschmitz
    Participant

    Yup, that solved it! I probably should have consulted the documentation first…

    
    [in,out]	deviceCount	Point to int that contains the size of the serials array. When the function returns it will contain the number of devices returned.
    

    – Tom

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.