没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
'调用例子
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
'计算CRC校验,两种格式,看哪种方便用哪种计算
Dim aa() As Byte
' Dim CRC() As Byte
Dim bb(1) As Byte '返回的数字
Dim cc(5) As String
cc = Split("01 02 00 00 00 10")
ReDim aa(UBound(cc))
Dim i As Int16
For i = 0 To UBound(cc)
aa(i) = Val("&H" & cc(i))
Next
bb = CRC16(aa) '输入数组,返回数组
MsgBox(Byte2Hex(bb(1)) & Byte2Hex(bb(0)))
'第二种计算方式.从字符到字符
MsgBox(sCRC16("010200000010"))
End Sub
'函数
'CRC16校验函数, 参数是字符串,返回值也是字符串
'sdata 字符串的长度必须是偶数
Public Function sCRC16(sdata As String) As String
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
'计算CRC校验,两种格式,看哪种方便用哪种计算
Dim aa() As Byte
' Dim CRC() As Byte
Dim bb(1) As Byte '返回的数字
Dim cc(5) As String
cc = Split("01 02 00 00 00 10")
ReDim aa(UBound(cc))
Dim i As Int16
For i = 0 To UBound(cc)
aa(i) = Val("&H" & cc(i))
Next
bb = CRC16(aa) '输入数组,返回数组
MsgBox(Byte2Hex(bb(1)) & Byte2Hex(bb(0)))
'第二种计算方式.从字符到字符
MsgBox(sCRC16("010200000010"))
End Sub
'函数
'CRC16校验函数, 参数是字符串,返回值也是字符串
'sdata 字符串的长度必须是偶数
Public Function sCRC16(sdata As String) As String
Dim crc16lo As Byte, crc16hi As Byte 'crc寄存器
Dim cl As Byte, ch As Byte '多项式码&ha001
Dim savehi As Byte, savelo As Byte
Dim i As Integer
Dim Data() As Byte
Dim iLength As Int16
iLength = Len(sdata)
'=====================
If iLength Mod 2 <> 0 Then 'sdata 字符串的长度必须是偶数
sdata = "0" & sdata
End If
iLength = Len(sdata) / 2
ReDim Data(iLength - 1)
Dim R As Integer
i = 0
For R = 1 To Len(sdata) - 1 Step 2
Data(i) = Val("&H" + Mid(sdata, R, 2)) '把16进制字符转换成字节
Debug.Print(i & "," & Mid(sdata, R, 2))
i = i + 1
Next
'=============================
Dim flag As Integer
crc16lo = &HFF
crc16hi = &HFF
cl = &H1
Dim cl As Byte, ch As Byte '多项式码&ha001
Dim savehi As Byte, savelo As Byte
Dim i As Integer
Dim Data() As Byte
Dim iLength As Int16
iLength = Len(sdata)
'=====================
If iLength Mod 2 <> 0 Then 'sdata 字符串的长度必须是偶数
sdata = "0" & sdata
End If
iLength = Len(sdata) / 2
ReDim Data(iLength - 1)
Dim R As Integer
i = 0
For R = 1 To Len(sdata) - 1 Step 2
Data(i) = Val("&H" + Mid(sdata, R, 2)) '把16进制字符转换成字节
Debug.Print(i & "," & Mid(sdata, R, 2))
i = i + 1
Next
'=============================
Dim flag As Integer
crc16lo = &HFF
crc16hi = &HFF
cl = &H1
剩余5页未读,继续阅读
sheep021
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页