如何强制关闭SerialPort连接? [英] How to Forcefully close SerialPort Connection?

查看:479
本文介绍了如何强制关闭SerialPort连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有通过USB串行通信连接到PC的设备.我正在执行以下步骤

1.启动设备(开机)
2.设备将在我的PC中检测为COMx名称
3.启动我的应用程序
4.在COM PID/VID的基础上,我连接到设备
5.进行交流. (到目前为止,我没有遇到任何问题)
6.关闭设备电源时,设备已断开连接,但无法关闭通讯端口

7.当我再次启动(打开)设备时,检测到设备,但是我的应用程序无法连接到COMx(设备).引发IOException"COMx不存在"


所以我认为我有办法强制关闭通讯端口.

任何帮助表示赞赏

谢谢

I have device which is connect to PC via USB Serial communication. I am performing following steps

1. Start Device (Power On)
2. Device will detected in my PC as COMx name
3. Start my application
4. On base of COM PID/VID, I connect to device
5. Perform communication. (Up to this I am not facing any problem)
6. when I switch off device, device is disconnected but I cannot able close communication Port

7. When I again start(Switch on) device, Device is detected but my application cannot able to connect to COMx(device). It throws IOException "COMx does not exist"


So I think I have some way to close communication port forcefully.

Any help is appreciated

Thanks

推荐答案

这是因为当在某个端口中检测到您的设备驱动程序时,它将被保存为已连接的端口名.

(在控制面板->电话和调制解调器选项->调制解调器->您的设备端口中进行检查)

但是在某些情况下(可能与您的情况类似),当重新连接设备时,它将在其他未使用的端口上安装驱动程序(但通常系统会自动将设备连接到已使用的端口)

(在conrtol面板中再次检查您的设备正在使用的任何新端口)

如果设备安装在其他端口,则必须找到某种解决方案,该解决方案可以自动检测设备每次连接到PC时都使用的端口,而不是连接到同一端口. :)
That is because when your device driver is detected in some port, it will get saved under the port name that it was connected.

(Check it in Control Panel -> Phone and modem options -> Modems -> Your Device port)

But there are certain cases (May be like yours) that when the device is reconnected it will get its driver installed in some other port which is not in use (But usually the system will automatically connect the device to its port which it used already)

(Check again in conrtol panel for any new port your device is using)

If the device is installed in different port, then you have to find some solution that automatically detects the port that you device is using everytime to get connected to PC instead of connecting to the same port. :)


如果您将非常仔细地研究有关SerialPort的msdn页面,您会发现一些对您来说非常有趣的东西... ;-)

http://msdn.microsoft.com/en-us/library/system. io.ports.serialport.aspx [ ^ ]

在社区内容下方,给定的链接为:

http://code.mbx.wh01.ipv.no/examples/SerialPortFixer.html [ ^ ]

祝你好运!
If you would have studied the msdn page about the SerialPort very closely you would find something that is very interesting to you... ;-)

http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx[^]

It''s below under community content, the given link is:

http://code.mbx.wh01.ipv.no/examples/SerialPortFixer.html[^]

Good luck!


这篇关于如何强制关闭SerialPort连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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