笔记本电脑上的 C# 应用程序中的通讯端口问题
我正在使用 Visual Studio 2008 并使用 .net 3.5 在 C# 中开发 Windows 窗体应用程序
,我正在进行串行通信,然后单击按钮,应用程序会获取所有可用通信端口的列表。然后,我通过依次打开每个端口、发送自定义握手请求命令并等待回复几秒钟来扫描我正在寻找的设备。
它在我的电脑上(以及我测试过的其他 8 台电脑)上一切正常,但是当我在笔记本电脑上运行该程序时,我的程序似乎看到了所有通信端口并发送了一个请求,但我的设备从未收到它。我尝试过使用硬件通讯端口和 USB 转串口转换器。我还在不同制造商的几台笔记本电脑上对其进行了测试。它们的行为都完全相同。
有人遇到过类似的问题吗?
更新1
笔记本电脑似乎能够从设备接收数据,但仍然无法传输。当然,台式机没有任何问题。
更新2
笔记本电脑可以接收和传输数据。 因此,这将问题缩小到我的 C# 软件,它可以在台式机上进行串行通信,但不能在笔记本电脑上做同样的事情。
更新3
解决了它。该问题是由我的测试笔记本电脑的内置调制解调器引起的。调制解调器保留的com端口(通常是COM3)不会出现在设备管理器中,但可以在Windows注册表中看到。因此,每当我的串行端口对象请求 com 端口列表时,它都会获取调制解调器端口,并且这些调制解调器在端口扫描期间因我的握手请求而阻塞。 像往常一样,一切都是愚蠢而简单的。
I am using visual studio 2008 and developing a windows forms application in C# using .net 3.5
I am doing serial communication and on a button click the application getting a list of all the comm ports available. I then scan for the device i am looking for by opening each port in turn, sending my custom handshake request command and waiting the reply for some number of seconds.
It all works fine on my PC (and on other 8 PCs I've tested it on) but when i run the program on a laptop my program seems to see all the comm ports and sends a requires but my device never receives it. I've tried using the hardware comm port and the usb-to-serial converters. I've also tested it on several laptops form different manufacturers. All of the them behave exactly the same.
Has anyone ran into similar problems?
UPDATE 1
The laptops seem to be able to receive data from the device, but still can not transmit. And of course no problems whatsoever with desktops.
UPDATE 2
A laptop can receive and transmit data.
Therefore that narrows the problem down to my C# software that can do serial communication on a desktop but can not do same thing on a laptop.
UPDATE 3
Solved it. The problem was caused by built in modems of my test laptops. The com port reserved by the modem (typically COM3) does not appear in the device manager, but can be seen in the windows regestry. So whenever my serial port object would ask for a list of com ports, it would get the modem port, and these modems choked on my handshake requests during the port scan.
As usual everything is stupid and simple.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您的设备对电压水平很挑剔。 RS-232 并不能很好地解决这个问题,允许 +/- 5V 到 +/- 28V 之间的任何电压。大多数设备最喜欢使用 +/- 12V,这是台式机中可用的标准电压。然而,笔记本电脑始终处于低端,典型值+/- 5V。你对此无能为力。
要测试这个理论,请消除由您的代码引起的可能性,并确保它适用于空调制解调器。将 TxD 连接到 RxD,以便您接收发送的内容。然后使用超级终端或 Putty。如果后者也无法看到该设备,则可能是硬件问题。
Sounds like your device is picky about the voltage levels. RS-232 doesn't nail that down very well, allowing anywhere between +/- 5V to +/- 28V. Most devices are happiest with +/- 12V, a standard voltage available in desktop machines. Laptops however are always on the low end, +/- 5V typ. Not much you can do about it.
To test this theory, eliminate the possibility that this is induced by your code and make sure it works with a null modem. Connect TxD to RxD so that you receive what you send. Then use Hyperterminal or Putty. If the latter fails to see the device as well then it's a hardware problem.