Computer.Ports 属性

定义

获取一个对象,该对象提供用于访问计算机的串行端口的属性和方法。

public:
 property Microsoft::VisualBasic::Devices::Ports ^ Ports { Microsoft::VisualBasic::Devices::Ports ^ get(); };
public Microsoft.VisualBasic.Devices.Ports Ports { get; }
member this.Ports : Microsoft.VisualBasic.Devices.Ports
Public ReadOnly Property Ports As Ports

属性值

My.Computer.Ports 对象。

示例

此示例介绍如何将字符串发送到计算机的 COM1 串行端口。

即使应用程序生成异常,该 Using 块也允许应用程序关闭串行端口。 操作串行端口的所有代码都应出现在此块中,或者出现在调用Close方法的块中Try...Catch...Finally

该方法 WriteLine 将数据发送到串行端口。

Sub SendSerialData(ByVal data As String)
    ' Send strings to a serial port.
    Using com1 As IO.Ports.SerialPort =
            My.Computer.Ports.OpenSerialPort("COM1")
        com1.WriteLine(data)
    End Using
End Sub

有关详细信息,请参阅 如何:将字符串发送到串行端口

注解

此属性提供对 My.Computer.Ports 对象的轻松访问。 有关详细信息,请参阅 Ports 对象。

按项目类型提供可用性

项目类型 可用
Windows 窗体应用程序 Yes
类库 Yes
控制台应用程序 Yes
Windows 窗体控件库 Yes
Web 控件库
Windows 服务 Yes
网站

适用于

另请参阅