有关串口的问题 求助啊 程序如下
Dim buffer As VariantDim shi(10000) As Double
Dim shu(10000) As Double
Dim num As Integer
Private Sub Form_Load()
= 4
MSComm1.Settings = "9600,n,8,1"
' MSComm1.InputMode = comInputModeBinary
MSComm1.InputMode = 1
MSComm1.RThreshold = 1
MSComm1.InputLen = 2 '读取缓冲区的两个字符,
MSComm1.InBufferCount = 0
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Select Case
Case comEvReceive
buffer = MSComm1.Input
For i = LBound(buffer) To UBound(buffer)
Text1.Text = buffer(i)
Next i
shi(num) = buffer(0) + buffer(1) * 256
shu(num) = shi(num) * 2.5 / 65536
Text2.Text = shu(num)
num = num + 1
Case comEvSend
End Select
End Sub
比如下位机发一个温度值,十六进制发送,每次发一个字节,分两次发送,先发低字节,再发送高字节,如要发送0X384B 则先发送4B再发38。显然得到的值是正确的。可是为什么每到num=510时就下标越界呢?大家帮忙看看怎么回事啊?比如我要接受一万个数据,即num能达到10000,怎么处理啊?不知道下标越界到底怎么回事