我正在构建一个Windows应用程序,需要通过串行端口传输数据,但我无法弄清楚如何让它工作。我尝试了不同的声明和
我拥有最新版本的.NET框架:5.0.100
感谢任何能提供帮助的人!
所使用的导入:
imports
,但都没有成功。以下是我从3个方法中看到的3个错误:
此外,它也没有将其标记为错误,但我找不到'nuGet包'文件夹中的'SerialPort1'未声明。由于保护级别,可能无法访问。
'SerialPorts'未声明。由于保护级别,可能无法访问。
'Ports'不是'MyComputer'的成员。
System.IO.Ports
,因此无法安装它(也无法安装其先决条件)。我拥有最新版本的.NET框架:5.0.100
感谢任何能提供帮助的人!
所使用的导入:
Imports System.Windows.Forms
Imports System
Imports System.IO.Ports
这个子程序在实际程序中属于公共类。
子程序GetSerialPortNames()
显示所有可用的COM端口。获取串口名称列表。
SerialPort1.Open() 'first way i tried
Dim ports As String() = SerialPorts.GetPortNames() 'second way i tried
' Show all available COM ports. third way i tried
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox_Serial_Ports.Items.Add(sp)
Next
End Sub