LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

C program to disable COM port

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?

0 Kudos
Message 1 of 4
(1,379 Views)

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,

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 4
(1,307 Views)

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?

0 Kudos
Message 3 of 4
(1,263 Views)

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.

0 Kudos
Message 4 of 4
(1,246 Views)