Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix COM port enumeration for ESP32 #2134

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,22 @@ HRESULT Library_sys_io_ser_native_System_IO_Ports_SerialPort::GetDeviceSelector_
NANOCLR_HEADER();

// declare the device selector string whose max size is "COM1,COM2,COM3" + terminator
// COM1 is being used for VS debug, so it's not available
char deviceSelectorString[10] = "COM2,COM3";
// and init with the terminator
char deviceSelectorString[14 + 1] = {0};

// unless the build is configure to use USB CDC, COM1 is being used for VS debug, so it's not available
#if defined(CONFIG_USB_CDC_ENABLED)
strcat(deviceSelectorString, "COM1,");
#endif
#if defined(UART_NUM_1)
strcat(deviceSelectorString, "COM2,");
#endif
#if defined(UART_NUM_2)
strcat(deviceSelectorString, "COM3,");
#endif

// replace the last comma with a terminator
deviceSelectorString[hal_strlen_s(deviceSelectorString) - 1] = '\0';

// because the caller is expecting a result to be returned
// we need set a return result in the stack argument using the appropriate SetResult according to the variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,26 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial
GetDeviceSelector___STATIC__STRING(CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();
{
// declare the device selector string whose max size is "COM1,COM2,COM3" + terminator
// COM1 is being used for VS debug, so it's not available
char deviceSelectorString[15] = "COM2,COM3";

// because the caller is expecting a result to be returned
// we need set a return result in the stack argument using the appropriate SetResult according to the variable
// type (a string here)
stack.SetResult_String(deviceSelectorString);
}

// declare the device selector string whose max size is "COM1,COM2,COM3" + terminator
// and init with the terminator
char deviceSelectorString[14 + 1] = {0};

// unless the build is configure to use USB CDC, COM1 is being used for VS debug, so it's not available
#if defined(CONFIG_USB_CDC_ENABLED)
strcat(deviceSelectorString, "COM1,");
#endif
#if defined(UART_NUM_1)
strcat(deviceSelectorString, "COM2,");
#endif
#if defined(UART_NUM_2)
strcat(deviceSelectorString, "COM3,");
#endif

// because the caller is expecting a result to be returned
// we need set a return result in the stack argument using the appropriate SetResult according to the variable
// type (a string here)
stack.SetResult_String(deviceSelectorString);

NANOCLR_NOCLEANUP_NOLABEL();
}