當前位置:編程學習大全網 - 源碼下載 - 關於VB6.0串口通訊的問題

關於VB6.0串口通訊的問題

串口控件的參數設置應該有問題,建議采用串口控件事件觸發的方式,接收數據。下面的代碼是我以前寫的多串口通訊的串口初始化函數,妳參考壹下吧,有問題追問。

Public Sub psubInitComPort(intMsCommIndex As Integer, intComNo As Integer, strSettings As String, intInBuffSize As Integer, intRThreshold As Integer, blnPortOpen As Boolean)

On Error GoTo err_proc

If blnPortOpen Then '--打開串口

MSComm(intMsCommIndex).CommPort = intComNo '--使用端口Com1~8

MSComm(intMsCommIndex).Settings = strSettings '"1200,N,8,1" '--設置端口屬性,設置波特率1200、無奇偶校驗、8數據位和1停止位

MSComm(intMsCommIndex).InBufferSize = intInBuffSize '1024 '--設置接收緩沖區大小為1024個字節

MSComm(intMsCommIndex).RThreshold = intRThreshold ' 12 '--設置每接收n個字節觸發OnComm()事件

MSComm(intMsCommIndex).InBufferCount = 0 '--清空接收緩沖區

MSComm(intMsCommIndex).InputLen = 0 '--使用Input屬性時在接收緩沖區讀取的字符數,0為讀取整個接收緩沖區內容

MSComm(intMsCommIndex).InputMode = comInputModeBinary '--Input屬性取的數據是二進制數據

If Not MSComm(intMsCommIndex).PortOpen Then '--打開串口

MSComm(intMsCommIndex).PortOpen = True

End If

Else

If MSComm(intMsCommIndex).PortOpen Then '--關閉串口

MSComm(intMsCommIndex).PortOpen = False

End If

End If

Exit Sub

err_proc:

End Sub

  • 上一篇:為什麽尤雨溪·猶大說VUE沒有完全追隨MVVM?
  • 下一篇:如何弄微商小程序?
  • copyright 2024編程學習大全網