COM Ports with high numbers and C#

having a curious issue, more wondering if this is just me than aiming for a solution just yet.

I have two MCU, an Arduino Nano and a Raspberry Pi Pico, both programmed with the Arduino IDE with the same code except for one line to define where the on board LED lives.

very simple code, open the serial port, sit want wait - if a character comes through flash the light (using non-blocking code) and if the character is 0x01, respond with 0x02 and go back to sleep.

compiles, installs and runs perfectly on both - the Nano is COM5 and the Pico is COM24.

the Serial Monitor can talk to both - obviously it cannot send binary but the light flashes, a terminal programme that can send Binary shows this works exactly as expected.

so far so good.

I then have a C# console application.. this will talk to the Nano on COM5 but will hang trying to talk to the Pico on COM24...

has anyone else had entertainment trying to get C# to talk to COM ports with numbers above 9?

Maybe the format \\.\COMxx does the trick; standard COM ports go from 1 to 9. Source: HOWTO: Specify Serial Ports Larger than COM9 - Microsoft Support (yes I know, it's not C# but the principle should apply).

It might be a bug in your C# code that we can't see :wink:

Hi, I did try "\.\COM...." generates an error message that the name cannot start with ""

C# sharp code could be bugged, its quite basic with minimal error checking, however it talks to other MCU quite nicely. and when liberally sprinkled with exceptions handlers etc none of them trigger

it just locks up.

I suspect the issue is something about the nature of the virtual port driver for the chip on the Pi Pico as a bit more testing and it does work with an Arduino Mega on COM23

have filed it under "one of them things", largely because I was only fiddling trying to see why code written by someone else in C# will talk to an Arduino, and stuff like an ESP32 etc, but not the Pi Pico

when the code on the Pi Pico will work just fine when a terminal programme is talking to it - issue seems to be in the guts of C# - next step is to try talking using the Win32 API and if that works maybe generate my own little library that can be called from C# to manage it

these things are sent to try us, cheers for the reply though :slight_smile:

Do a forum search for "creeping com port" It may have some additional help for you.

It's double backslashes; and to use them in code, it's even more. E.g.

String port = "\\\\.\\COM10";

First backslash escapes the second one, third backslash escapes the fourth one and so on.

Sorry, ignore. It looks like the forum software eats backslashes for supper :unamused:

not come across this problem with C#
I have had similar problems with other software when attempting to use COM ports with high number
I fixed the problem by removing unused COM ports so low numbered COM ports can be reused

Removing unused COM ports is also documented in the

creeping com port

posts with additional information.
But yours is also totally correct too just to remove them.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.