Skip to content

Error with arduino-cli >= v1.0.0 #11

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

Closed
wagnerc4 opened this issue Sep 23, 2024 · 2 comments · Fixed by #12
Closed

Error with arduino-cli >= v1.0.0 #11

wagnerc4 opened this issue Sep 23, 2024 · 2 comments · Fixed by #12

Comments

@wagnerc4
Copy link

Hello! when I try to compile wtih the newer arduino-cli version >= 1.0.0,
I get this error: Wrong type argument: listp, (detected_ports . [((port (address . "/dev/ttyACM0") (label . "/dev/ttyACM0") (protocol . "serial") (protocol_label . "Serial Port (USB)") (properties (pid . "0x5385") (serialNumber . "HTK32") (vid ."0x27c6")) (hardware_id . "HTK32")))])

@roelhem
Copy link

roelhem commented Dec 20, 2024

I did find the problem, but I do not have a neat solution for you...

The problem is in the arduino-cli--board func. It expects that arduino-cli --json board list the result to be a list of available ports like this:

[
    {
      "matching_boards": [
        {
          "name": "Arduino Uno",
          "fqbn": "arduino:avr:uno"
        }
      ],
      "port": {
        "address": "/dev/cu.usbmodem41214121",
        "label": "/dev/cu.usbmodem41214121",
         ....<truncated>....
      }
    },
    ....<other ports>....
  ]

but the new arduino-cli board list gives this:

{
  "detected_ports": [
    {
      "matching_boards": [
        {
          "name": "Arduino Uno",
          "fqbn": "arduino:avr:uno"
        }
      ],
      "port": {
        "address": "/dev/cu.usbmodem41214121",
        "label": "/dev/cu.usbmodem41214121",
        ....<truncated>....
      }
    },
    ....<other ports>....
  ]
}

It can be solved by re-defining the arduino-cli--board function as:

(defun arduino-cli--board ()
  "Get connected Arduino board."
  (let* ((usb-devices     (alist-get 'detected_ports (arduino-cli--cmd-json "board list")))
         (boards          (seq-filter #'arduino-cli--arduino? usb-devices))
         (boards-info     (seq-map (lambda (m) (thread-first (assoc 'boards m) cdr (seq-elt 0))) boards))
         (informed-boards (cl-mapcar (lambda (m n) (map-merge 'list m n)) boards boards-info))
         (selected-board  (arduino-cli--dispatch-board informed-boards))
         (default-board   (arduino-cli--default-board)))
    (cond (selected-board selected-board)
          (default-board  default-board)
          (t (error "ERROR: No board connected")))))

note the added (alist-get 'detected_ports ....) for the binding of usb-devices.

I personally solved this by copying the whole arduino-cli-mode.el file and made the adjustments that I needed (as there were a few other things I wanted to change.)

That said, I can see why this cannot be changed as easily in this module, as this automatically breaks compatibility with the old behaviour of arduino-cli. This requires some branching based on the version of the arduino-cli, which will probably ruin the simple and easy to read code that @motform wrote.

If @motform is interested, I could write a pull request to solve this (and similar problems) in a more robust way. To do this properly, I do need to know if @motform wants to support all versions of arduino-cli or only the latest version. The last time I did something with the Arduino platform was 10 years ago, so I have no idea how important backwards compatibility is in the Arduino community...

@motform
Copy link
Owner

motform commented Dec 21, 2024

Hi @roelhem and @wagnerc4 ,

Thank you so much for using the library, and thank you @roelhem for offering to help with support for 1.0! I'm usually the one to champion backward compatibility, however, in this case, I think it is fair to drop backward compatibility to a .0 release. ardunio-cli have done the same/broken the interfaces of various APIs a few times now anyway.

I'm also not that up to date with the values of the arduino community, but I reckon a someone how decides to use a terminal based solution is technical enough to be updated/troubleshoot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants