求vb.net 2008版 SerialPort组件下令
求vb.net 2008版 SerialPort组件命令
大家好!如题:求vb.net 2008版 SerialPort组件命令,包括读、写
com1的端口初始化和端口关闭!
简单精炼即可!谢谢!
------解决方案--------------------
Private Sub FrmQuery_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
If sp.IsOpen Then
sp.Close()
End If
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
SendData()
End Sub
Private Sub SendData()
Dim data(5) As Char
Dim str As String = Chr(&H10) + Chr(&H7B) + Chr(&H0) + Chr(&H7B) + Chr(&H16)
Try
sp.Write(str)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
''' <summary>
''' 同步委托
''' </summary>
''' <remarks></remarks>
Public Delegate Sub myDelegate()
''' <summary>
''' 接收数据
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub sp_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim DB() As SByte
Dim LEN, N As Integer
Dim str As String = ""
' Thread.Sleep(100)
'触发-串口收到数据
txtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
If sp.BytesToRead > 0 Then
End If
'If sp.BytesToRead > 0 Then
' ReDim DB(sp.BytesToRead)
'End If
'For M As Integer = 1 To sp.BytesToRead
' DB(M) = sp.ReadByte
' str = str + " " + Format(Hex(DB(M)), "00")
大家好!如题:求vb.net 2008版 SerialPort组件命令,包括读、写
com1的端口初始化和端口关闭!
简单精炼即可!谢谢!
------解决方案--------------------
Private Sub FrmQuery_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
If sp.IsOpen Then
sp.Close()
End If
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
SendData()
End Sub
Private Sub SendData()
Dim data(5) As Char
Dim str As String = Chr(&H10) + Chr(&H7B) + Chr(&H0) + Chr(&H7B) + Chr(&H16)
Try
sp.Write(str)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
''' <summary>
''' 同步委托
''' </summary>
''' <remarks></remarks>
Public Delegate Sub myDelegate()
''' <summary>
''' 接收数据
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub sp_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim DB() As SByte
Dim LEN, N As Integer
Dim str As String = ""
' Thread.Sleep(100)
'触发-串口收到数据
txtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
If sp.BytesToRead > 0 Then
End If
'If sp.BytesToRead > 0 Then
' ReDim DB(sp.BytesToRead)
'End If
'For M As Integer = 1 To sp.BytesToRead
' DB(M) = sp.ReadByte
' str = str + " " + Format(Hex(DB(M)), "00")