我用MSComm控件接收下位机给我的34字节数据,但是好像没有接收到数据,不知道在哪有问题。我的设置和代码如下
With MSComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InBufferCount = 0
.InputLen = 0
.RThreshold = 1 '32768
.InputMode = comInputModeBinary '以2进制接收
.PortOpen = True
End WithSelect Case MSComm1.CommEvent
Case comEvReceive
MSComm1.RThreshold = 0
m = Timer
While Timer - m < 0.038 '从0.01到0.02(20sm)做延时
Wend
inByte = MSComm1.Input
For i = 0 To UBound(inByte)
If Len(Hex(inByte(i))) = 1 Then
str1 = 0 & Hex(inByte(i))
Else
str1 = Hex(inByte(i))
End If
StrData = StrData & str1
Next
MSComm1.RThreshold = 1
End Select
请大家帮我看看问题在什么地方啊!
With MSComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InBufferCount = 0
.InputLen = 0
.RThreshold = 1 '32768
.InputMode = comInputModeBinary '以2进制接收
.PortOpen = True
End WithSelect Case MSComm1.CommEvent
Case comEvReceive
MSComm1.RThreshold = 0
m = Timer
While Timer - m < 0.038 '从0.01到0.02(20sm)做延时
Wend
inByte = MSComm1.Input
For i = 0 To UBound(inByte)
If Len(Hex(inByte(i))) = 1 Then
str1 = 0 & Hex(inByte(i))
Else
str1 = Hex(inByte(i))
End If
StrData = StrData & str1
Next
MSComm1.RThreshold = 1
End Select
请大家帮我看看问题在什么地方啊!
解决方案 »
- 用webbrowser做循环访问以系列网页,是不是会不稳定??有没什么更好的办法?
- 如何 取得这个网页 的信息?50元求解
- 如何建立.cfg文件?
- 关于在网页上使用控件,存在内存泄漏的问题?谢谢!
- 可能是 SourceSafe 引起的问题(附图)
- IBM公司的面试题,大家交流一下
- listview中,当前选择的listItem项能高度显亮吗?
- 计算机专科就找不到工作吗?志同道和朋友进来聊聊!
- 紧急!!求助关于用MAPX和VB开发地理信息系统,在线给分!!谢谢!!
- listBoxd的MultiSelect属性在程序中如何修改?
- 程序运行后提示缺少一个组件或注册的问题,在线等。谢谢
- 关于FOR循环小弟有几个问题
Dim varP As Variant
With MSComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InBufferCount = 0
.InputLen = 1 '把这个修改为1,每次读一个字节,便于读出处理
.RThreshold = 1 '32768
.InputMode = comInputModeBinary '以2进制接收
.PortOpen = True
End WithSelect Case MSComm1.CommEvent
Case comEvReceive
MSComm1.RThreshold = 0
m = Timer
While Timer - m < 0.038 '从0.01到0.02(20sm)做延时
Wend
Do
sleep 1 '请加入API函数Sleep的声明,用于延迟,以便下位机没有传上来的数据传上来
varP = Null
varP = MSComm1.Input
str1 = str1 & Right("00" & Hex(varP(0)), 2) '读出通信内容
Loop Until MSComm1.InBufferCount = 0
MSComm1.RThreshold = 1
End Select
text13 = strdata
下位机发送时text13没有显示内容
楼上的 m = Timer
While Timer - m < 0.038 '从0.01到0.02(20sm)做延时
这个就是个延时,为什么后边还要加个延时呢?
With MSComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InBufferCount = 0
.InputLen = 0
.RThreshold = 1 '32768
.InputMode = comInputModeBinary '以2进制接收
.PortOpen = True
End With
下边的是在OnComm事件中
Select Case MSComm1.CommEvent
Case comEvReceive
MSComm1.RThreshold = 0
m = Timer
While Timer - m < 0.038 '从0.01到0.02(20sm)做延时
Wend
inByte = MSComm1.Input
For i = 0 To UBound(inByte)
If Len(Hex(inByte(i))) = 1 Then
str1 = 0 & Hex(inByte(i))
Else
str1 = Hex(inByte(i))
End If
StrData = StrData & str1
Next
MSComm1.RThreshold = 1
End Select
Private Sub MSComm1_OnComm()
Dim inByte() As Byte, byt As Byte, bytsj() As Byte
Dim i As Integer
Dim strData As String, str1 As String, m As String
Select Case MSComm1.CommEvent
Case comEvReceive
MSComm1.RThreshold = 0
m = Timer
While Timer - m < 0.038 '从0.01到0.02(20sm)做延时
Wend
inByte = MSComm1.Input
For i = 0 To UBound(inByte)
If Len(Hex(inByte(i))) = 1 Then
str1 = 0 & Hex(inByte(i))
Text14 = str1 ‘最后text14里边显示的是"00"
Else
str1 = Hex(inByte(i))
Text15 = str1 '最后text15里边显示的是"92"
End If
strData = strData & str1
Text13 = strData
'在text13中显示的就是下位机给我发送的正确数据"10030211073511234505050604000800260027030110030211073200000000007492"
Next
MSComm1.RThreshold = 1
End Select
Text16 = strData ’但是到了这个地方就没有了,里边是空的了,为啥啊?
Call subSaveString
End Sub
'
'
Next
End Select
Text16 = strData ’但是到了这个地方就没有了,里边是空的了,为啥啊?
Call subSaveString
MSComm1.RThreshold = 1
End Sub
Next
End Select
Text16 = strData ’但是到了这个地方就没有了,里边是空的了,为啥啊?
Call subSaveString
MSComm1.RThreshold = 1
.........
.........
........
End Sub