Hi team,
Thank you for the great servos and the well-maintained open source codes. Recently I noticed that I cannot connect and control two or more serial ports simultanously by using C version SDK (and C# P/invoke as well) on Windows.
How to reproduce the issue
In the example C program for multi-port handling, we should create a PortHandler for EACH serial port by the following code:
int port_num1 = portHandler(DEVICENAME1);
int port_num2 = portHandler(DEVICENAME2);
However in the real world, port_num2 returns 0 (which is equal to port_num1), thus the access to the first device is lost. I believe port_num2 should be 1 by design.
My work-around
After digging into the source code, I found the following part of portHandlerWindows function in DynamixelSDK/c/src/dynamixel_sdk/port_handler_windows.c might be the issue.
for (port_num = 0; port_num < g_used_port_num; port_num++)
{
if (portData[port_num].serial_handle != INVALID_HANDLE_VALUE) // ******* Should be == rather than != ?
break;
}
if (port_num == g_used_port_num)
{
g_used_port_num++;
portData = (PortData*)realloc(portData, g_used_port_num * sizeof(PortData));
g_is_using = (uint8_t*)realloc(g_is_using, g_used_port_num * sizeof(uint8_t));
}
If the first serial port opens correctly and gets a valid handle, the validation in Line 78 breaks the for-loop, leaving port_num as 0 at the second device, thus mistakenly writes the information for the second port to portData[0]. By changing != to == in Line 78 solves my problem (seemingly).
Please help review this. If this is the case, the Linux/mac version might also need update respondingly.
Best,
Yusi
Hi team,
Thank you for the great servos and the well-maintained open source codes. Recently I noticed that I cannot connect and control two or more serial ports simultanously by using C version SDK (and C# P/invoke as well) on Windows.
How to reproduce the issue
In the example C program for multi-port handling, we should create a PortHandler for EACH serial port by the following code:
However in the real world,
port_num2returns 0 (which is equal toport_num1), thus the access to the first device is lost. I believeport_num2should be 1 by design.My work-around
After digging into the source code, I found the following part of
portHandlerWindowsfunction inDynamixelSDK/c/src/dynamixel_sdk/port_handler_windows.cmight be the issue.If the first serial port opens correctly and gets a valid handle, the validation in Line 78 breaks the
for-loop, leavingport_numas 0 at the second device, thus mistakenly writes the information for the second port toportData[0]. By changing!=to==in Line 78 solves my problem (seemingly).Please help review this. If this is the case, the Linux/mac version might also need update respondingly.
Best,
Yusi