1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
Imports System.IO.Ports
Imports System
Imports System.Collections
Public Class Form2
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 Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetSerialPortNames()
End Sub
Sub SendSerialData(ByVal data1 As Byte(), ByVal data2 As Byte())
' Send bytes to a serial port.
Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM1", 4800, Parity.None, 8, StopBits.One)
If com1.IsOpen Then
MsgBox("port opened")
com1.Write(data1, 0, 7)
com1.Write(data2, 0, 7)
MsgBox("message sended")
com1.Close()
MsgBox("port closed")
Else
MsgBox("port closed")
End If
End Using
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim adresse As UInteger = 1
adresse = Byte.Parse((adresse).ToString())
Dim b As Byte() = New Byte() {&HFF, adresse, &H0, &H4, &H0, &H20, &H26}
Dim c As Byte() = New Byte() {&HFF, adresse, &H88, &H0, &H0, &H0, &H89}
SendSerialData(c, b)
End Sub
End Class |
Partager