Private Sub Form_Load()
With ctrMSComm
.CommPort = 3
.Settings = "38400,N,8,1"
.InBufferSize = 4096
.RThreshold = 1
.InBufferCount = 0
.InputLen = 0
End With
If ctrMSComm.PortOpen = False Then
ctrMSComm.PortOpen = True
If Err Then
MsgBox (Err.Description)
Exit Sub
End If
End If
End SubPrivate Sub ctrMSComm_OnComm()
Dim bytInput() As Byte
Dim intInputLen As Integer
Select Case Form1.ctrMSComm.CommEvent
Case comEvReceive
'此处添加处理接收的代码
Form1.ctrMSComm.InputMode = comInputModeBinary
intInputLen = Form1.ctrMSComm.InBufferCount
ReDim bytInput(intInputLen)
bytInput = Form1.ctrMSComm.Input
Call InputManage(bytInput, intInputLen)
Call GetDisplayText
End Select
End Sub
Public bytReceiveByte() As Byte '接收到的字节
Public intReceiveLen As Integer '接收到的字节数Public strHex As String '十六进制编码
'***********************************
'为输出准备文本
'保存在全局变量
'strText
'strHex
'strAddress
'总行数保存在
'intLine
'***********************************Public Sub GetDisplayText() Dim n As Integer
Dim intValue As Integer
Dim intHighHex As Integer
Dim intLowHex As Integer
strHex = "" '设置初值
'*****************************************
'获得16进制码
'*****************************************
For n = 1 To intReceiveLen
intValue = bytReceiveByte(n - 1)
intHighHex = intValue \ 16
intLowHex = intValue - intHighHex * 16
If intHighHex < 10 Then
intHighHex = intHighHex + 48
Else
intHighHex = intHighHex + 55
End If
If intLowHex < 10 Then
intLowHex = intLowHex + 48
Else
intLowHex = intLowHex + 55
End If
strHex = strHex + " " + Chr$(intHighHex) + Chr$(intLowHex) + " " If (n Mod 8) = 0 Then '设置换行
strHex = strHex + Chr$(13) + Chr$(10)
End If
Form1.Text1.Text = strHex
Next n
End Sub'**********************************
'输入处理
'处理接收到的字节流,并保存在全局变量
'bytReceiveRyte()
'**********************************Public Sub InputManage(bytInput() As Byte, intInputLenth As Integer)
Dim n As Integer '定义变量及初始化
ReDim Preserve bytReceiveByte(intReceiveLen + intInputLenth) For n = 1 To intInputLenth Step 1
bytReceiveByte(intReceiveLen + n - 1) = bytInput(n - 1)
Next n
intReceiveLen = intReceiveLen + intInputLenth
End Sub数据是硬件发过来的,发送的数据量非常大,串口调试精灵可以一直接收数据并且显示。结果自己写的只能显示2,3行,然后程序就死了。求大神帮一下!新手,实在弄不明白。。VB串口
解决方案 »
- VBA如何执行带参数的存储过程
- 请教:由于控件太多,在一个界面中放不下,但是又必须在同一个界面中显示,我想,如何用垂直滚动条来现实?
- 如何获取QQLive的登录命令
- 困惑中,text1与text2的比较,这怎么解决啊??
- 100分请教数据保存问题!谢谢大家
- 怎样改变控件的形状和颜色??????!!!!!!???????????
- 一返回查询结果的存储过程如何以可读写方式打开?基决问题即结贴
- 小樵顿首: 请问有没有方法把textbox的backcolor属性改为透明?
- Inet1控件问题!50分奉送(回答以前的问题-用Inet1控件做ftp下载问题,急!!!,分照送!)
- 一点小问题,小弟谢了
- vb 网络编程 遇到的 关于接收缓冲区问题
- VB中ADO连接显示的datagrid1内部的数据怎么设置自动换行
http://download.csdn.net/detail/veron_04/4037248