IDE 2.x won't connect to serial port, but IDE 1.x will

I'm using IDE version 2.1.1 on Windows 11 Pro. If I open the serial monitor with the correct port selected, I get " Port monitor error: command 'open' failed: Invalid serial port. Could not connect to COM8 serial port". I'm selecting the correct port and board type in the IDE.

I can connect to COM8 with Teraterm, and it connects fine, and I can see the output from the Arduino. (and yes - I'm disconnecting from the COM port with Teraterm before trying with the IDE)

I can connect to COM8 with IDE version 1.x with no problems as well.

BUT, as I say, I can't connect with IDE version 2.x - I get the error above in the Serial Monitor. I've tried uninstalling and reinstalling the CH340 driver, uninstalling and reinstalling the IDE, and I've even tried the "nightly build" development version of IDE 2.x, but all to no avail.

Does anyone have any other suggestions, please?

So you can upload without problems but serial monitor gives you the error?
What does Windows device manager say at the moment that you get the error message? Does it still recognise the board?

Your topic has been moved to the dedicated IDE2.x section of the forum.

Hi sterretje, thanks for getting back to me.

When I first noticed a problem, it was during uploading. I was getting errors like this:

avrdude: ser_open(): can't set com-state for "\\.\COM6"

...but now I am able to upload with no problems. I don't know for sure what has changed on my system, although my IDE 2.x was previously installed in "for this user only" mode, and when I reinstalled it as part of my troubleshooting so far, I installed it in "for all users" mode since I thought that'd be more likely to work.

So IDE 2.x is able to open the serial port in order to do an upload. But unable to open the port in the serial monitor, it seems.

I tried starting the IDE from PowerShell with

& ".\Arduino IDE"

in the hope of getting some useful debugging info. I'm not sure is terribly helpful though:

2023-07-26T07:38:40.524Z daemon INFO INFO[0007] Required tool                                 tool="arduino:arduinoOTA@1.3.0"
INFO[0007] Required tool                                 tool="arduino:avr-gcc@7.3.0-atmel3.6.1-arduino7"
INFO[0007] Required tool                                 tool="arduino:avrdude@6.3.0-arduino17"

2023-07-26T07:38:40.528Z daemon INFO INFO[0007] Starting monitor process                      monitor=serial-monitor

2023-07-26T07:38:40.532Z daemon INFO INFO[0007] Monitor process started successfully!         monitor=serial-monitor
INFO[0007] sending command                               command="HELLO 1 \"arduino-cli 0.32.3\"" monitor=serial-monitor

2023-07-26T07:38:40.551Z daemon INFO INFO[0007] received message                              error=false event_type=hello message=OK monitor=serial-monitor

2023-07-26T07:38:40.551Z daemon INFO INFO[0007] sending command                               command=DESCRIBE monitor=serial-monitor
INFO[0007] received message                              error=false event_type=describe message=OK monitor=serial-monitor
INFO[0007] sending command                               command="CONFIGURE bits 8" monitor=serial-monitor
INFO[0007] received message                              error=false event_type=configure message=OK monitor=serial-monitor
INFO[0007] sending command                               command="CONFIGURE dtr on" monitor=serial-monitor

2023-07-26T07:38:40.552Z daemon INFO INFO[0007] received message                              error=false event_type=configure message=OK monitor=serial-monitor
INFO[0007] sending command                               command="CONFIGURE parity none" monitor=serial-monitor
INFO[0007] received message                              error=false event_type=configure message=OK monitor=serial-monitor
INFO[0007] sending command                               command="CONFIGURE rts on" monitor=serial-monitor
INFO[0007] received message                              error=false event_type=configure message=OK monitor=serial-monitor

2023-07-26T07:38:40.552Z daemon INFO INFO[0007] sending command                               command="CONFIGURE stop_bits 1" monitor=serial-monitor
INFO[0007] received message                              error=false event_type=configure message=OK monitor=serial-monitor
INFO[0007] sending command                               command="CONFIGURE baudrate 9600" monitor=serial-monitor
INFO[0007] received message                              error=false event_type=configure message=OK monitor=serial-monitor

2023-07-26T07:38:40.552Z daemon INFO INFO[0007] sending command                               command="OPEN 127.0.0.1:61105 COM8" monitor=serial-monitor

2023-07-26T07:38:40.553Z daemon INFO INFO[0007] received message                              error=true event_type=open message="Invalid serial port" monitor=serial-monitor

2023-07-26T07:38:40.553Z daemon INFO INFO[0007] sending command                               command=QUIT monitor=serial-monitor
INFO[0007] received message                              error=false event_type=quit message=OK monitor=serial-monitor
INFO[0007] Killing monitor process                       monitor=serial-monitor

2023-07-26T07:38:40.553Z daemon INFO ERRO[0007] Sent kill signal                              error="TerminateProcess: Access is denied." monitor=serial-monitor

2023-07-26T07:38:40.554Z daemon INFO ERRO[0007] stopped decode loop: EOF                      monitor=serial-monitor

2023-07-26T07:38:40.573Z daemon INFO INFO[0007] Monitor process killed                        monitor=serial-monitor

2023-07-26T07:38:40.574Z monitor-service ERROR Error: 2 UNKNOWN: Port monitor error: command 'open' failed: Invalid serial port
    at Object.callErrorFromStatus (C:\Program Files\Arduino IDE\resources\app\node_modules\@grpc\grpc-js\build\src\call.js:31:19)
    at Object.onReceiveStatus (C:\Program Files\Arduino IDE\resources\app\node_modules\@grpc\grpc-js\build\src\client.js:413:49)
    at Object.onReceiveStatus (C:\Program Files\Arduino IDE\resources\app\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:328:181)
    at C:\Program Files\Arduino IDE\resources\app\node_modules\@grpc\grpc-js\build\src\call-stream.js:187:78
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
for call at
    at ServiceClientImpl.makeBidiStreamRequest (C:\Program Files\Arduino IDE\resources\app\node_modules\@grpc\grpc-js\build\src\client.js:398:30)
    at ServiceClientImpl.monitor (C:\Program Files\Arduino IDE\resources\app\node_modules\@grpc\grpc-js\build\src\make-client.js:105:19)
    at MonitorService.createDuplex (C:\Program Files\Arduino IDE\resources\app\node_modules\arduino-ide-extension\lib\node\monitor-service.js:184:34)
    at async C:\Program Files\Arduino IDE\resources\app\node_modules\arduino-ide-extension\lib\node\monitor-service.js:257:37
    at async retry (C:\Program Files\Arduino IDE\resources\app\node_modules\@theia\core\lib\common\promise-util.js:73:20)
    at async MonitorService.start (C:\Program Files\Arduino IDE\resources\app\node_modules\arduino-ide-extension\lib\node\monitor-service.js:148:13)
    at async MonitorManager.startMonitor (C:\Program Files\Arduino IDE\resources\app\node_modules\arduino-ide-extension\lib\node\monitor-manager.js:90:13)
    at async JsonRpcProxyFactory.onRequest (C:\Program Files\Arduino IDE\resources\app\node_modules\@theia\core\lib\common\messaging\proxy-factory.js:132:24)
    at async RpcProtocol.handleRequest (C:\Program Files\Arduino IDE\resources\app\node_modules\@theia\core\lib\common\message-rpc\rpc-protocol.js:150:28)
2023-07-26T07:38:40.574Z monitor-service INFO monitor to COM8 using serial closed by server
2023-07-26T07:38:40.574Z monitor-service INFO monitor to COM8 using serial closed by client

Does any of the above shed any light on the problem?

And yes - to answer your question! - Device Manager has an entry "USB-SERIAL CH340 (COM8)" under the "Ports (COM & LPT)" category, and there's no change at all when I launch the IDE, go to Serial Monitor, and wait for the error to appear.

Hi @wakatashi

There were some previous reports of this "can't set com-state for ..." error occurring specifically associated with the presence of the CH340 USB chip that is commonly used on the cheap derivative boards. It seems that a driver upgrade included in a recent Windows update is the cause of this problem.

The affected users have reported that doing a "roll back" to an older version of the driver was an effective workaround. You can give that a try.

I'll provide instructions:

  1. Open this tutorial from SparkFun in your browser:
    https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/all#drivers-if-you-need-them
    We are using this tutorial as a source for an older version of the CH340 drivers. Generally I recommend only obtaining drivers from the manufacturer of the device, but WCH does not provide older versions of their drivers and SparkFun is trustworthy.
  2. Click the "Windows (EXE)" link you see in red under the "Drivers (If You Need Them)" section of the tutorial.
  3. Wait for the download to finish.
  4. Run the downloaded CH341SER.EXE file.
  5. A "User Account Control" dialog may now appear asking "Do you want to allow this app to make changes to your device?". Click the "Yes" button.
  6. A "DriverSetup(X64)" dialog will appear. Click the "INSTALL" button in the dialog.
  7. Wait for the driver installation to finish, as indicated by the appearance of a "Driver install success!" dialog.
  8. Click the "OK" button in the "Driver install success!" dialog.
  9. Click the X icon at the top right of the "DriverSetup(X64)" dialog to close it.
  10. Close Arduino IDE if it is running.
  11. Connect the Arduino board to your computer with a USB cable.
  12. Open the Windows Device Manager.
  13. Select View > Devices by type from the Device Manager menus.
  14. Open the "View" menu.
  15. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  16. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  17. You should see a port identified as "USB-SERIAL CH340 (COM_n_)" under the "Ports (COM & LPT)" section (where "COM_n_" is some serial port e.g., COM4). Right click on that item.
    A context menu will open.
  18. Select the "Drivers" tab of the "USB-SERIAL CH340 (COM_n_) Properties" dialog.
  19. You will see a "Roll Back Driver" button in the dialog. If it is not clickable, perform the following instructions:
    1. Select "Update driver" from the context menu.
      An "Update Drivers Device - USB-SERIAL CH340 (COM_n_)" dialog will open.
    2. Click on "Search automatically for drivers" in the "Update Drivers Device - USB-SERIAL CH340 (COM_n_)" dialog.
    3. You should now see the driver installation wizard update the driver. Wait for the update to finish, as indicated by the message "Windows has successfully updated your drivers" in the dialog.
      :exclamation: It is possible you will instead see the message "The best drivers are already installed". If so, please stop following the instructions here and reply on the forum thread to let me know. I'll provide alternative instructions you can follow.
    4. Click the "Close" button in the "Update Drivers Device - USB-SERIAL CH340 (COM_n_)" dialog.
  20. Click the "Roll Back Driver" button in the "USB-SERIAL CH340 (COM_n_) Properties" dialog.
    The "Driver Package rollback" dialog will open.
  21. Click the radio button next to "My apps don't work with this driver" in the "Driver Package rollback" dialog .
  22. Click the "Yes" button.
  23. Click the "Close" button in the "USB-SERIAL CH340 (COM_n_) Properties" dialog.

Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error. Please reply here to let us know whether the error still occurs.

Thanks ptillisch, that has solved the problem.

I had seen links to that article from SparkFun, but hadn't read it properly and had ended up installing the latest CH340 driver from the manufacturer (which didn't work), rather than reverting to the old driver from 2014 provided by SparkFun (which does work).

