⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 从串口读取数据
💻 VB
字号:
Imports ZylGPSReceiverMobile

Public Class FormMain

    ' This delegate enables asynchronous calls for setting
    ' the text property on a TextBox control.
    Private Delegate Sub SetTextCallback(ByVal text As String)
    Private Delegate Sub RefreshPaintBoxCallBack()

    Private Sub SetTextBoxOut(ByVal text As String)
        Try

            ' InvokeRequired required compares the thread ID of the
            ' calling thread to the thread ID of the creating thread.
            ' If these threads are different, it returns true.
            If Me.InvokeRequired Then
                Dim d As New SetTextCallback(AddressOf SetTextBoxOut)
                Me.Invoke(d, New Object() {[text]})
                Return
            End If

            If Me.textBoxOut.Text.Length > 65000 Then
                textBoxOut.Text = String.Empty
            End If

            Me.textBoxOut.Text &= text
            Me.textBoxOut.SelectionStart = textBoxOut.Text.Length
            Me.textBoxOut.SelectionLength = 0
            Me.textBoxOut.ScrollToCaret()
        Catch
            Me.textBoxOut.Text = String.Empty
        End Try
    End Sub

    Private Sub SetTextBoxCoord(ByVal text As String)
        Try
            ' InvokeRequired required compares the thread ID of the
            ' calling thread to the thread ID of the creating thread.
            ' If these threads are different, it returns true.
            If (Me.InvokeRequired) Then
                Dim d As New SetTextCallback(AddressOf SetTextBoxCoord)

                Me.Invoke(d, New Object() {[text]})
                Return

            End If
            If Me.textBoxOut.Text.Length > 10000 Then
                textBoxOut.Text = String.Empty
            End If
            Me.textBoxCoord.Text = text
        Catch
        End Try
    End Sub

    Private Sub SetTextBoxParams(ByVal text As String)
        Try
            ' InvokeRequired required compares the thread ID of the
            ' calling thread to the thread ID of the creating thread.
            ' If these threads are different, it returns true.
            If (Me.InvokeRequired) Then
                Dim d As New SetTextCallback(AddressOf SetTextBoxParams)
                Me.Invoke(d, New Object() {[text]})
                Return

            End If
            Me.textBoxParams.Text = text
        Catch
        End Try
    End Sub

    Private Sub RefreshPaintBox()        
        Try
            If (Me.InvokeRequired) Then

                Dim d As New RefreshPaintBoxCallBack(AddressOf RefreshPaintBox)
                Me.Invoke(d)
                Return
            End If

            Me.pBox.Refresh()
        Catch
        End Try

    End Sub

    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        If lstPorts.SelectedIndex >= 0 AndAlso lstBaud.SelectedIndex >= 0 Then
            cmpGpsReceiver.Port = CType(lstPorts.SelectedIndex + 1, SerialCommPort)
            cmpGpsReceiver.BaudRate = CType(Convert.ToUInt32(lstBaud.SelectedItem.ToString()), SerialBaudRate)
            If Not cmpGpsReceiver.Open() Then
                MessageBox.Show("Cannot open.")
            End If
        Else
            MessageBox.Show("Select port and baud rate.")
        End If
    End Sub
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        cmpGpsReceiver.Close()
    End Sub

    Private Sub cmpGpsReceiver_Received(ByVal sender As System.Object, ByVal e As ZylGPSReceiverMobile.DataEventArgs) Handles cmpGpsReceiver.Received
        Dim str As String
        str = "Lt: " & cmpGpsReceiver.Position.Latitude_Degree.ToString() & "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -