c# - 串口未授权访问异常

标签 c# io

我试图从串行端口读取一些信息,但是当我实际打开一个连接时它抛出一个未经授权的访问异常

此代码读取端口名称

        SerialPort port = new SerialPort();
        string[] serialPorts = System.IO.Ports.SerialPort.GetPortNames();


        public Page_Main()
        {
            InitializeComponent();

            for (int i = 0; i < serialPorts.Count(); i++)
                portBox.Items.Add(serialPorts[i]);
        }

这是尝试获取来自串口的信息的代码

            port.PortName = portBox.SelectedItem.ToString();
            port.BaudRate = 9600;
            port.DataBits = 8;
            port.Parity = Parity.None;
            port.StopBits = StopBits.One;

            port.Open();// This is where the exception is thrown

            serialOutput.Text = port.ReadLine();

最佳答案

拒绝访问该端口。

  • 或-

当前进程或系统上的另一个进程已经通过 SerialPort 实例或非托管代码打开了指定的 COM 端口。

关于c# - 串口未授权访问异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10341744/

相关文章:

c# - 为什么 C# switch 语句不能接受 'dynamic' 类型?

c# - 是创建自定义异常还是等待下线发生 NullReferenceException?

java - 在java中使用UTF-8编码读取文件时出现问题

linux - 使用 getchar() 在原始模式下捕获 Ctrl-Enter?

perl - 如何在Perl中为简单的I/O子例程创建单元测试

C# 子类返回类型的协方差

c# - 用于查找和删除重复单词的正则表达式

C#改进算法

java - 扫描仪在使用 next() 或 nextFoo() 后跳过 nextLine()?

performance - 读取未格式化文件的最有效方法