拒绝访问端口'COM1'。 您所在的位置:网站首页 端口com1访问被拒 拒绝访问端口'COM1'。

拒绝访问端口'COM1'。

#拒绝访问端口'COM1'。| 来源: 网络整理| 查看: 265

百度翻译此文   有道翻译此文 问题描述

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?

推荐答案

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.

其他推荐答案

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.

其他推荐答案

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.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有