首頁>Club>
4
回覆列表
  • 1 # 用戶470207478119515

    VB6.0MsComm控件可以利用OnComm事件連續獲取來自外設發送的信號。

    基於:

    1)MsComm控件的RThreshold 屬性不為0和恰當的接收代碼。

    2)使用電腦主機板物理COM口或PCI多串口卡上的COM口COM,這樣的COM口是全雙工的,發送與接收不會衝突。

    3)高質量的接收代碼和符合通信協議和數據幀規約的接收處理代碼。

    實例代碼:

    Private Sub Form_Load() MSComm1.InputMode = comInputModeBinary '採用二進制傳輸 MSComm1.InBufferCount = 0 '清空接受緩衝區 MSComm1.OutBufferCount = 0 '清空傳輸緩衝區 MSComm1.RThreshold = 1 '產生MSComm事件 MSComm1.InBufferSize = 1024 TxtSend = "" TxtSend = "" txtReceive = "" Text2 = ""End SubPrivate Sub MSComm1_OnComm() '接收數據 Dim strBuff As String Select Case MSComm1.CommEvent Case 2 MSComm1.InputLen = 0 strBuff = MSComm1.Input BytReceived() = strBuff jieshou lenInput = Len(strData) Text2 = lenInput \ 2 '數據處理代碼 End SelectEnd SubPublic Function jieshou() '接收數據處理為16進制 Dim i As Integer For i = 0 To UBound(BytReceived) If Len(Hex(BytReceived(i))) = 1 Then strData = strData & "0" & Hex(BytReceived(i)) Else strData = strData & Hex(BytReceived(i)) End If Next txtReceive = strDataEnd Function

  • 中秋節和大豐收的關聯?
  • 蘋果手錶watch激活鎖怎麼解?