vb 统计传送字符出错率(本人想做字符接收的出错率,发送的信号字符串是:"

hua8426700 2008-03-22 12:06:07

Option Explicit
Dim Sendstr() As Byte Dim ReceiveStr$ Dim RcvByte() As Byte Dim RcvLen As Integer
Private Sub CmdExit_Click()
End
End Sub
Private Sub CmdSend_Click()
Dim str As String
Dim strArray() As String
Dim i ,J As Integer
Dim n As Single
str = Trim(txtSend.Text)
strArray = Split(str, " ")
J = UBound(strArray)
ReDim Sendstr(J)
For i = 0 To UBound(strArray)
Sendstr(i) = Val("&h" & strArray(i)) '十六进制
' senddata()=sendstr(i)
Next i
Comm1.Output = Sendstr
If RcvLen Then
Debug.Print RcvLen
str = ""
For i = 0 To RcvLen - 1
str = str & btoHex(RcvByte(i)) & " "
Next i
txtReceive.Text = txtReceive.Text & str & Format(Now, " h:m:s") & vbCrLf
End If
RcvLen = 0
End Sub
Private Sub cmdTest_Click()
Dim str As String
Dim strArray() As String
Dim i As Integer
Dim J As Integer
Dim n As Single
Dim rByte() As Byte
str = Trim(txtSend.Text)
strArray = Split(str, " ")
J = UBound(strArray)
ReDim Sendstr(J)
For i = 0 To UBound(strArray)
Sendstr(i) = Val("&h" & strArray(i)) '十六进制
Next i
Comm1.Output = Sendstr

Timer1.Interval = Val(Trim(txtInterval.Text))
If cmdTest.Caption = "自动测试" Then
Timer1.Enabled = True
cmdTest.Caption = "停止测试"
Else
Timer1.Enabled = True
cmdTest.Caption = "自动测试"
End If
End Sub

Private Sub Comm2_OnComm()
Dim rByte() As Byte
Dim i As Integer
Dim J As Integer
If Comm2.CommEvent = comEvReceive Then
J = Comm2.InBufferCount
rByte = Comm2.Input
ReDim Preserve RcvByte(RcvLen + J)
For i = 0 To J - 1
RcvByte(RcvLen + i) = rByte(i)
Next i
RcvLen = RcvLen + J
End If
End Sub
Private Sub Command1_Click()
txtReceive.Text = ""
End Sub
Private Sub Form_Load()
Dim str As String
Dim strArray() As String
Comm1.InBufferSize = 4096
Comm1.OutBufferSize = 512
Comm1.Settings = "4800,N,8,1"
Comm1.CommPort = 1
Comm1.RThreshold = 1
Comm1.InputMode = comInputModeBinary '二进制形式
Comm1.RTSEnable = False
Comm1.PortOpen = True
Comm1.Output = "SET TYPE 3" & vbCr
Comm2.InBufferSize = 4096
Comm2.OutBufferSize = 512
Comm2.Settings = "4800,N,8,1"
Comm2.CommPort = 2
Comm2.RThreshold = 1
Comm2.InputMode = comInputModeBinary '二进制形式
Comm2.RTSEnable = False
Comm2.PortOpen = True
ReDim Sendstr(5)
Sendstr(0) = &HAA
Sendstr(1) = &HAA
Sendstr(2) = &HAA
Sendstr(3) = &HAA
Sendstr(4) = &HAA '先发几个随机字符一确保能显示 End Sub
Private Sub Form_Unload(Cancel As Integer)
If Comm1.PortOpen Then Comm1.PortOpen = False
If Comm2.PortOpen Then Comm2.PortOpen = False
End Sub
Private Function btoHex(B As Byte) As String
btoHex = Hex(B)
If Len(btoHex) = 1 Then btoHex = "0" & btoHex
End Function
Private Sub Timer1_Timer()
Dim i As Integer
Dim str As String
Dim Send_num As Integer
If cmdTest.Caption = "停止测试" Then '判断当前是否正在自动测试
If RcvLen Then Debug.Print RcvLen
str = ""
For i = 0 To RcvLen - 1 str = str & btoHex(RcvByte(i)) & " "
Next i str = str & vbCrLf
If Len(txtReceive.Text) > 60000 Then
Open "txtReceive.Txt" For Append As #1
Print #1, txtReceive.Text
Close #1
txtReceive.Text = "" End If
txtReceive.Text = txtReceive.Text & str & Format(Now, " h:m:s") & vbCrLf End If Comm1.Output = Sendstr
RcvLen = 0
ReDim RcvByte(0) Else
Timer1.Enabled = False End If End Sub
现在我需要用VB来实现.以上程序已经实现数据的发送接收,我现在想统计一下发送字符串的条数和接收的条数,希望记录下出错的情况.求高手帮帮忙啦!
...全文
34 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
发帖
VB基础类

7617

社区成员

VB 基础类
社区管理员
  • VB基础类社区
加入社区
帖子事件
创建了帖子
2008-03-22 12:06
社区公告
暂无公告