Computer.Ports 属性
定义
获取一个对象,该对象提供用于访问计算机的串行端口的属性和方法。Gets an object that provides a property and a method for accessing the computer's serial 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 对象。The My.Computer.Ports object.
示例
此示例介绍如何将字符串发送到计算机的 COM1 串行端口。This example describes how to send strings to the computer's COM1 serial port.
Using 块允许应用程序在即使会生成异常的情况下也关闭串行端口。The Using block allows the application to close the serial port even if it generates an exception. 操作串行端口的所有代码都应出现在此块中,或者出现在块中, Try...Catch...Finally 调用使用 Close 方法。All code that manipulates the serial port should appear within this block, or within a Try...Catch...Finally block with a call to use the Close method.
WriteLine 方法将数据发送到串行端口。The WriteLine method sends the data to the serial port.
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
有关详细信息,请参阅 如何:将字符串发送到串行端口。For more information, see How to: Send Strings to Serial Ports.
注解
此属性提供对对象的轻松访问 My.Computer.Ports 。This property provides easy access to the My.Computer.Ports object. 有关详细信息,请参阅 Ports 对象。For more information, see Ports object.
按项目类型的可用性Availability by Project Type
| 项目类型Project type | 可用Available |
|---|---|
| Windows 窗体应用程序Windows Forms Application | 是Yes |
| 类库Class Library | 是Yes |
| 控制台应用程序Console Application | 是Yes |
| Windows 窗体控件库Windows Forms Control Library | 是Yes |
| Web 控件库Web Control Library | 否No |
| Windows 服务Windows Service | 是Yes |
| 网站Web Site | 否No |