L
lht123
Unregistered / Unconfirmed
GUEST, unregistred user!
这是module 代码
************************************************************************
' *
' * Copyright(c) 2003, 周立功单片机发展有限公司
' * All rights reserved.
' *
' * 文 件: Mur100Fun.bas
' *
' * 摘 要: 本程序主要是演示Mur100 API函数调用方法
' *
' *
' * 创建日期: 2003年02月13日
' *
' *************************************************************************
' */
'*************************************************************************
'* 声明引用系统API函数
'*************************************************************************
'------------------------------------------------------------
'说明: 挂起当前线程
'参数: dwMilliseconds 挂起时间(毫秒)
'返回: 无
'------------------------------------------------------------
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'*************************************************************************
'* 声明引用 RC500USB.dll API函数
'*************************************************************************
'------------------------------------------------------------
'说明: 发送请求命令(Request),检查在有效范围内是否有卡的存在
'参数: mode:请求类型
' (mode=0:请求天线范围内IDLE状态的卡(HALT状态的除外)
' mode=1: 请求天线范围内的所有卡)、
' tagtype:返回的目标类型
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_request Lib "RC500USB.dll" (ByVal mode As Byte, ByRef tagtype As Byte) As Byte
'------------------------------------------------------------
'说明: 开始防冲突操作
'参数: bcnt:为预选卡所分配的位的个数,通常Bcnt=0、
' snr:返回卡的序号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_anticoll Lib "RC500USB.dll" (ByVal bcnt As Byte, ByRef snr As Long) As Byte
'------------------------------------------------------------
'说明: 开始防冲突操作(是否充许多张卡操作)
'参数: encoll:若为1,则使能多张卡进入天线区;
' (若为0,则不允许多张卡进入,此时返回错误MI_COLLERR)、
' bcnt:为预选卡所分配的位的个数,通常Bcnt=0、
' snr:返回卡的序号
'返回: 0 发送数据成功、非0发送数据失败
'------------------------------------------------------------
Declare Function RC500USB_anticoll2 Lib "RC500USB.dll" (ByVal encoll As Byte, ByVal bcnt As Byte, ByRef snr As Byte) As Byte
'------------------------------------------------------------
'说明: 选择某一个序号的mf卡
'参数: snr:卡的序号
' size:返回卡的容量
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_select Lib "RC500USB.dll" (ByVal snr As Long, ByRef size As Byte) As Byte
'------------------------------------------------------------
'说明: 将RC500中的密匙与卡中的密匙进行验证(每个扇区密码相同)
' (在进行对卡片的读写操作之前,必须成功执行此指令。
' 系统初始化时,主控设备将把每个扇区的密码加载到读卡器中。
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04、
' secnr:要验证的卡扇区号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_authentication Lib "RC500USB.dll" (ByVal mode As Byte, ByVal secnr As Long) As Byte
'------------------------------------------------------------
'说明: 将RC500中的密匙与卡中的扇区密匙进行验证。
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04
' secnr:要验证的卡扇区号
' keynr:用于证实的密匙区号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_authentication2 Lib "RC500USB.dll" (ByVal mode As Byte, ByVal secnr As Byte, ByVal keynr As Byte) As Byte
'------------------------------------------------------------
'说明: 密钥验证(在对卡进行读、写、加、减等操作前)
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04
' key:存储密钥缓冲区
' secnr:要验证的卡扇区号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_authkey Lib "RC500USB.dll" (ByVal mode As Byte, ByRef key As Byte, ByVal secnr As Byte) As Byte
'------------------------------------------------------------
'说明: 使被选择的卡产生一个暂停(即使之处于Halt模式)
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_halt Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 读取卡的一个块的数据
'参数: addr:块号(0x00--0x3f)
' data:块数据,长度16个字节
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_read Lib "RC500USB.dll" (ByVal addr As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 对指定的块进行整块写操作。
'参数: addr:块号(0x00--0x3f)
' data:块数据,长度16个字节
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_write Lib "RC500USB.dll" (ByVal addr As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 往一个块中写入数值
'参数: addr: 块号(0x00--0x3f)
' value: 要写入的值
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_writeval Lib "RC500USB.dll" (ByVal addr As Byte, ByVal value As Long) As Byte
'------------------------------------------------------------
'说明: 读出一个块中的数值
'参数: addr: 块号(0x00--0x3f)
' value: 存储要读出的值
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_readval Lib "RC500USB.dll" (ByVal addr As Byte, ByRef value As Long) As Byte
'------------------------------------------------------------
'说明: 对一个块进行值操作,并把结果存到trans_addr
'参数: mode:模式(1字节,加C1H,减C0H,复制C2H)
' addr:块号(0x00--0x3f)
' value:要操作的值
' trans_addr:传输块地址
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_value Lib "RC500USB.dll" (ByVal mode As Byte, ByVal addr As Byte, ByRef value As Long, ByVal trans_addr As Byte) As Byte
'------------------------------------------------------------
'说明: RC500中的密匙与卡中的密匙进行验证(全部密匙相同)
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04
' secnr:要载入的读卡器中的密钥区号
' key:密码,长度6个字节
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_load_key Lib "RC500USB.dll" (ByVal mode As Byte, ByVal secnr As Byte, ByRef key As Byte) As Byte
'------------------------------------------------------------
'说明: 使射频电路关闭所规定的时间
' (若msec=0,射频电路部分将一直处于关闭状态,
' 一直到下一个Request命令到来。
' 关闭射频能使天线内的所有卡复位)
'参数: msec:射频电路关闭时间(以毫秒为单位)
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_reset Lib "RC500USB.dll" (ByVal msec As Byte) As Byte
'------------------------------------------------------------
'说明: RC500的复位管脚置为高电平,关闭RC500,使之电流最小。
' 若要重新启动则需调用Config()
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_close Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 系统配制(模块每次上电复位之后,都必须首先调用此函数
' 对模块进行初始化,才能进行进一步的操作。)
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_config Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 返回一个包含有RC500的产品类型标识和序列号的数组。
'参数: info: info[0]-info[4]为RC500的产品类型标识,依次为0x30,
' 0x88,0xf8,0x00,0xXX,info[5]-info[8]为RC500的序列号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_get_info Lib "RC500USB.dll" (ByRef info As Byte) As Byte
'------------------------------------------------------------
'说明: 此函数设置读卡器中的控制位为高电平。
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_set_control_bit Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 清除MIFARE读卡器中的控制位
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_clr_control_bit Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 此函数输出一驱动信号可驱动蜂鸣器和绿色发光管,
' 持续时间、间隙时间和重复次数可调
'参数: contrl: 控制字,如下表相应位为1时该器件动作。
' contrl^1为绿灯,contrl^0为蜂鸣器
' opentm: 低电平持续时间,取值(0-255),10ms的分辨率
' closetm: 高电平间隙时间,取值(0-255),10ms的分辨率
' repcnt: 重复次数
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_buzzer Lib "RC500USB.dll" (ByVal contrl As Byte, ByVal opentm As Byte, ByVal closetm As Byte, ByVal repcnt As Byte) As Byte
'------------------------------------------------------------
'说明: 此函数将RC500内EEPROM的数据读出。
'参数: addr: 被读RC500内EEPROM首址,必须小于0x80
' length: 被读数据长度
' data: 读出数据缓冲区首址
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_read_E2 Lib "RC500USB.dll" (ByVal addr As Byte, ByVal length As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 将数据写入RC500内EEPROM中
'参数: addr: RC500内EEPROM的写入首址,取值范围(0x30-0x7E)
' length: 被写数据长度
' data: 写入数据缓冲区首址
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_write_E2 Lib "RC500USB.dll" (ByVal addr As Byte, ByVal length As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 初始化MUR-100读卡器
'参数: 无
'返回: 无
'------------------------------------------------------------
Declare Function RC500USB_init Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 关闭MUR-100读卡器
'参数: 无
'返回: 无
'------------------------------------------------------------
Declare Sub RC500USB_exit Lib "RC500USB.dll" ()
'/************************************************************
' 函数返回值定义:
' 0: 操作成功;
' 1: 在有效区域内没有卡;(Check Write出错)
' 2: 从卡中接收到了错误的CRC校验和;(Check Write:写出错(比较出错))
' 3: 值溢出;
' 4: 不能验证;
' 5: 从卡中接收到了错误的校验位;
' 6: 通信错误;
' 8: 在防冲突时读到了错误的串行码;
' 10: 卡没有验证;
' 11: 从卡中接收到了错误数量的位;
' 12: 从卡中接收了错误数量的字节;
' 14: 调用Transfer函数出错;
' 15: 调用Write函数出错。
' 16: 调用Increment函数出错
' 17: 调用Decrment函数出错
' 18: 调用Read函数出错
' 24: 冲突错
' 30: 上一次了送命令时被打断
' 255:串行通信错误
'/************************************************************
Function CheckErr(ByVal st As Integer)
'------------------------------------------------------------
' 制作功能卡:CheckErr(返回号)
'------------------------------------------------------------
Select Case st
Case 1
MsgBox "对不起,没有检测到卡!", vbInformation, "信息提示"
Exit Function
Case 2
MsgBox "对不起,错误的CRC校验和!", vbInformation, "信息提示"
Exit Function
Case 3
MsgBox "对不起,值溢出!", vbInformation, "信息提示"
Exit Function
Case 4
MsgBox "对不起,验证错误!", vbInformation, "信息提示"
Exit Function
Case 5
MsgBox "对不起,错误的校验位!", vbInformation, "信息提示"
Exit Function
Case 6
MsgBox "对不起,通信错误!", vbInformation, "信息提示"
Exit Function
Case 8
MsgBox "对不起,错误的串行码!", vbInformation, "信息提示"
Exit Function
Case 8
MsgBox "对不起,输入参数错误!", vbInformation, "信息提示"
Exit Function
Case 10
MsgBox "对不起,卡没有验证!", vbInformation, "信息提示"
Exit Function
Case 11
MsgBox "对不起,错误数量的位!", vbInformation, "信息提示"
Exit Function
Case 12
MsgBox "对不起,错误数量的字节!", vbInformation, "信息提示"
Exit Function
Case 14
MsgBox "对不起,调用Transfer函数出错!", vbInformation, "信息提示"
Exit Function
Case 15
MsgBox "对不起,调用Write函数出错!", vbInformation, "信息提示"
Exit Function
Case 16
MsgBox "对不起,调用Increment函数出错!", vbInformation, "信息提示"
Exit Function
Case 17
MsgBox "对不起,调用Decrment函数出错!", vbInformation, "信息提示"
Exit Function
Case 18
MsgBox "对不起,调用Read函数出错!", vbInformation, "信息提示"
Exit Function
Case 24
MsgBox "对不起,卡冲突错!", vbInformation, "信息提示"
Exit Function
Case 30
MsgBox "对不起,命令不正确!", vbInformation, "信息提示"
Exit Function
Case 255
MsgBox "对不起,串行通信错误!", vbInformation, "信息提示"
Exit Function
Case Else
MsgBox "对不起,未知错误码!" + CStr(st), vbInformation, "信息提示"
End Select
End Function
'------------------------------------------------------------
'说明: 把字符串转为十六进制数
'参数: Str十六进制字符
'
'返回: 字符串
'------------------------------------------------------------
Function HtoS(ByVal str As String)
Dim i As Integer
Dim StrTem As String
Dim StrTem2 As String
If Len(Trim(str)) > 0 Then
For i = 1 To Len(Trim(str))
If Asc(Mid(Trim(str), i, 1)) <> 32 Then '不为空格时
StrTem2 = Mid(Trim(str), i, 1)
StrTem = StrTem + StrTem2
StrTem2 = ""
End If
Next i
HtoS = StrTem
End If
End Function
这是 窗体代码
*
' * Copyright(c) 2003, 周立功单片机发展有限公司
' * All rights reserved.
' *
' * 文 件: Mur100Fun.bas
' *
' * 摘 要: 本程序主要是演示Mur100 API函数调用方法
' *
' *
' * 创建日期: 2003年02月13日
' *
' *************************************************************************
' */
'*************************************************************************
'* 声明全局变量
'*************************************************************************
Dim st As Byte '接收端口设置状态
Dim mode As Byte '校验 密钥A:0x00,密钥B:0x04
Dim secnr As Byte '分区
Dim psw(5) As Byte '密码数据
Private Sub Command1_Click()
Dim str As String
Dim i As Long
Dim j As Long
'------------------------------------------------------------
' 连机操作
'------------------------------------------------------------
str = HtoS(Text1.Text)
j = 0
For i = 0 To 11
psw(j) = Val("&H" & Mid$(str, i + 1, 2))
j = j + 1
i = i + 1
Next i
st = RC500USB_init()
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_config()
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_load_key(mode, secnr, psw(0))
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Command2_Click()
'------------------------------------------------------------
' 写数值数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
value = Val("&h" + Trim$(Text2))
st = RC500USB_writeval(Val("&H" + Combo1) * 4 + Combo2, value) '写入数值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command3_Click()
'------------------------------------------------------------
' 递增数值
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
value = Val("&h" + Trim$(Text3))
st = RC500USB_value(&HC1, Val("&H" + Combo1) * 4 + Combo2, value, Val("&H" + Combo1) * 4 + Combo2) '写入数值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command4_Click()
'------------------------------------------------------------
' 增加数值
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
value = Val("&h" + Trim$(Text3))
st = RC500USB_value(&HC0, Val("&H" + Combo1) * 4 + Combo2, value, Val("&H" + Combo1) * 4 + Combo2) '写入数值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command5_Click()
'------------------------------------------------------------
' 读取数值数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
' st = RC500USB_halt() '停止当前卡
' If st <> 0 Then
' CheckErr (st)
' Exit Sub
' End If
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_readval(Val("&H" + Combo1) * 4 + Combo2, value) '读取值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(value) '格式化显示读取的数值
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Text4 = StrTem
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command6_Click()
'------------------------------------------------------------
' 写一块数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim buf(15) As Byte '所读到的数据
Dim kh As Long
Dim j As Long
Dim i As Long
Dim size As Byte '容量(是多少K字节)
Dim StrTem As String '临时字符串
StrTem = "" '取数据
StrTem = HtoS(Text5.Text)
j = 0
For i = 0 To 31
buf(j) = Val("&H" & Mid$(StrTem, i + 1, 2))
i = i + 1
j = j + 1
Next i
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo3)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_write(Val("&H" + Combo3) * 4 + Combo4, buf(0)) '写取块数据
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command7_Click()
'------------------------------------------------------------
' 读取一块数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim buf(15) As Byte '所读到的数据
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo5)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_read(Val("&H" + Combo5) * 4 + Combo6, buf(0)) '读取块数据
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = "" '格式化显示
StrTem = Combo5.Text + ":" + Combo6.Text + " "
For i = 0 To 15
If i = 6 Or i = 10 Then
StrTem = StrTem + " "
End If
If Len(Hex(buf(i))) = 1 Then
StrTem = StrTem + " 0" + Hex(buf(i))
Else
StrTem = StrTem + " " + Hex(buf(i))
End If
Next i
List1.AddItem StrTem
List1.ListIndex = List1.ListCount - 1
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command8_Click()
Unload Me
End Sub
Private Sub Form_Load()
'设置下拉列表的值
Dim i As Long
Dim j As Long
Dim StrTem As String
List1.Clear
Combo1.Clear
Combo2.Clear
Combo3.Clear
Combo4.Clear
Combo5.Clear
Combo6.Clear
For i = 0 To 15
StrTem = ""
StrTem = Hex(i)
If Len(StrTem) < 2 Then
StrTem = "0" + StrTem
End If
Combo1.AddItem StrTem
Combo3.AddItem StrTem
Combo5.AddItem StrTem
If i < 4 Then
If i < 3 Then '这里不充许对密码块进行写操作
Combo2.AddItem StrTem
Combo4.AddItem StrTem
End If
Combo6.AddItem StrTem
End If
Next i
mode = 0
Combo1.ListIndex = 0
Combo2.ListIndex = 0
Combo3.ListIndex = 0
Combo4.ListIndex = 0
Combo5.ListIndex = 0
Combo6.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
'退出操作
RC500USB_exit
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 32
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 32
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
另外还有两个 dll ,有兴趣的朋友我可以把他们发给你 ,我的 qq 是 47196976
************************************************************************
' *
' * Copyright(c) 2003, 周立功单片机发展有限公司
' * All rights reserved.
' *
' * 文 件: Mur100Fun.bas
' *
' * 摘 要: 本程序主要是演示Mur100 API函数调用方法
' *
' *
' * 创建日期: 2003年02月13日
' *
' *************************************************************************
' */
'*************************************************************************
'* 声明引用系统API函数
'*************************************************************************
'------------------------------------------------------------
'说明: 挂起当前线程
'参数: dwMilliseconds 挂起时间(毫秒)
'返回: 无
'------------------------------------------------------------
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'*************************************************************************
'* 声明引用 RC500USB.dll API函数
'*************************************************************************
'------------------------------------------------------------
'说明: 发送请求命令(Request),检查在有效范围内是否有卡的存在
'参数: mode:请求类型
' (mode=0:请求天线范围内IDLE状态的卡(HALT状态的除外)
' mode=1: 请求天线范围内的所有卡)、
' tagtype:返回的目标类型
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_request Lib "RC500USB.dll" (ByVal mode As Byte, ByRef tagtype As Byte) As Byte
'------------------------------------------------------------
'说明: 开始防冲突操作
'参数: bcnt:为预选卡所分配的位的个数,通常Bcnt=0、
' snr:返回卡的序号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_anticoll Lib "RC500USB.dll" (ByVal bcnt As Byte, ByRef snr As Long) As Byte
'------------------------------------------------------------
'说明: 开始防冲突操作(是否充许多张卡操作)
'参数: encoll:若为1,则使能多张卡进入天线区;
' (若为0,则不允许多张卡进入,此时返回错误MI_COLLERR)、
' bcnt:为预选卡所分配的位的个数,通常Bcnt=0、
' snr:返回卡的序号
'返回: 0 发送数据成功、非0发送数据失败
'------------------------------------------------------------
Declare Function RC500USB_anticoll2 Lib "RC500USB.dll" (ByVal encoll As Byte, ByVal bcnt As Byte, ByRef snr As Byte) As Byte
'------------------------------------------------------------
'说明: 选择某一个序号的mf卡
'参数: snr:卡的序号
' size:返回卡的容量
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_select Lib "RC500USB.dll" (ByVal snr As Long, ByRef size As Byte) As Byte
'------------------------------------------------------------
'说明: 将RC500中的密匙与卡中的密匙进行验证(每个扇区密码相同)
' (在进行对卡片的读写操作之前,必须成功执行此指令。
' 系统初始化时,主控设备将把每个扇区的密码加载到读卡器中。
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04、
' secnr:要验证的卡扇区号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_authentication Lib "RC500USB.dll" (ByVal mode As Byte, ByVal secnr As Long) As Byte
'------------------------------------------------------------
'说明: 将RC500中的密匙与卡中的扇区密匙进行验证。
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04
' secnr:要验证的卡扇区号
' keynr:用于证实的密匙区号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_authentication2 Lib "RC500USB.dll" (ByVal mode As Byte, ByVal secnr As Byte, ByVal keynr As Byte) As Byte
'------------------------------------------------------------
'说明: 密钥验证(在对卡进行读、写、加、减等操作前)
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04
' key:存储密钥缓冲区
' secnr:要验证的卡扇区号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_authkey Lib "RC500USB.dll" (ByVal mode As Byte, ByRef key As Byte, ByVal secnr As Byte) As Byte
'------------------------------------------------------------
'说明: 使被选择的卡产生一个暂停(即使之处于Halt模式)
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_halt Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 读取卡的一个块的数据
'参数: addr:块号(0x00--0x3f)
' data:块数据,长度16个字节
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_read Lib "RC500USB.dll" (ByVal addr As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 对指定的块进行整块写操作。
'参数: addr:块号(0x00--0x3f)
' data:块数据,长度16个字节
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_write Lib "RC500USB.dll" (ByVal addr As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 往一个块中写入数值
'参数: addr: 块号(0x00--0x3f)
' value: 要写入的值
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_writeval Lib "RC500USB.dll" (ByVal addr As Byte, ByVal value As Long) As Byte
'------------------------------------------------------------
'说明: 读出一个块中的数值
'参数: addr: 块号(0x00--0x3f)
' value: 存储要读出的值
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_readval Lib "RC500USB.dll" (ByVal addr As Byte, ByRef value As Long) As Byte
'------------------------------------------------------------
'说明: 对一个块进行值操作,并把结果存到trans_addr
'参数: mode:模式(1字节,加C1H,减C0H,复制C2H)
' addr:块号(0x00--0x3f)
' value:要操作的值
' trans_addr:传输块地址
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_value Lib "RC500USB.dll" (ByVal mode As Byte, ByVal addr As Byte, ByRef value As Long, ByVal trans_addr As Byte) As Byte
'------------------------------------------------------------
'说明: RC500中的密匙与卡中的密匙进行验证(全部密匙相同)
'参数: mode:密钥类型,密钥A:0x00,密钥B:0x04
' secnr:要载入的读卡器中的密钥区号
' key:密码,长度6个字节
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_load_key Lib "RC500USB.dll" (ByVal mode As Byte, ByVal secnr As Byte, ByRef key As Byte) As Byte
'------------------------------------------------------------
'说明: 使射频电路关闭所规定的时间
' (若msec=0,射频电路部分将一直处于关闭状态,
' 一直到下一个Request命令到来。
' 关闭射频能使天线内的所有卡复位)
'参数: msec:射频电路关闭时间(以毫秒为单位)
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_reset Lib "RC500USB.dll" (ByVal msec As Byte) As Byte
'------------------------------------------------------------
'说明: RC500的复位管脚置为高电平,关闭RC500,使之电流最小。
' 若要重新启动则需调用Config()
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_close Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 系统配制(模块每次上电复位之后,都必须首先调用此函数
' 对模块进行初始化,才能进行进一步的操作。)
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_config Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 返回一个包含有RC500的产品类型标识和序列号的数组。
'参数: info: info[0]-info[4]为RC500的产品类型标识,依次为0x30,
' 0x88,0xf8,0x00,0xXX,info[5]-info[8]为RC500的序列号
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_get_info Lib "RC500USB.dll" (ByRef info As Byte) As Byte
'------------------------------------------------------------
'说明: 此函数设置读卡器中的控制位为高电平。
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_set_control_bit Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 清除MIFARE读卡器中的控制位
'参数: 无
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_clr_control_bit Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 此函数输出一驱动信号可驱动蜂鸣器和绿色发光管,
' 持续时间、间隙时间和重复次数可调
'参数: contrl: 控制字,如下表相应位为1时该器件动作。
' contrl^1为绿灯,contrl^0为蜂鸣器
' opentm: 低电平持续时间,取值(0-255),10ms的分辨率
' closetm: 高电平间隙时间,取值(0-255),10ms的分辨率
' repcnt: 重复次数
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_buzzer Lib "RC500USB.dll" (ByVal contrl As Byte, ByVal opentm As Byte, ByVal closetm As Byte, ByVal repcnt As Byte) As Byte
'------------------------------------------------------------
'说明: 此函数将RC500内EEPROM的数据读出。
'参数: addr: 被读RC500内EEPROM首址,必须小于0x80
' length: 被读数据长度
' data: 读出数据缓冲区首址
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_read_E2 Lib "RC500USB.dll" (ByVal addr As Byte, ByVal length As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 将数据写入RC500内EEPROM中
'参数: addr: RC500内EEPROM的写入首址,取值范围(0x30-0x7E)
' length: 被写数据长度
' data: 写入数据缓冲区首址
'返回: 0 操作成功、非0发操作失败
'------------------------------------------------------------
Declare Function RC500USB_write_E2 Lib "RC500USB.dll" (ByVal addr As Byte, ByVal length As Byte, ByRef data As Byte) As Byte
'------------------------------------------------------------
'说明: 初始化MUR-100读卡器
'参数: 无
'返回: 无
'------------------------------------------------------------
Declare Function RC500USB_init Lib "RC500USB.dll" () As Byte
'------------------------------------------------------------
'说明: 关闭MUR-100读卡器
'参数: 无
'返回: 无
'------------------------------------------------------------
Declare Sub RC500USB_exit Lib "RC500USB.dll" ()
'/************************************************************
' 函数返回值定义:
' 0: 操作成功;
' 1: 在有效区域内没有卡;(Check Write出错)
' 2: 从卡中接收到了错误的CRC校验和;(Check Write:写出错(比较出错))
' 3: 值溢出;
' 4: 不能验证;
' 5: 从卡中接收到了错误的校验位;
' 6: 通信错误;
' 8: 在防冲突时读到了错误的串行码;
' 10: 卡没有验证;
' 11: 从卡中接收到了错误数量的位;
' 12: 从卡中接收了错误数量的字节;
' 14: 调用Transfer函数出错;
' 15: 调用Write函数出错。
' 16: 调用Increment函数出错
' 17: 调用Decrment函数出错
' 18: 调用Read函数出错
' 24: 冲突错
' 30: 上一次了送命令时被打断
' 255:串行通信错误
'/************************************************************
Function CheckErr(ByVal st As Integer)
'------------------------------------------------------------
' 制作功能卡:CheckErr(返回号)
'------------------------------------------------------------
Select Case st
Case 1
MsgBox "对不起,没有检测到卡!", vbInformation, "信息提示"
Exit Function
Case 2
MsgBox "对不起,错误的CRC校验和!", vbInformation, "信息提示"
Exit Function
Case 3
MsgBox "对不起,值溢出!", vbInformation, "信息提示"
Exit Function
Case 4
MsgBox "对不起,验证错误!", vbInformation, "信息提示"
Exit Function
Case 5
MsgBox "对不起,错误的校验位!", vbInformation, "信息提示"
Exit Function
Case 6
MsgBox "对不起,通信错误!", vbInformation, "信息提示"
Exit Function
Case 8
MsgBox "对不起,错误的串行码!", vbInformation, "信息提示"
Exit Function
Case 8
MsgBox "对不起,输入参数错误!", vbInformation, "信息提示"
Exit Function
Case 10
MsgBox "对不起,卡没有验证!", vbInformation, "信息提示"
Exit Function
Case 11
MsgBox "对不起,错误数量的位!", vbInformation, "信息提示"
Exit Function
Case 12
MsgBox "对不起,错误数量的字节!", vbInformation, "信息提示"
Exit Function
Case 14
MsgBox "对不起,调用Transfer函数出错!", vbInformation, "信息提示"
Exit Function
Case 15
MsgBox "对不起,调用Write函数出错!", vbInformation, "信息提示"
Exit Function
Case 16
MsgBox "对不起,调用Increment函数出错!", vbInformation, "信息提示"
Exit Function
Case 17
MsgBox "对不起,调用Decrment函数出错!", vbInformation, "信息提示"
Exit Function
Case 18
MsgBox "对不起,调用Read函数出错!", vbInformation, "信息提示"
Exit Function
Case 24
MsgBox "对不起,卡冲突错!", vbInformation, "信息提示"
Exit Function
Case 30
MsgBox "对不起,命令不正确!", vbInformation, "信息提示"
Exit Function
Case 255
MsgBox "对不起,串行通信错误!", vbInformation, "信息提示"
Exit Function
Case Else
MsgBox "对不起,未知错误码!" + CStr(st), vbInformation, "信息提示"
End Select
End Function
'------------------------------------------------------------
'说明: 把字符串转为十六进制数
'参数: Str十六进制字符
'
'返回: 字符串
'------------------------------------------------------------
Function HtoS(ByVal str As String)
Dim i As Integer
Dim StrTem As String
Dim StrTem2 As String
If Len(Trim(str)) > 0 Then
For i = 1 To Len(Trim(str))
If Asc(Mid(Trim(str), i, 1)) <> 32 Then '不为空格时
StrTem2 = Mid(Trim(str), i, 1)
StrTem = StrTem + StrTem2
StrTem2 = ""
End If
Next i
HtoS = StrTem
End If
End Function
这是 窗体代码
*
' * Copyright(c) 2003, 周立功单片机发展有限公司
' * All rights reserved.
' *
' * 文 件: Mur100Fun.bas
' *
' * 摘 要: 本程序主要是演示Mur100 API函数调用方法
' *
' *
' * 创建日期: 2003年02月13日
' *
' *************************************************************************
' */
'*************************************************************************
'* 声明全局变量
'*************************************************************************
Dim st As Byte '接收端口设置状态
Dim mode As Byte '校验 密钥A:0x00,密钥B:0x04
Dim secnr As Byte '分区
Dim psw(5) As Byte '密码数据
Private Sub Command1_Click()
Dim str As String
Dim i As Long
Dim j As Long
'------------------------------------------------------------
' 连机操作
'------------------------------------------------------------
str = HtoS(Text1.Text)
j = 0
For i = 0 To 11
psw(j) = Val("&H" & Mid$(str, i + 1, 2))
j = j + 1
i = i + 1
Next i
st = RC500USB_init()
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_config()
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_load_key(mode, secnr, psw(0))
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Command2_Click()
'------------------------------------------------------------
' 写数值数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
value = Val("&h" + Trim$(Text2))
st = RC500USB_writeval(Val("&H" + Combo1) * 4 + Combo2, value) '写入数值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command3_Click()
'------------------------------------------------------------
' 递增数值
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
value = Val("&h" + Trim$(Text3))
st = RC500USB_value(&HC1, Val("&H" + Combo1) * 4 + Combo2, value, Val("&H" + Combo1) * 4 + Combo2) '写入数值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command4_Click()
'------------------------------------------------------------
' 增加数值
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
value = Val("&h" + Trim$(Text3))
st = RC500USB_value(&HC0, Val("&H" + Combo1) * 4 + Combo2, value, Val("&H" + Combo1) * 4 + Combo2) '写入数值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command5_Click()
'------------------------------------------------------------
' 读取数值数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim kh As Long
Dim size As Byte '容量(是多少节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
' st = RC500USB_halt() '停止当前卡
' If st <> 0 Then
' CheckErr (st)
' Exit Sub
' End If
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo1)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_readval(Val("&H" + Combo1) * 4 + Combo2, value) '读取值
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(value) '格式化显示读取的数值
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Text4 = StrTem
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command6_Click()
'------------------------------------------------------------
' 写一块数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim buf(15) As Byte '所读到的数据
Dim kh As Long
Dim j As Long
Dim i As Long
Dim size As Byte '容量(是多少K字节)
Dim StrTem As String '临时字符串
StrTem = "" '取数据
StrTem = HtoS(Text5.Text)
j = 0
For i = 0 To 31
buf(j) = Val("&H" & Mid$(StrTem, i + 1, 2))
i = i + 1
j = j + 1
Next i
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo3)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_write(Val("&H" + Combo3) * 4 + Combo4, buf(0)) '写取块数据
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command7_Click()
'------------------------------------------------------------
' 读取一块数据
'------------------------------------------------------------
Dim Btype(1) As Byte
Dim buf(15) As Byte '所读到的数据
Dim kh As Long
Dim size As Byte '容量(是多少K字节)
Dim value As Long '读出的值勤
Dim StrTem As String '临时字符串
Dim i As Long
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
st = RC500USB_request(0, Btype(0)) '发命令
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End If
st = RC500USB_anticoll(0, kh) '开始防冲突
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = ""
StrTem = Hex(kh) '格式化显示读取卡号
For i = Len(StrTem) To 7
StrTem = "0" + StrTem
Next i
Lkh = StrTem '显示卡号
st = RC500USB_select(kh, size) '选择卡
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_authentication(mode, Val("&H" + Combo5)) '密码验证
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
st = RC500USB_read(Val("&H" + Combo5) * 4 + Combo6, buf(0)) '读取块数据
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
StrTem = "" '格式化显示
StrTem = Combo5.Text + ":" + Combo6.Text + " "
For i = 0 To 15
If i = 6 Or i = 10 Then
StrTem = StrTem + " "
End If
If Len(Hex(buf(i))) = 1 Then
StrTem = StrTem + " 0" + Hex(buf(i))
Else
StrTem = StrTem + " " + Hex(buf(i))
End If
Next i
List1.AddItem StrTem
List1.ListIndex = List1.ListCount - 1
st = RC500USB_buzzer(3, 50, 20, 1) '发声明(11则为发声及红灯亮)
If st <> 0 Then
CheckErr (st)
Exit Sub
End If
End Sub
Private Sub Command8_Click()
Unload Me
End Sub
Private Sub Form_Load()
'设置下拉列表的值
Dim i As Long
Dim j As Long
Dim StrTem As String
List1.Clear
Combo1.Clear
Combo2.Clear
Combo3.Clear
Combo4.Clear
Combo5.Clear
Combo6.Clear
For i = 0 To 15
StrTem = ""
StrTem = Hex(i)
If Len(StrTem) < 2 Then
StrTem = "0" + StrTem
End If
Combo1.AddItem StrTem
Combo3.AddItem StrTem
Combo5.AddItem StrTem
If i < 4 Then
If i < 3 Then '这里不充许对密码块进行写操作
Combo2.AddItem StrTem
Combo4.AddItem StrTem
End If
Combo6.AddItem StrTem
End If
Next i
mode = 0
Combo1.ListIndex = 0
Combo2.ListIndex = 0
Combo3.ListIndex = 0
Combo4.ListIndex = 0
Combo5.ListIndex = 0
Combo6.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
'退出操作
RC500USB_exit
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 32
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判断输入是否为有效字符符(十六进制数)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 32
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
另外还有两个 dll ,有兴趣的朋友我可以把他们发给你 ,我的 qq 是 47196976