vb6.0 串口通讯 运行后总显示溢出是哪的毛病?应该怎么解决,代码如下: 20
DimaddrnumAsInteger'要设置参数仪表的地址代号DimcaijiAsBoolean'采集状态标志DimshezhizhiAsLong'设置值DimiAsI...
Dim addrnum As Integer '要设置参数仪表的地址代号
Dim caiji As Boolean '采集状态标志
Dim shezhizhi As Long '设置值
Dim i As Integer '轮循采集仪表代号
Dim cmdout(0 To 7) As Byte
Dim DJY As Long
Private Sub Form_Load()
For i = 1 To 7
Next i
i = addrnum
Call chushihua '设置串口参数
Timer1.Enabled = True
caiji = True
End Sub
Private Sub Timer1_Timer()
On Error GoTo ErrLine
i = IIf(i + 1 > 32767, 1, i + 1)
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
cmdout(0) = 128 + i
cmdout(1) = cmdout(0)
cmdout(2) = &H52
cmdout(3) = &H1
cmdout(4) = &H0
cmdout(5) = &H0
DJY = 1 * 256 + 82 + i
If DJY > 65535 Then DJY = DJY Mod 65535 '若校验码大于65535则取余,但不会大于65535
cmdout(6) = CByte(DJY Mod 256)
cmdout(7) = CByte(DJY \ 256)
MSComm1.InBufferCount = 0
MSComm1.Output = cmdout
Exit Sub
ErrLine:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) + "" + Err.Description, vbOKOnly + vbInformation, "提示信息!"
End If
Err.Clear
End Sub 展开
Dim caiji As Boolean '采集状态标志
Dim shezhizhi As Long '设置值
Dim i As Integer '轮循采集仪表代号
Dim cmdout(0 To 7) As Byte
Dim DJY As Long
Private Sub Form_Load()
For i = 1 To 7
Next i
i = addrnum
Call chushihua '设置串口参数
Timer1.Enabled = True
caiji = True
End Sub
Private Sub Timer1_Timer()
On Error GoTo ErrLine
i = IIf(i + 1 > 32767, 1, i + 1)
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
cmdout(0) = 128 + i
cmdout(1) = cmdout(0)
cmdout(2) = &H52
cmdout(3) = &H1
cmdout(4) = &H0
cmdout(5) = &H0
DJY = 1 * 256 + 82 + i
If DJY > 65535 Then DJY = DJY Mod 65535 '若校验码大于65535则取余,但不会大于65535
cmdout(6) = CByte(DJY Mod 256)
cmdout(7) = CByte(DJY \ 256)
MSComm1.InBufferCount = 0
MSComm1.Output = cmdout
Exit Sub
ErrLine:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) + "" + Err.Description, vbOKOnly + vbInformation, "提示信息!"
End If
Err.Clear
End Sub 展开
2013-09-09
展开全部
什么地方出现溢出?
祝好
推荐看书
Visual_Basic与_RS-232_串行通信控制
祝好
推荐看书
Visual_Basic与_RS-232_串行通信控制
更多追问追答
追问
不知道 怎么看在哪出现溢出?? 我觉得我这个只有刚开始运行时是采集数据了,然后传感器温度变了也没再采集到温度的,是不是内存的问题??还是缓冲区满了??
追答
没有 chushihua 函数
调试时没有溢出提示
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码不全,无法测试。
参考:http://www.vbgood.com/thread-83700-1-1.html
参考:http://www.vbgood.com/thread-83700-1-1.html
追问
我下了,但是不太会用,还是就是没反应的?我设置地址是都少都没变化,波特率也改了啊
追答
LZ,你溢出是指向代码的哪一行?
Private Sub Timer1_Timer()
On Error GoTo ErrLine
i = IIf(i + 1 > 32767, 1, i + 1)
If i > 7 Then
i = 0
End If
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
cmdout(0) = 128 + i
cmdout(1) = cmdout(0)
cmdout(2) = &H52
cmdout(3) = &H1
cmdout(4) = &H0
cmdout(5) = &H0
djy = 1 * 256 + 82 + i
If djy > 65535 Then djy = djy Mod 65535 '若校验码大于65535则取余,但不会大于65535
cmdout(6) = CByte(djy Mod 256)
cmdout(7) = CByte(djy \ 256)
MSComm1.InBufferCount = 0
MSComm1.Output = cmdout
Exit Sub
ErrLine:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) + "" + Err.Description, vbOKOnly + vbInformation, "提示信息!"
End If
Err.Clear
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询