Private Sub MSComm1_OnComm()
MSC
End Sub
Private Sub MSC()
Dim intInputLen As Integer
Dim i As Integer
Dim bytInput() As Byte
Dim hxstr As String
Select Case Me.MSComm1.CommEvent
Case comEvReceive
'此处添加处理接收的代码
Me.MSComm1.InputMode = comInputModeBinary '二进制接收
intInputLen = Me.MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = Me.MSComm1.Input
'jieshou
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strData = strData & "0" & Hex(bytInput(i))
Else
strData = strData & Hex(bytInput(i))
End If
Next
hxstr = Left$(strData, 4)
hxstr = Right$(hxstr, 2)
Text1.Text = CStr(CInt(&H13 * 256) + CInt("&H" & hxstr))
End Select
End Sub
MSC
End Sub
Private Sub MSC()
Dim intInputLen As Integer
Dim i As Integer
Dim bytInput() As Byte
Dim hxstr As String
Select Case Me.MSComm1.CommEvent
Case comEvReceive
'此处添加处理接收的代码
Me.MSComm1.InputMode = comInputModeBinary '二进制接收
intInputLen = Me.MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = Me.MSComm1.Input
'jieshou
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strData = strData & "0" & Hex(bytInput(i))
Else
strData = strData & Hex(bytInput(i))
End If
Next
hxstr = Left$(strData, 4)
hxstr = Right$(hxstr, 2)
Text1.Text = CStr(CInt(&H13 * 256) + CInt("&H" & hxstr))
End Select
End Sub
解决方案 »
- 苦寻 绝对给分 类似于这样的 文本文档信息如何变成 每个人的 属性 赋给数组中的每个元素
- 高手求求,来者有分。关于控件制成CAB包下到客户端问题
- 如何记录对画板的操作啊!!!
- 关于FTP问题,请高手指点。
- 找了一个上午,也没有找到vsflexgrid这个属性
- VB操作VF,删除数据,请问物理删除怎么写?
- winamp3.0的那种效果是如何实现的?
- $$$有偿求教: 如何编写传销奖金发放的程序$$$
- 假如我只用到了vb缺省的那几个控件,那我是否就可以只把已编好的程序文件(.exe),考到另一台机器就可以运行了?
- 请教: 记录集与记录集之间根据主键值如何关联,使指针一起移动?
- 求一个刷票的程序
- 征集滚动条的控制意见
Private strData As String
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End SubPrivate Sub MSComm1_OnComm()
Dim intInputLen As Integer
Dim i As Integer
Dim bytInput() As Byte
Dim hxstr As String
Select Case Me.MSComm1.CommEvent
Case comEvReceive
'此处添加处理接收的代码
MSComm1.InputMode = comInputModeBinary '二进制接收
intInputLen = Me.MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = Me.MSComm1.Input
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strData = strData & "0" & Hex(bytInput(i))
Else
strData = strData & Hex(bytInput(i))
End If
Next
hxstr = Left$(strData, 4)
hxstr = Right$(hxstr, 2)
Text1.Text = CStr(CInt(&H13 * 256) + CInt("&H" & hxstr))
End Select
End Sub
Private strData As String
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.RThreshold = 1 '产生OnComm事件
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Select Case Me.MSComm1.CommEvent
Case comEvReceive
MSC
End Select
End Sub
Private Sub MSC()
Dim intInputLen As Integer
Dim i As Integer
Dim bytInput() As Byte
Dim hxstr As String
MSComm1.InputMode = comInputModeBinary '二进制接收
intInputLen = Me.MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = Me.MSComm1.Input
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strData = strData & "0" & Hex(bytInput(i))
Else
strData = strData & Hex(bytInput(i))
End If
Next
hxstr = Left$(strData, 4)
hxstr = Right$(hxstr, 2)
Text1.Text = CStr(CInt(&H13 * 256) + CInt("&H" & hxstr))
End Sub
我给出的代码(VB6调试通过),是基于二进制方式接收数据,然后转换为16进制字符串形式显示。然后需按上下位机的通信协议进行数据处理,以达到你所想要求的结果。
Dim ccount As Integer
Dim ReadStr As String '存放读取读取数据的变量
'直接轮循法
With Com1
Select Case .CommEvent
Case comEvReceive
.RThreshold = 0
Do
ccount = .InBufferCount
Sleep (200)
Loop Until .InBufferCount = ccount
ReadStr = .Input test1.text= ReadStr
.RThreshold = 1
End Select
End With
End Sub