的SerialPort port.open"端口“COM2”不存在&QUOT。 [英] SerialPort port.open "The port 'COM2' does not exist."

查看:2136
本文介绍了的SerialPort port.open"端口“COM2”不存在&QUOT。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的问题与 SerialPort.Open();

I'm having a big problem with the SerialPort.Open();

我用USB虚拟COM端口(CDC)进行通信,它被列为COM2。

I am communicating with an usb virtual com port (cdc), and it is listed as COM2.

它工作正常,在TeraTerm /超级终端等。但是当我尝试打开端口在C#中,它给我的异常端口COM2不存在

It works fine in TeraTerm/hyperTerminal ect. but when I try to open the port in C#, it gives me the Exception The port 'COM2' does not exist.

我得到使用 SerialPort.GetPortNames()功能的端口名称,它看起来很好,当我调试。

I get the port name using the SerialPort.GetPortNames() function, and it looks fine when I debug.

我试图设置名称硬codeD,但没有运气。

I have tried to set the name hardcoded, but with no luck.

现在真是个奇怪的东西,它工作正常,在某些PC的,并且不能在其他电脑。在某些PC是它失败的时候,和别人失败的10%的时间。

Now the really strange thing, it works fine on some PC's, and fails on other PC's. On some PC's it fail all the time, and on others it fails 10% of the time.

更为奇怪的是取决于所使用的USB端口,某些端口工作正常,别人失败(在同一台PC上!)。

Even more strange it depends on the usb port used, some ports works fine, others fail (on the same PC!).

可能有人帮助我吗?

推荐答案

我已经与虚拟串行端口工作过。通常情况下,他们无法访问为COMX:一些Windows API调用,你必须完全指定。这可能是这里的情况。尝试使用Windows设备的命名空间路径,串行设备。例如:\\。\ COM2

I've worked with virtual serial ports before. Oftentimes they aren't accessible as "COMX:" to some windows API calls, and you have to fully specify them. That might be the case here. Try using the Windows device namespace path for the serial device. For example: "\\.\COM2"

我已经找到了为调试指定的串行端口是开放的超级终端。有用的另一件事

Another thing I've found useful for debugging is opening up a Hyperterm on the given serial port.

最后一件事:对于不具备所有的硬件​​系统调试你的逻辑,我发现这个精彩的节目叫 com0com 。这是一个GPL SourceForge项目,创造拴在系统上对虚拟COM端口。无论是写入一个可以从其他,反之亦然读取。你可以写一个仿真器,并给它一个端口,或只需打开超级终端就可以了。然后给对方你的程序。 ,无需电缆或其他硬件测试。

One final thing: For debugging your logic on systems that don't have all the hardware, I found this wonderful program called com0com. It is a GPL Sourceforge project that creates tied pairs of virtual com ports on your system. Whatever is written to one can be read from the other, and visa versa. You can either write an emulator and give it one of the ports, or just open up Hyperterm on it. Then give the other to your program. Testing with no cables or other hardware required.

这篇关于的SerialPort port.open"端口“COM2”不存在&QUOT。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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