Thanks so much - I now have a fully-functional IDE once more. Yay!

You are welcome. I'm glad it is working now.

Regards,
Per

Any idea why this is (or seems to be) IDE 2.x specific?

I did a comprehensive survey of all reports and, though it is true that IDE 2.x was used in the great majority of the reports where an IDE version could be determined from the contents of the thread (very often it could not be), there are some counterexamples:

One thing to consider is that it is likely the great majority of people using these boards with AVRDUDE are using Arduino IDE and the great majority of Arduino IDE users are using 2.x at this point. So we would expect that a majority of reports of a problem unrelated to the use of Arduino IDE or the IDE version will be IDE 2.x users, purely coincidentally.

I also notice that the great majority of the reports are from new forum users. A new forum user is likely to also be relatively new to using Arduino and that user segment is even more likely to use Arduino IDE 2.x because they will have started with 2.x and thus not have the bias against update that the ossified long time Arduino users do.

These new users who are more likely to use IDE 2.x might also have a higher likelihood of owning the affected hardware if the problematic chips only hit the market recently. I have quite a few CH340-based boards, mostly purchased from the sketchiest sellers on eBay and AliExpress, but they were all purchased years ago because I have a large enough stockpile of the type of board that tends to use the CH340 that I have no need to buy more. I would guess that is a common state among the long time Arduino users, but not for new users who need to purchase a new board to get started with Arduino. The fact that I have not been able to reproduce the fault with the boards I have makes me think the problematic chips were not on the market years ago when I was buying them.

