基於VB的串口使用

來源:互聯網
上載者:User

這個是個好東西,當時也是搜了很多資料才做出來的,第一個介面用來選擇串口,它可以自動搜尋當前可用的串口,這個很重要,沒有警告,不會崩潰。

先看程式。

Dim comn(9) As BytePrivate Function jiance()Me.Combo1.Clearm = 0On Error Resume NextFor i = 1 To 10Me.MSComm1.CommPort = iMe.MSComm1.PortOpen = TrueIf Err.Number = 0 Then    Me.Combo1.AddItem "串口" & i    comn(m) = i    m = m + 1End IfMe.MSComm1.PortOpen = FalseErr.ClearNext iMe.Combo1.ListIndex = 0Command1.Enabled = TrueIf m = 0 Then    Me.Combo1.Text = "未檢測到串口"    Command1.Enabled = FalseEnd IfEnd FunctionPrivate Sub Command1_Click()ClsPrint comn(Me.Combo1.ListIndex)comnum = comn(Me.Combo1.ListIndex)Form1.HideForm2.ShowEnd SubPrivate Sub Command2_Click()If MsgBox("確定要退出系統嗎?", vbOKCancel, "退出提醒") = vbOK Then EndEnd SubPrivate Sub Command3_Click()Call jianceEnd SubPrivate Sub Form_Load()Command1.Enabled = FalseCall jianceEnd Sub

運行這樣的:

已經用到了我的一些項目中了,值得收藏。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.