Serial port locked after a while

I’m using an Arduino Mega to do certain tasks based on the commands it receives. I send the commands serially through my computers usb port And my own pc application.

Everything works great most of the time, however after a day or so, I suddenly cannot open the port anymore. I receive the error “-5 internal error” from cvi labwindows serial library “rs232.h”.

Resetting the arduino does not help. Opening the serial monitor in the Arduino IDE gives the error message “Error while setting serial port parameters: 9,600 N 8 1”. The only thing that works is to unplug the arduino and then plug it back in.

Does anybody recognize this problem?

The USB hardware or the USB driver is to blame but most likely caused by Windows sending a low-power/sleep message.

You may need to dig deep into power settings.

Write down any setting before changing!

Try using a different usb cable or a different USB port.

Okey I will test this. Thanks

There is a power setting called “USB selective suspend”, disabling this seems to have fixed the issue

Sadly the problem seems to sort of exist again. There is no problem with opening the port, however I get an error when trying to write to the arduino. From the cvi labwindows rs232.h library I get the error “-1”. Just as before this error only occurs after a day or so of running the arduino. The only thing that works is to unplug the arduino, just as before.
The problem with opening the com port has not appeared again.

From the RS-232.h documentation:

The RS-232 Library returns status information through a global variable called rs232err. If this variable is negative after the function returns, an error occurred. Notice that many of the functions return a value in addition to setting the global variable. Usually, this value contains information about the result of the function that also can be used to detect a problem. Each function should be checked individually. The following table lists the error codeserror codes, defined constants, and error messages associated with functions in the the LabWindows/CVI RS-232 Library.

Code	Defined Constant	Error Message
-1	kRS_UnknownSysError	Unknown system error.

I have no personal experience with the NI software, so You may wish to open an inquiry on the CVI forum:
LabWindows/CVI - Page 221 - NI Community

Another option is you can check the Windows Event Viewer to determine is any system message was posted. Note that it is common to see many failure messages in these logs.

Another option, you could install a Microsoft approved traffic logger:
Portmon for Windows - Sysinternals | Microsoft Learn

Portmon has built-in knowledge of all standard serial and parallel port IOCTLs, which are the primary way that applications and drivers configure and read status information from ports.

Please note that serial logs can become somewhat large, so ensure that you delete or off-load them when finished analyzing.

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