欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 原創(chuàng)-visual basic net串口樣板架構(gòu) [打印本頁]

作者: xjbworld    時間: 2023-9-5 11:41
標(biāo)題: 原創(chuàng)-visual basic net串口樣板架構(gòu)
visual basicnet其實比visual C#更好用,作為嵌入式開發(fā)人員,用basic入門更簡單,可以很快做出調(diào)試產(chǎn)品工具。附件是完整項目
這個是電腦串口尋找子函數(shù)
   Private Sub com_channel_get(ByVal getcom1 As Integer)

        Dim getcom As Integer
        Dim ports As String() = SerialPort.GetPortNames() '必須用命名空間,用SerialPort,獲取計算機的有效串口
        Dim port As String

        For Each port In ports
            Console.WriteLine(port)
        Next port

        ComboBox1.Items.Clear()
        ComboBox1.Text = ""
        For Each port In ports
            ComboBox1.Items.Add(port) '向combobox中添加項
        Next port
        getcom = ComboBox1.Items.Count '讀ComboBox1的數(shù)值


        Dim comnum As Integer
        Dim textcom As String
        ComboBox1.Enabled = False


        '     Exit Sub

        Dim mBaudRate As Integer
        Dim mParity As IO.Ports.Parity
        Dim mDataBit As Integer
        Dim mStopbit As IO.Ports.StopBits
        Dim mPortName As String = "COM1"


        mBaudRate = 9600   '比特率
        mParity = Parity.None  '校驗位檢查設(shè)定
        mDataBit = 8    '數(shù)據(jù)位設(shè)定值
        mStopbit = StopBits.One  '停止位設(shè)定值



        For comnum = 0 To getcom - 1 Step 1
            ComboBox1.SelectedIndex() = comnum '第一個端口為默認(rèn)
            mPortName = ComboBox1.GetItemText(ComboBox1.SelectedItem) '欲開啟的通訊端口  
            '     mPortName = "COM3"
        Next comnum

        RS232 = New IO.Ports.SerialPort(mPortName, mBaudRate, mParity, mDataBit, mStopbit)

        If RS232.IsOpen = True Then  '尚未開啟
            RS232.Close()  '開啟通訊端口
        End If

        Threading.Thread.Sleep(50)

        Try
            If RS232.IsOpen = False Then  '尚未開啟
                RS232.Open()  '開啟通訊端口
                RS232.ReceivedBytesThreshold = 1        '設(shè)置引發(fā)事件的門限值
            End If
        Catch
            Try

                If RS232.IsOpen = True Then  '尚未開啟
                    RS232.Close()  '開啟通訊端口
                End If
            Catch
            End Try
        End Try

        Exit Sub

        Dim hexBytes(3) As Byte

        hexBytes(0) = &H6A
        'RS232.Write(hexBytes, 0, 1)
        RS232.Write("AT+DISC" + Chr(&HD) + Chr(&HA))
        Threading.Thread.Sleep(500)

        '   Dim rxdata As String = RS232_Data(3)
        Label1.Text = "通信未連接"
        Label1.ForeColor = Color.Red
        Dim textcompare As String = ""
        If (Len(gl_string) > 4) Then
            textcompare = Mid(gl_string, 1, 5)
        End If
        'ERROR OR OK+DISC
        If ((textcompare = "ERROR") Or (textcompare = "OK+DI")) Then
            Label1.Text = "通信已連接"
            Label1.ForeColor = Color.Green
            setrxnum = 4

        End If
        '    If (RS232.BytesToRead >= 5) Then
        'setrxnum = 8 '打開串口自動讀取
        '   Exit For
        '    End If


        If RS232.IsOpen = True Then  '尚未開啟
            RS232.Close()  '開啟通訊端口
        End If


    End Sub
prj_Vbnet.zip (509.89 KB, 下載次數(shù): 1)




作者: heicad    時間: 2024-1-22 02:43
好資料,51黑有你更精彩!!!




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1