本文介绍了无法获得真实的端口名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了用于接收串行端口数据的项目. 从我的项目中,我打开comport 2,当我想获取端口名时,我正在获取comport1,我不知道是什么问题. 我在想这段代码: var poname = comPort.PortName; 打开comport2时,我以另一种形式使用此代码并创建了表单的创建对象. comPort是我的串行端口. 而且我想要在我的项目中打开的端口名不在我的计算机中.
I develop my project for receive serial port data. From my project i open comport 2 and when i want to get port name i am getting comport1 what is problem i don''t know. I muse this code: var poname = comPort.PortName; i use this code in another form with create object of form at when i open comport2. comPort is my serial port. And i want the port name of which is open in my project not in my computer.
推荐答案问题一定在您使用的包装类中,C#仅具有System.IO.Ports.SerialPort的概念.在这里,您可以使用GetPortNames(静态方法)来获取系统上当前可用的端口. 有关更多信息,请参见: SerialPort类 [ ^ ] 干杯,AT The problem must be in the wrapper class you are using, C# only has a notion of System.IO.Ports.SerialPort. Here you can use GetPortNames (static method) to get the ports currently available on your system. See for more info: SerialPort Class[^] Cheers, AT
我在我的项目中解决了该问题,在该表单中,我设置了端口详细信息,然后关闭了该页面,所以我没有真正的端口名,所以现在的解决方案是只隐藏该页面并定义公共静态串行端口,因此我在所有形式下均获得相同的值. I solve it in my project at which form i set port detail i closed that page so i am not get real port name so now solution is to only hide that page and define public static serial port so i get same value at all form.
更多推荐
无法获得真实的端口名称
发布评论