MSCOMM控件问题真的没人知道吗??
'-----------------------------------------------------
'发送区
'-----------------------------------------------------
Public Function SendData(ByRef bytData() As Byte) As Long
On Error Resume Next
MSComm1.InBufferCount = 0 '清空接收缓冲区
MSComm1.Output = bytData '发送数据
Do
DoEvents
Loop Until MSComm1.OutBufferCount = 0 '等待,直到数据发送完毕
MSComm1.OutBufferCount = 0
'-----------------------------------------------------
'接收区
'-----------------------------------------------------
Private Sub MSComm1_OnComm()
On Error Resume Next
Dim BytReceived() As Byte
Dim strBuff As String
Dim strData As Variant
Dim i As Integer
Dim x As Integer
Select Case MSComm1.CommEvent
Case 2
MSComm1.Settings = "19200,M,8,2"
MSComm1.InputLen = 0
strBuff = MSComm1.Input
BytReceived() = strBuff
For i = 0 To UBound(BytReceived)
If Len(Hex(BytReceived(i))) = 1 Then
strData = 0 & Hex(BytReceived(i))
Else
strData = Hex(BytReceived(i))
End If
Next
Text1.Text = Text1.Text
MSComm1.OutBufferCount = 0 '清空发送缓冲区
MSComm1.InBufferCount = 0 '清空接收缓冲区
End Select
End Sub
'---------------------------------------
'发送数据
'---------------------------------------
Private Sub cmdConnect_Click()
Dim bytData1(0) As Byte
Dim bytData(21) As Byte
Dim i As Integer
MSComm1.CommPort = 1 'COM端口
MSComm1.Settings = "19200,m,8,2"
MSComm1.InputMode = comInputModeBinary '采用二进制传输
MSComm1.InBufferCount = 0 '清空接受缓冲区
MSComm1.OutBufferCount = 0 '清空传输缓冲区
MSComm1.SThreshold = 1 '如果传输缓冲区完全空时产生MSComm事件
MSComm1.RThreshold = 1 '不产生MSComm事件
MSComm1.PortOpen = True '打开端口
bytData1(0) = 8
bytData(20) = 8
bytData(21) = 128
For i = 1 To 19
bytData(i) = 0
Next
MSComm1.Settings = "19200,m,8,2" '改变奇偶校验
Call SendData(bytData1) '发送
MSComm1.Settings = "19200,s,8,2" '改变奇偶校验
Call SendData(bytData) '发送
End Sub
当我改变MSComm1.Settings 值后发送没问题,硬件收到信息。可是接收到的数据全部都是3F,我代码全部在这里。请问我的问题出的哪里?该如何解决。解决后100分。不给是小狗