avrdude can't find com

Im follow this topic:
https://forum.arduino.cc/index.php?topic=417659.0

To install hex directly on arduino leonardo on lattepanda with win10.
But there is an error and avrdude can not upload.

"avrdude: ser_open(): can't open device "\.\Com4": The system cannot find the file specified."

Window show 2 com port: 1 and 5, com5 is arduino port. There is no port 4.
Using Ide there is no problem, and if upload my sketch all it's ok. And with verbose output show that the programmer is on port 4.

So, someone could help me? Any idea? Where I wrong? :confused:

Thansk.

if I select com5 avrduce give this: butterfly_recv(): programmer is not responding
It's try a lot but can't connect to programmer.
(IDE is closed)

The Arduino IDE does a special process when uploading to the Leonardo that doesn't happen when you are uploading using avrdude directly.

The bootloader on the ATmega32U4 runs for several seconds after the microcontroller is reset. The bootloader must be running for avrdude to to the upload. In order to make uploading easy, the Arduino IDE automates this reset process. That is done by opening a serial connection to the COM port of the board at 1200 baud. The Leonardo has code that runs in the background of your sketch and sees that 1200 baud connection as a signal to reset the microcontroller. The Arduino IDE then watches for the first COM port to be enumerated on the system, then runs the avrdude command to upload to that port.

So in order to upload using avrdude directly, you need to manually reset the Leonardo by pressing the reset button before running the avrdude command. But you also need to figure out what the correct COM port is to use in your avrdude command. The Leonardo will likely have a different COM port number when the bootloader is running than when the bootloader is running. So do a reset and then quickly check the com port before the bootloader times out and exits to the sketch.

pert:
So in order to upload using avrdude directly, you need to manually reset the Leonardo by pressing the reset button before running the avrdude command. But you also need to figure out what the correct COM port is to use in your avrdude command. The Leonardo will likely have a different COM port number when the bootloader is running than when the bootloader is running. So do a reset and then quickly check the com port before the bootloader times out and exits to the sketch.

Yes, great! Pressing reset of arduino avrdude works on com4 like the IDE!!
Perfet! Thanks so much!

You're welcome. I'm glad to hear it's working now. Enjoy!
Per