无法打开在.NET串口 [英] Unable to open serial port in .NET

查看:305
本文介绍了无法打开在.NET串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开COM1,但每次我打电话得到一个奇怪的错误 SerialPort.Open()

I am trying to open COM1, but get a strange error every time I call SerialPort.Open().

该错误是:

给定的端口名称没有以COM / COM或不能解决一个有效的串行端口。   参数名:PORTNAME

The given port name does not start with COM/com or does not resolve to a valid serial port. Parameter name: portName

在code是很简单的:

The code is very simple:

SerialPort port = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);
port.Handshake = Handshake.RequestToSend;
port.Open();

如果我称之为 SerialPort.GetPortNames(),它返回称为COM1一个端口。

If I call SerialPort.GetPortNames(), it returns one port called "COM1".

我已经验证了我在我的电脑上的COM1,而我没有使用它的任何其他应用程序。当我在另一台计算机上运行的code,它的工作原理。我的系统正在运行Windows Vista。 .NET的版本是2.0。

I've verified that I have a "COM1" on my computer, and I'm not using it in any other applications. When I run the code on another computer, it works. My system is running Windows Vista. The version of .NET is 2.0.

有没有安全设置我有什么地方改变?我登录的管理员,并UAC关闭。

Is there a security setting I have to change somewhere? I'm logged in as an admin, and have UAC turned off.


更多信息

我使用的Process Explorer,并确认没有使用\设备\ Serial0上。

I used Process Explorer and confirmed that nothing is using \Device\Serial0.


解决方法

我安装了一个USB串行接口(COM3),并能正常工作。去搞清楚。必须与COM1存在的问题。

I installed a USB-Serial adaptor (COM3), and it works fine. Go figure. There must be a problem with COM1.

推荐答案

我有这个问题了。原来,我有一台打印机设置为使用COM端口,我试图打开。有一次,我改变了打印机使用其他端口的端口打开就好了。

I had this problem too. It turned out that I had a printer set to use the COM port I was trying to open. Once I changed the printer to use another port the port opened just fine.

这篇关于无法打开在.NET串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