Serial Port Error: "Unable to initialize Com: Can't access port. probably in use by another app"


Recommended Posts

If I go into the quick device configuration, Select the device name, and go to the configure screen and select save, I get the error:

 "Unable to initialize Com3: Can't access port. probably in use by another app"  

The error is correct. I am already using the port. I am just tweaking the timeout setting. 

How do you "close" a com port before using the Serial Port Configuration so it is no longer "in use"  and thus not get the error message ?



Link to comment
Share on other sites

You won't get an "unable to initialize" error on a port if it is the only port and you reconfigure it.  Either you have another port you don't know about (CLV?) or Windows is having troubles closing the port before reopening, something you sometimes see in virtual comm port drivers (which includes USB to serial converters), and is thus one of the many reasons I recommend against using these.  These drivers are not created by Microsoft, but instead by the vendor, and in the case of cheaper USB to serial converters, the software is equally cheap.  I recommend using a quality converter from a reputable company, say, SeaLevel or just using an ethernet to serial converter (also available from SeaLevel) where they offer a Raw port allowing use without a driver.  Otherwise you will largely have to deal with it since it is a Windows level issue.

But to answer your question, you can, of course, juse open the configure page again and hit save and it will reinit the port.  The only way to close a port is to give it a different port number (if available) or set it to 0, which closes it without opening a new one.  This applies to TCP too: set the Port of a TCP connection to 0 and it will close the existing socket without opening a new one.  This is a great way to create ports that may or may not be used by a particular instance of your application.

Link to comment
Share on other sites

Thanks for the reply.

Using your port 0 advice, I have been able to get rid of the error. It works from script or configurecomm() 

1. change the port to 0.

2. initcomm()  or save in configurecomm(.)

3. change the port back to 3.

4. initcomm() or save in configurecomm().

No error.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.