vb.net 查看本地计算机串口
在VB.NET中,您可以使用System.IO.Ports.SerialPort
类来查看本地计算机的串口。以下是一个简单的示例代码,用于列出所有可用的串口名称:
代码1
Imports System.IO.Ports Module ListSerialPortsModule Sub Main() Dim portNames As String() Try portNames = SerialPort.GetPortNames() Console.WriteLine("Available Serial Ports:") For Each portName As String In portNames Console.WriteLine(portName) Next Catch ex As Exception Console.WriteLine("Error: " & ex.Message) End Try Console.ReadLine() End Sub End Module
代码2
Private Sub MTPrint5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '获取计算机有效串口 Dim ports As String() = SerialPort.GetPortNames() '必须用命名空间,用SerialPort,获取计算机的有效串口 Dim port As String For Each port In ports ComboBox1.Items.Add(port) '向combobox中添加项 Next port End Sub
标签:vb,Console,Sub,System,SerialPort,串口,End,net From: https://www.cnblogs.com/Sunshine-bing/p/18202059