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: show board info based on the selected port #1803

Merged
merged 1 commit into from
Feb 6, 2023
Merged

fix: show board info based on the selected port #1803

merged 1 commit into from
Feb 6, 2023

Conversation

kittaakos
Copy link
Contributor

Motivation

As requested in #1435, IDE2 shows the board info based on the Tools > Port and not Tools > Board.
This PR makes the board's serial number (SN) available via the board details.

Change description

Expected behavioral change:

  • IDE shows the SN if available.
  • IDE shows the Network port, can't obtain info. message when a network port is selected.
  • IDE shows the Native serial port, can't obtain info. message when no matching_boards can be found for the currently selected port. For example, I installed the core for ESP8266MOD, compiled against the NodeMCU 0.9 (ESP-12 Module) board on the /dev/cu.usbserial-0001 serial port, compile upload works, but as this board is not recognized as the matching_boards of a port (board list --format json), it cannot show the details.

Examples:

1435_01.mp4
1435_02.mp4

Locally discovered boards for the examples:

[
  {
    "matching_boards": [
      {
        "name": "Arduino MKR1000",
        "fqbn": "arduino:samd:mkr1000"
      }
    ],
    "port": {
      "address": "192.168.0.104",
      "label": "Arduino at 192.168.0.104",
      "protocol": "network",
      "protocol_label": "Network Port",
      "properties": {
        ".": "mkr1000",
        "auth_upload": "yes",
        "board": "mkr1000",
        "hostname": "Arduino.local.",
        "port": "65280",
        "ssh_upload": "no",
        "tcp_check": "no"
      }
    }
  },
  {
    "matching_boards": [
      {
        "name": "Arduino Uno",
        "fqbn": "arduino:avr:uno"
      }
    ],
    "port": {
      "address": "/dev/cu.usbmodem14401",
      "label": "/dev/cu.usbmodem14401",
      "protocol": "serial",
      "protocol_label": "Serial Port (USB)",
      "properties": {
        "pid": "0x0043",
        "serialNumber": "551313237373514130C1",
        "vid": "0x2341"
      }
    }
  },
  {
    "port": {
      "address": "/dev/cu.BLTH",
      "label": "/dev/cu.BLTH",
      "protocol": "serial",
      "protocol_label": "Serial Port"
    }
  },
  {
    "port": {
      "address": "/dev/cu.Bluetooth-Incoming-Port",
      "label": "/dev/cu.Bluetooth-Incoming-Port",
      "protocol": "serial",
      "protocol_label": "Serial Port"
    }
  },
  {
    "port": {
      "address": "/dev/cu.usbserial-0001",
      "label": "/dev/cu.usbserial-0001",
      "protocol": "serial",
      "protocol_label": "Serial Port (USB)",
      "properties": {
        "pid": "0xEA60",
        "serialNumber": "0001",
        "vid": "0x10C4"
      }
    }
  },
  {
    "port": {
      "address": "/dev/cu.SLAB_USBtoUART",
      "label": "/dev/cu.SLAB_USBtoUART",
      "protocol": "serial",
      "protocol_label": "Serial Port (USB)",
      "properties": {
        "pid": "0xEA60",
        "serialNumber": "0001",
        "vid": "0x10C4"
      }
    }
  },
  {
    "matching_boards": [
      {
        "name": "Arduino MKR1000",
        "fqbn": "arduino:samd:mkr1000"
      }
    ],
    "port": {
      "address": "/dev/cu.usbmodem14301",
      "label": "/dev/cu.usbmodem14301",
      "protocol": "serial",
      "protocol_label": "Serial Port (USB)",
      "properties": {
        "pid": "0x804E",
        "serialNumber": "94A3397C5150435437202020FF150838",
        "vid": "0x2341"
      }
    }
  }
]
  • MKR1000 on serial,
  • MKR1000 on network,
  • UNO on serial,
  • ESP8266MOD on serial

Other information

Closes #1489
Closes #1435

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

