Forums › SM Series Discussions › SM API: smGetDeviceList() & smNetworkConfigGetDeviceList() bug
- This topic has 3 replies, 3 voices, and was last updated 1 hour, 30 minutes ago by
tschmitz.
- AuthorPosts
tschmitzParticipantHello, 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
Justin CrooksModeratorThanks for pointing this out. I’ll make sure the software department sees this.

RogerModerator- This reply was modified 19 hours, 17 minutes ago by
Roger.
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
tschmitzParticipantYup, 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
- This reply was modified 19 hours, 17 minutes ago by
- AuthorPosts
You must be logged in to reply to this topic.