serial port,即串行端口,现在大多数硬件设备均采用串口技术与计算机相连。
Public Class Form1
Private Sub GetSerialPortNames()
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox1.Items.Add(sp)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
GetSerialPortNames()
End Sub
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
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MessageBox.Show("开始发送数据给:" & ListBox1.SelectedItem.ToString())
SendSerialData(TextBox1.Text)
MessageBox.Show("发送" & Trim(TextBox1.Text) & "完毕")
End Sub
End Class