@kittaakos kittaakos requested review from AlbyIanna and per1234 January 6, 2023 12:32
@kittaakos kittaakos added type: enhancement Proposed improvement topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Jan 6, 2023
Comment on lines 114 to 59
// IDE 1.x show this when cannot identify for example a ESP8266MOD although compile and upload works
if (!boardListOnSelectedPort.length) {
this.messageService.info(
nls.localize(
'arduino/board/noNativeSerialPort',
"Native serial port, can't obtain info."
)
);
return;
Copy link
Contributor

@per1234 per1234 Jan 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE: Fixed by 43283ba

There are three possible cases:
  • identified port
  • unidentified port
  • native port

An example of all three is shown here:

$ arduino-cli board list --format json
[
  {
    "port": {
      "address": "/dev/ttyUSB0",
      "label": "/dev/ttyUSB0",
      "protocol": "serial",
      "protocol_label": "Serial Port (USB)",
      "properties": {
        "pid": "0x6001",
        "serialNumber": "AB0P8H9K",
        "vid": "0x0403"
      }
    }
  },
  {
    "matching_boards": [
      {
        "name": "Arduino Uno",
        "fqbn": "arduino:avr:uno"
      }
    ],
    "port": {
      "address": "/dev/ttyACM0",
      "label": "/dev/ttyACM0",
      "protocol": "serial",
      "protocol_label": "Serial Port (USB)",
      "properties": {
        "pid": "0x0043",
        "serialNumber": "95032303537351D0F001",
        "vid": "0x2341"
      }
    }
  },
  {
    "port": {
      "address": "/dev/ttyS4",
      "label": "/dev/ttyS4",
      "protocol": "serial",
      "protocol_label": "Serial Port"
    }
  }
]

Identified

/dev/ttyACM0 is an identified port:

Arduino IDE 1.x

image

Arduino IDE 2.x

image

🙂 Arduino IDE 2.x behavior matches 1.x

Unidentified

/dev/ttyUSB0 is an unidentified port (it is a classic Nano, which uses the manufacturer provided VID/PID pair of its general purpose FTDI FT232RL USB chip, and thus can't be identified as a specific board):

Arduino IDE 1.x

image

Arduino IDE 2.x

image

🐛 Arduino IDE 2.x behavior does not match 1.x

The behavior of the current PR code is problematic for two reasons:

  • It is incorrect to call /dev/ttyUSB0 a "native port".
  • It makes it so the VID and PID (which is valuable information for support/troubleshooting) can not be determined.

Native

/dev/ttyS4 is a native port:

Arduino IDE 1.x

image

Arduino IDE 2.x

image

🙂 Arduino IDE 2.x behavior matches 1.x

@kittaakos
Copy link
Contributor Author

Thank you for the review, Per.

I pushed the requested changes. Please review.

I have a few questions and remarks:

  • I do not have a classic Nano board; hence I could not reproduce the behavior with an attached board.
  • I mocked the board list --watch format json response of the CLI based on your board list output, and it works like this in IDE2 from the PR:
    Screen Shot 2023-01-09 at 08 58 05
  • How can any client of the CLI distinguish between serial and native serial ports:
{
    "port": {
      "address": "/dev/ttyUSB0",
      "label": "/dev/ttyUSB0",
      "protocol": "serial",
      "protocol_label": "Serial Port (USB)",
      "properties": {
        "pid": "0x6001",
        "serialNumber": "AB0P8H9K",
        "vid": "0x0403"
      }
    }
  }
  {
    "port": {
      "address": "/dev/ttyS4",
      "label": "/dev/ttyS4",
      "protocol": "serial",
      "protocol_label": "Serial Port"
    }
  }
  • Currently, IDE2 shows an unknown board for a port if the protocol is 'serial' and the matching_boards is not empty or 'vid' and 'pid' is available from the port#properties. Is this the correct approach?
  • For the unidentified board, the SN is available: AB0P8H9K. Is this correct to show: "Upload any sketch to obtain it."? Thanks

@kittaakos
Copy link
Contributor Author

I have a few questions

  • How can any client of the CLI distinguish between serial and native serial ports:
  • Is this correct to show: "Upload any sketch to obtain it."?

IDE2 will consider a port a non-serial if:

  • The port protocol is 'serial', AND
  • The VID+PID is available from port#properties

From @cmaglie:

  • before USB, the Serial ports were embedded in the PC. You'll get COM1 and COM2 usually, and you connected them using a 9 pin D-SUB connector this is what the IDE Java calls "native" port, because it's something that is embedded in the PC. It doesn't have any USB VID/PID, so nothing can be told about what you connect to that port
    image (3)
  • so fact 1. if you don't have VID/PID than it's a "native" port
  • after some times the USB standard got traction and the old serial ports have been replaced by USB-2-serial converters: you had these cables where one side was USB and the other was 9-pin D-SUB. Actually the USB connection was converted to Serial, but in this case the USB VID/PID are fixed, and are those of the chip mounted on the cable. This is the case where that Per calls "unidentified". you have VID/PID but it's the VID/PID of the "converter"
  • finally, we got the modern microcontrollers that have direct USB connection, so they can "emulate" an USB-2-serial cable... in this case each microcontoller can send arbitrary VID/PID, because there is no more the real convert cable, it's emulated, so each board can have his unique VID/PID. This is what Per calls "identified" port.

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE: resolved

I believe the notification shown when no board is selected is an artifact from the old system where the information was sourced from the board definition.

It seems to me that the only requirement now is for a port to be selected, since the information is gathered from the port and the board definition is not used at all.

To reproduce

  1. Select File > Quit from the Arduino IDE menus if it is running
  2. Rename or delete (:warning: cautiously) the following folder to produce the condition of not having a board selected:
    • Windows:
      C:\Users\<user name>\AppData\Roaming\arduino-ide
      
    • Linux:
      ~/.config/arduino-ide
      
    • macOS:
      ~/Library/Application Support/arduino-ide
      
  3. Start Arduino IDE.
  4. Select a port from the Tools > Port menu in Arduino IDE.
  5. Select Tools > Get Board Info from the Arduino IDE menus.

🐛 An inappropriate notification is shown:

Please select a board to obtain board info.

🐛 The "Board Info" dialog does not open.

@kittaakos
Copy link
Contributor Author

Could you please take another look, Per?

include serial number of board if available

Closes #1489
Closes #1435

Signed-off-by: Akos Kitta <[email protected]>
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Akos!

@kittaakos kittaakos merged commit 5d264ef into main Feb 6, 2023
@kittaakos kittaakos deleted the #1435 branch February 6, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect output from Tools > Get Board Info Show board serial number from Tools > Get Board Info
2 participants