架构师◎ 代做诚信第一
关注数: 2 粉丝数: 13 发帖数: 338 关注贴吧数: 25
还有优化的地步么。速度好慢 Private Sub WriteDateToTxT(ByRef DateBuffAll() As Byte, BlockNumber As Long) 'On Error Resume Next Dim i, j, k, x As Long Dim Timestamp As String '存时间戳 Dim MessageChannel As String '通道号 Dim MessageLength As String '数据长度 Dim MessageType As String '数据类型,用于判断是标准帧还是拓展帧 Dim MessageID As String '报文ID Dim MessageDate As String '报文数据段 Dim Message As String '汇总 Dim str0 As String '将数组转换成字符串,查询指定字符 Dim DateBuff(511) As Byte ' DoEvents '数据处理 For k = 0 To BlockNumber - 1 For x = 0 To 512 - 1 DateBuff(x) = DateBuffAll(x + (k * 512)) Next x DoEvents For i = 0 To (23 - 1) Step 1 '一个块23个报文,一个报文22个字节 '时间戳计算 Timestamp = Str(DateBuff(i * 22)) + Str(DateBuff(i * 22 + 1)) * Str(256 ^ 1) + Str(DateBuff(i * 22 + 2)) * Str(256 ^ 2) '时间戳整数位 If Val(Timestamp) = 0 Then Timestamp = "0" & (Str(DateBuff(i * 22 + 3)) + Str(DateBuff(i * 22 + 4)) * Str(256 ^ 1) _ + Str(DateBuff(i * 22 + 5)) * Str(256 ^ 2)) / 100000 '合并时间戳小数位 Else Timestamp = Timestamp + (Str(DateBuff(i * 22 + 3)) + Str(DateBuff(i * 22 + 4)) * Str(256 ^ 1) _ + Str(DateBuff(i * 22 + 5)) * Str(256 ^ 2)) / 100000 '合并时间戳小数位 End If '通道号 MessageChannel = Str(DateBuff(i * 22 + 6)) '判断错误帧 If Chr(DateBuff(i * 22 + 7)) = "E" And Chr(DateBuff(i * 22 + 8)) = "r" And Chr(DateBuff(i * 22 + 9)) = "r" And Chr(DateBuff(i * 22 + 10)) = "o" _ And Chr(DateBuff(i * 22 + 11)) = "r" And Chr(DateBuff(i * 22 + 12)) = "F" And Chr(DateBuff(i * 22 + 13)) = "r" And Chr(DateBuff(i * 22 + 14)) = "a" _ And Chr(DateBuff(i * 22 + 15)) = "m" And Chr(DateBuff(i * 22 + 16)) = "e" Then '有错误帧 Message = Message & Timestamp & " " & MessageChannel & " " & "ErrorFrame" & " " & Str(DateBuff(17)) Else '没有错误帧 '数据长度 MessageLength = Str(DateBuff(i * 22 + 7)) '数据类
1 下一页