I have indeed seen the report mostly for IDE 2.x. In this topic however, both Teraterm and IDE 1.x do not show the problem while IDE 2.x does. So this would basically exclude the driver / fake CH340 from the equation and hence the question why IDE 2.x in this shows the problem (maybe it was not that clear in my previous post).

I mostly use IDE 2.x; exception is various portable installs for IDE 1.8.x when needed. And my Nano clones are indeed older ones.

I see now this was about the "Port monitor error: command 'open' failed: Invalid serial port." error from Serial Monitor rather than the "can't set com-state" error while uploading.

My previous reply was about the uploading error. I don't have an explanation for why the Arduino IDE 2.x Serial Monitor fails to open the port while the other monitors do not.

There wouldn't be much benefit to making Serial Monitor resilient to this problem while the upload tools are still non-functional. However, this might indicate that it is possible to somehow mitigate the issue in the codebase of the upload tools (at which time it would make sense to do the same in Serial Monitor).

A post was split to a new topic: Uploading to Arduino Nano ESP32 blocked

I thought the finding reported here was quite interesting in the context of our discussion here re: how it seems it is possible for the problem to be managed at the tooling layer:

1 Like

I could add that I have 2 identical NANOs, one has "Pulsivo" written on it and has the CH340 driver with WCH inscription on it and works in both Arduino IDE 2.x and Arduino 1.x, while the other one with CH340 driver WITHOUT any inscription on it only works in Arduino 1.x by opening the serial monitor and setting it to 9600 or less.

I am having this same problem, but my system says "the best drivers are already installed" and won't let me roll back. Could you please include those alternate instructions for rolling back, since I can't seem to see any other way? Thanks!

Also, a bit more color on my issue: I can always upload to a Nano using an Atmega 168, (and a CH340) under all/normal conditions. I can only upload to Nano using Atmega 328 old bootloader (and CH340) if I open the serial monitor first, then upload while the monitor is open. Something about opening the serial monitor first forces it to connect, or something. However, I cannot use this trick to upload to an ESP32-CAM (and CH340 sub board), In that case, it still says "A fatal error occurred: could not open COM7, the port doesn't exist."

Any additional help rolling the driver back would be greatly appreciated. Thanks!

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