user140003
user140003

Reputation: 179

Access to the port 'COM1' is denied

I am trying to open the COM1 port but I am getting this error message "Access to the port 'COM1' is denied". I am writing a program for sending SMS via .NET. I expect there could be an error, but the error "Access denied" should not be arisen. Please give me any solution. If port requires any access privileges then how can I do that?

Upvotes: 15

Views: 109438

Answers (6)

AnonNumber711
AnonNumber711

Reputation: 11

This is what magically worked for me on Windows 10. Could be useful for others. In short, turn off "Serial Enumerator" for that port.

Device Manager -> Ports (COM & LPT) double click the port in question to open Go to "Port Settings" tab Click "Advanced" button Look under "Miscellaneous Options" Uncheck "Serial Enumerator" Click OK to get out

I believe this Enumerator is occupying the port by command of the OS getting in the way of using it for anything else.

Upvotes: 1

Matthew Whited
Matthew Whited

Reputation: 22433

If you are trying to use ASP.Net under IIS there account running the website may not have permissiongs to the device, as well as, there could also be conflicting thread/multi-access issues. Something to consider would me to write a service that manages requests for the COM port and then talk to that service from ASP.Net. This will allow for split permissions and controlled single access to the COM port. Any other hack has the potential of causing lots of problems.

Upvotes: 0

R Ubben
R Ubben

Reputation: 2204

First, make sure the serial port exists. Check the Device Manager; right-click on My Computer, select "Manage" from the context menu, select "Device Manager", expand "Ports Com & LPT". If Com1 is not listed, you will need to enable it in the BIOS.

If COM1 is there, then another program has left it open. Access to COM1 is exclusive; only one program can have it open at a time. Fax software or a modem could have it open, or you could have left it open yourself.

This is easy to do. If you work on a program that opens the port and forget to close it, or if an error occurs and the program terminates without closing the port, this is the message you will get the next time you try to open COM1. Only the program that opened the port can close it. "Catch" or "Finally" blocks are good places to close the port and prevent this.

Upvotes: 15

Chad Ruppert
Chad Ruppert

Reputation: 3680

Since you tagged this asp.net, are you trying to access the port with multiple threads? (as in on a request, accessing the port, creating the connection, sending data, closing connection, closing the port?

If you are, this is also a problem. If I am not mistaken, only one thread can access a com port at a time. You will need to write some code to ensure that only one thread is trying to access the port at a given time. Typically I would suggest a queue and a worker for that queue that does the job.

Upvotes: 2

Vicky
Vicky

Reputation: 13244

There's probably something else using COM1 (auto sync programs tend to be quite bad at grabbing COM ports as soon as they become available).

Try downloading PortMon and it will tell you exactly what's using the port.

Upvotes: 9

Gabe
Gabe

Reputation: 2536

There is probably another program using the serial port. Have you tried firing up hyperterminal?

Upvotes: 0

Related Questions