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 Sub Private 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 Sub Public 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
温馨提示:内容为网友见解,仅供参考