串口通信232VB程序多字节发送改编
现在下面的这个程序是单字节发送,比如发送的是01他接收的就是01.现在我要求要多字节发送,比如发送的是010203对应的接收就是010203,这个程序怎么改都改不对,谢谢了。
Private Sub Form_Load()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
Else
End If
Combo1.AddItem "COM1"
Combo1.AddItem "COM2"
Combo1.AddItem "COM3"
Combo1.ListIndex = 2
Combo3.AddItem "4"
Combo3.AddItem "5"
Combo3.AddItem "6"
Combo3.AddItem "7"
Combo3.AddItem "8"
MSComm1.CommPort = Combo1.ListIndex + 1
MSComm1.Settings = "9600,n,8,1"
ComOpen.Caption = "′ò?a′??ú"
Shape1.FillColor = &HFFFFC0
End Sub
Private Sub ComOpen_Click()
On Error GoTo uerror
If ComOpen.Caption = "1?±?′??ú" Then
MSComm1.PortOpen = False
ComOpen.Caption = "′ò?a′??ú"
Shape1.FillColor = &HFFFFC0
Else
MSComm1.PortOpen = True
ComOpen.Caption = "1?±?′??ú"
Shape1.FillColor = &HFF
End If
Exit Sub
uerror:
msg$ = "?TD§???úo?"
Title$ = "′??úμ÷ê??úê?"
X = MsgBox(msg$, 48, Title$)
End Sub
Private Sub MSComm1_OnComm()
Dim BytReceived() As Byte
Dim i As Integer
Dim strBuff As String
Select Case MSComm1.CommEvent
Case 2
Cls
MSComm1.InputLen = 0 '0±íê??áè??o3???è?2??úèY
strBuff = MSComm1.Input '?áè?μ??o3???
BytReceived() = strBuff '?t?????óê??£ê?
For i = 0 To UBound(BytReceived)
If Len(Hex(BytReceived(i))) = 1 Then
strData = strData & "0" & Hex(BytReceived(i)) & " " 'è?1???óDò???×???£??ò?°210£?è?F??ê?0F£?×?oó21????
Else '??±???ê?1?2ìè?£o 00 0F FE
strData = strData & Hex(BytReceived(i)) & " "
End If
Next
TextReceive = TextReceive & strData
strData = ""
End Select
End Sub
Private Sub ComSend1_Click()
Dim Temp(0) As Byte
Dim strBuff As String
Temp(0) = "&H" & TextSend
MSComm1.Output = Temp
If MSComm1.PortOpen = False Then
MsgBox "??′ò?a′??ú"
End If
On Error GoTo uerror
MSComm1.Output = strBuff
uerror:
End Sub
Private Sub ComClean1_Click()
TextSend.Text = ""
End Sub
Private Sub Timer1_Timer()
Call ComSend1_Click
End Sub
Private Sub Combo1_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
MSComm1.CommPort = Combo1.ListIndex + 1
End Sub
Private Sub ComClean2_Click()
TextReceive.Text = ""
End Sub
[解决办法]
http://download.csdn.net/source/1262066
[解决办法]
把要发的数据组成一数组连续发不就行了!
[解决办法]
触发oncomm事件与MSComm1.RThreshold设置相关。