1、全局代码
'''全局引用dll,引用的dll在附件中
Public Declare Function API_PCDRead Lib "mi.dll" (ByVal handle As Integer, ByVal deviceAddr As Integer, ByVal mode As Byte, ByVal blk_Addr As Byte, ByVal Num_blk As Byte, ByRef snr As Byte, ByRef Buffer As Byte) As Integer
Public Function myVal(ByVal str As String)
Dim retVal As Integer
retVal = 0
If Len(str) = 1 Then
If str >= "0" And str <= "9" Then
retVal = Val(str)
ElseIf str >= "a" And str <= "z" Then
retVal = Asc(str) - Asc("a") + 10
ElseIf str >= "A" And str <= "Z" Then
retVal = Asc(str) - Asc("A") + 10
End If
End If
myVal = retVal
End Function
Public Function hexToBin(ByVal str As String, ByRef Buffer() As Byte)
Dim strRemain As String
Dim firstChar As Boolean
Dim i, count, inputLen, remainLen As Integer
i = 0
count = 0
firstChar = True
strRemain = str
Do While Len(strRemain) > 0
If Mid(strRemain, 1, 1) = " " Then
firstChar = True
strRemain = Mid(strRemain, 2)
ElseIf firstChar = True Then
If Len(strRemain) = 1 Then
Buffer(count) = myVal(strRemain)
ElseIf Len(strRemain) >= 2 Then
Buffer(count) = myVal(Mid(strRemain, 1, 1)) * 16 + myVal(Mid(strRemain, 2, 1))
strRemain = Mid(strRemain, 3)
End If
count = count + 1
firstChar = False
Else
strRemain = Mid(strRemain, 2)
End If
Loop
hexToBin = count
End Function
'从数组中取多少为
Public Function strByHex(ByRef Buffer() As Byte, ByVal bufferSize As Integer)
Dim i As Integer
Dim strRet, strSingle As String
strRet = ""
For i = 0 To bufferSize - 1
strSingle = Hex$(Buffer(i))
If Len(strSingle) = 1 Then
strSingle = "0" & strSingle
End If
If bufferSize = 1 Then
strRet = strSingle
Else
strRet = strRet + strSingle + " "
End If
Next
strByHex = strRet
End Function
2、调用代码,涉及到对应的控件,无法直接改写执行。请自行测试。
[此贴子已经被作者于2018/11/16 9:21:41编辑过]