03-04-2023 07:22 AM - edited 03-04-2023 07:23 AM
I’m using an Arduino to do certain tasks based on the commands it receives. I send the commands serially through my computers usb port.
Everything works great most of the time, however after I’ve been opening and closing my pc application over the duration of a couple of days, I suddenly cannot open the COM port to communicate with the Arduino anymore.
I suspect that for some reason, the COM port does not close properly and is left opened. I receive the error code “-5 internal error” from the rs232 library.
I’ve tried resetting the arduino by pressing the reset button, but this does not help. The only thing that helps is to pull out the usb cable and plug it back in.
Is there any way to force close the port? Alternatively, is there any way to disable the Arduino and then re-enable it again, so that I’m able to open the COM port again?
03-05-2023 04:57 AM
Hi,
Without trying to comment on the error issue, I can suggest a workaround.
If disconnecting-reconnecting helps to solve the issue, maybe you can try disabling and re-enabling the USB device from the device manager.
You can see pnputil command on the command-line.
I have no experience about this approach solving this issue. Just a hunch.
Hope this helps,
03-07-2023 01:10 PM
Hi
After disabling the arduino the driver fails to load properly when I try to re-enable it again. So I end up having to unplug the arduino once again. Does anybody know what the cause could be that the driver fails to load after re-enabling the device?
03-08-2023 02:33 AM
Hello,
did you write the Arduino driver ? In that case verify that things are closed properly and that there aren't memory leaks. Arduino does not have an OS that can clean things up after a process finishes badly.
If you didn't write the driver and don't have the code for it (isn't everything open-source anyway?) you may have the choice of other drivers.