More details about COM ports

I have a question concerning com ports. A while ago in this thread

I managed to use arduino-cli.exe in order to get me more details about COM ports. It works really well. I can also find me boards with Ch340 chips. But if I export an application I don’t want to ship a copy of arduino-cli and deal with associated problems.

The output from Serial.list() is not satisfactory. It prints more COM ports than my OS can find and there are no details.

I cannot use this: Serial.list()

[0] "CNCA2"
[1] "CNCB2"
[2] "COM4" 
[3] "COM7" 
[4] "COM8" 
[5] "COM9" 

vs OS:

afbeelding

Are there besides arduino-cli.exe more lightweight tools (which may or may not be natively installed on windows) which I can launch from processing and use to get me a more acurate list of COM ports with some more detailing.

Bas

Have you tried using the cmd-line to list the ports? It’s ls /dev/{tty,cu}.*
on a Mac; have no idea what’s available on Windows.

Hello @bask185,

This will provide more details:

This is the list of COM ports using the jSerialComm library:

Those other COM ports are your virtual COM ports:

image

And your ports:

image

This is the list of COM ports using Processing Serial library:

:)

1 Like

Thank you, that seems really good.

I have one question. Despite being an electronics engineer I cannot find how to bloody install a library. I google searched…
I tried putting the jar file in my sketch folder
I tried putting the jar file in my sketchbook folder under libraries.

I tried like 4 different locations.

Where do libraries go in 2024?

Bas

Did you try creating a folder entitled ‘code’ inside of your sketch folder, then enclosing the .jar file?

1 Like

No, that is the common way nowadays? Is it like the arduino src/ directory? imma gonna try it out!

I’m not familiar with arduino/src, but it is also created with Processing as you probably know. Drag’NDropping .jar file onto editor should also work.

Yeah I know. The content of the src/ directory within an arduino sketch is compiled with your project. Usually you can dump whatever cpp and h files in your main sketch folder and you are good. If you have that much files that you want to use subfolder structure than the subfolder hast to be named “src”. It was not always like this. iirc one could name their subfolders however they liked.

I read on internet that you could drop a .jar file in a sketch folder. I don’t know if that used to be the case in the past??

Anyways. It seems to work now! I can compile and find my arduino. Thanks alot folks! :wink:

Kind regards,

Bas

1 Like

An extra reference for visitors to this topic:

:)

Thnx, I read it. But the ‘code’ subfolder is not mentioned however

On Windows, “mode” lists the com ports. I have in the past used the output of this to detect when a particular port is there for Arduino program load.

2 Likes

You are correct! It is not.

I did find a reference here to code folder:

:)

This need to be entered in the Command Prompt:

Additional reference:
MODE - Com1, Com2, Lpt1, con - Windows CMD - SS64.com

:)

Hello,

I have a follow-up question. I can succesfully identify my Uno board and set up a connection using this code

    SerialPort[] serialPorts = dccNext.getCommPorts() ;   
    for (SerialPort port: serialPorts)
    {           
        if( port.getDescriptivePortName().contains("Uno")
        ||  port.getDescriptivePortName().contains("CH340"))
        {
            println("dccNext found") ;
            try
            {
                dccNext = port ; // copy the for-loop's local object tot he global serial port object.

                dccNext.setBaudRate( 115200 ) ;
                if( dccNext.openPort() ) println("Serial port opened!") ;
                else                     println("Serial port opening !!!FAILED!!!") ;

            }
            catch (NullPointerException e)
            {
                println("NullPointerException") ;
            }
        }
    }

I can also succesfully write data to the Arduino.

However the reading part, does not work.

What I usually do in void draw/loop is to to wait for the serial object to contain atleast 1 byte. Than I add small quick and dirty delay to allow more bytes to fill the buffers before processing the data.
( I am not sure if the delay will work in processing like I think it will)

    if( dccNext.available() > 0 )
    {   delay(100);

        byte len = dccNext.available() ; // should have received entire message by now
        
        string s = "" ;  // make empty string

        for( int i = 0 ; i < len ; i ++ )
        {
            s += (char)dccNext.read() ; // add received bytes to string
        }
        println(s) ;  // go print string to terminal
        receivedText = s ; // copy local string to global string
    }

The problem is in this line:
if( dccNext.available() > 0 )

(dccNext is declared as: SerialPort dccNext ; )

The compiler error:
dccNextGUI.pde:58:0:58:0: The function available() does not exist.

The documentation claims:

Ability to read and write byte streams via Java’s InputStream and OutputStream interfaces

So I thought I could just use the available() method just like I can with the ‘default’ serial library.

How am I failing? :see_no_evil:

Bas

I found it!!

You have to create an inputStream object.
InputStream inputStream ;

And couple it to the serial object in the setup using the method getInputStream()
inputStream = dccNext.getInputStream() ;

Than you can use the inputStream object with all it’s methods like print() print is no input , read(), available() etc.

Kind regards,

Bas

1 Like