无法获得真实的端口名称

编程入门 行业动态 更新时间:2024-10-28 08:27:47
本文介绍了无法获得真实的端口名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我开发了用于接收串行端口数据的项目. 从我的项目中,我打开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.

更多推荐

无法获得真实的端口名称

本文发布于:2023-11-16 02:14:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   名称   真实

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!