且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取正在使用的RS232端口?

更新时间:2022-06-10 02:26:13

SerialPort.GetPortNames(v=vs.110).aspx [ ^ ]要找到系统的所有可用端口,那么你几乎必须尝试在try ... catch块中打开每个端口并仅使用那些没有失败的端口。对于comport没有IsFree属性,IsOpen只跟踪当前应用程序中的端口 - 如果它在不同的应用程序中打开(因此不是免费的),IsOpen仍将返回false。
Start with SerialPort.GetPortNames(v=vs.110).aspx[^] to find all available ports to the system, then you pretty much have to try to Open each one in a try...catch block and use only those that don't fail. There is no "IsFree" property for a comport and "IsOpen" only tracks ports within the current app - if it's open in a different application (and thus not free) IsOpen will still return false.