sample.frm 11.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "32位动态库调用示例 "
   ClientHeight    =   7170
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6465
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   9
      Charset         =   134
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   7170
   ScaleWidth      =   6465
   StartUpPosition =   2  'CenterScreen
   WhatsThisHelp   =   -1  'True
   Begin VB.CommandButton Command7 
      Caption         =   "修改密码"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   7
      Top             =   2640
      Width           =   1455
   End
   Begin VB.CommandButton Command6 
      Caption         =   "设备函数"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   4560
      TabIndex        =   6
      Top             =   3240
      Width           =   1455
   End
   Begin VB.CommandButton Command5 
      Caption         =   "SAM卡操作"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   5
      Top             =   3960
      Width           =   1455
   End
   Begin VB.CommandButton Command4 
      Caption         =   "退出"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   4
      Top             =   6000
      Width           =   1455
   End
   Begin VB.CommandButton Command3 
      Caption         =   "卡函数"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   3
      Top             =   1920
      Width           =   1455
   End
   Begin VB.CommandButton Command2 
      Caption         =   "装载密码"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   2
      Top             =   1200
      Width           =   1455
   End
   Begin VB.ListBox List1 
      BackColor       =   &H00FFFFC0&
      Height          =   6360
      Left            =   360
      TabIndex        =   1
      Top             =   360
      Width           =   3615
   End
   Begin VB.CommandButton Command1 
      Caption         =   "初始化"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   420
      Left            =   4560
      TabIndex        =   0
      Top             =   480
      Width           =   1455
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim hexkey As String * 12
Dim snr, tagtype As Long
Dim data32 As String * 32
Dim databuff32 As String * 32
Dim alldata As String * 3000
Dim rvalue As Long
Dim wvalue As Long
Dim cardmode As Integer
Dim loadmode As Integer
Dim sector As Integer
Dim displaydata(8) As Byte
Dim address As Integer  '写16字节数据 地址
Dim size As Byte
Dim block As Integer  '值操作 地址

Private Sub Command1_Click()
If icdev < 0 Then
  icdev = dc_init(100, 115200)   '这里初始化串口一,波特率为115200
End If
If icdev < 0 Then
      List1.AddItem ("调用 dc_init()函数出错!")
     Exit Sub
End If
List1.AddItem ("调用 dc_init()函数成功!")
End Sub


Private Sub Command2_Click()
hexkey = "ffffffffffff"
st = dc_load_key_hex(ByVal icdev, 0, 1, ByVal hexkey)  '装载1扇区的密码到读写器,这和后面要
If st <> 0 Then                                        '校验1扇区的密码是相对应的
      List1.AddItem ("调用 dc_Load_key_hex()函数出错!")
      Exit Sub
End If
List1.AddItem ("调用 dc_Load_key_hex()函数成功!")
End Sub

Private Sub Command3_Click()
cardmode = 0
sector = 1
address = 4
block = 5


st = dc_card(ByVal icdev, cardmode, snr)   '寻卡函数 cardmode=1 可对卡连续操作,为0时如果执行了HALT操作
If st <> 0 And st <> 1 Then                '则卡必须离开感应区后才能再次操作
      List1.AddItem ("调用 dc_card()函数出错,请检查设备连接是否正常")
      Exit Sub
End If
If st = 1 Then
       List1.AddItem ("没有找到卡片")
      Exit Sub
End If
List1.AddItem ("感应区内发现了卡片")
List1.AddItem Str(snr)

DoEvents


st = dc_authentication(ByVal icdev, 0, sector)  '核对卡密码
If st <> 0 Then
      List1.AddItem "调用 dc_authentication()函数出错!"
      Exit Sub
End If
List1.AddItem "调用 dc_authentication()函数成功!"
DoEvents

st = dc_read_hex(ByVal icdev, address, databuff32)   '读卡内的数据
If st <> 0 Then
     List1.AddItem "调用 dc_read_hex函数出错"
     Exit Sub

End If
List1.AddItem "调用 dc_read_hex函数成功"
List1.AddItem databuff32
DoEvents

data32 = "1234567890abcdef1234567890abcdef"
st = dc_write_hex(ByVal icdev, address, ByVal data32)  '数据写入卡片中
If st <> 0 Then
      List1.AddItem "调用 dc_write_hex()函数出错!"
      Exit Sub
End If

List1.AddItem "调用 dc_write_hex()函数成功!"
DoEvents

''data32 = "1234567890abcdef"
data32 = "1234567890abcdef1234567890abcdef"

st = dc_check_writehex(icdev, snr, 0, address, data32) ''检测指定数据是否与卡中数据一致
If st <> 0 Then
      List1.AddItem "调用 dc_check_writehex()函数出错!"
      Exit Sub
End If
List1.AddItem "调用 dc_check_writehex()函数成功!"
DoEvents





'以下是把扇区的数据块当作一个值块来操作
wvalue = 10000
st = dc_initval(ByVal icdev, block, ByVal wvalue)  '初始化值
If st <> 0 Then
      List1.AddItem "调用 dc_initval()函数出错"
      Exit Sub
End If
List1.AddItem "调用 dc_initval()函数成功"
DoEvents

 


st = dc_increment(ByVal icdev, block, 888)    '加值
If st <> 0 Then
      List1.AddItem "调用 dc_increment()函数出错"
      Exit Sub
End If
List1.AddItem "调用 dc_increment()函数成功"
DoEvents

st = dc_decrement(ByVal icdev, block, 88)    '减值
If st <> 0 Then
      List1.AddItem "调用 dc_decrement()函数出错"
      Exit Sub
End If
List1.AddItem "调用 dc_decrement()函数成功"
DoEvents

st = dc_readval(ByVal icdev, block, rvalue)    '读值
If st <> 0 Then
      List1.AddItem "调用 dc_readval()函数出错"
      Exit Sub
End If
List1.AddItem "调用 dc_readval()函数成功"
List1.AddItem rvalue
DoEvents

'
st = dc_halt(ByVal icdev)                    '该函数执行后,如果卡不离开感应区不能再次操作
If st <> 0 Then
      List1.AddItem "调用 dc_halt()函数出错"
      Exit Sub
End If
List1.AddItem "调用 dc_halt()函数成功"

DoEvents

List1.AddItem "读写设备测试通过!"

End Sub

Private Sub Command4_Click()
quit
Unload Me
End Sub

Private Sub Command5_Click()
Dim data1 As String * 1024
Dim data2 As String * 1024
Dim slen As Byte
Dim rlen As Byte

st = dc_cpureset_hex(ByVal icdev, rlen, data1)
If st <> 0 Then
      List1.AddItem ("调用 dc_cpureset函数出错")
      Exit Sub
End If
List1.AddItem ("调用 dc_cpureset()函数成功")
List1.AddItem data1


slen = 5
data1 = "0084000008"
st = dc_cpuapdu_hex(icdev, ByVal slen, ByVal data1, rlen, ByVal data2)
If st <> 0 Then
      List1.AddItem ("调用 dc_cpuapdu函数出错")
      Exit Sub
End If
List1.AddItem ("调用 dc_cpuapdu()函数成功")
List1.AddItem data2

st = dc_cpudown(icdev)
If st <> 0 Then
      List1.AddItem ("调用 dc_cpudown函数出错")
      Exit Sub
End If
List1.AddItem ("调用 dc_cpudown函数成功")


End Sub

Private Sub Command6_Click()
Dim dispdata(8) As Byte
Dim ctt(7) As Byte
dispdata(0) = &H44
dispdata(1) = &H46
dispdata(2) = &H5
dispdata(3) = &H5
dispdata(4) = &H85
dispdata(5) = &H5
dispdata(6) = &H5F

st = dc_gettime(icdev, ctt(0))
If st <> 0 Then
      List1.AddItem "Gettime Error"
      Exit Sub
End If
List1.AddItem "gettime ok"



ctt(0) = &H4
ctt(1) = &H2
ctt(2) = &H5
ctt(3) = &H15
ctt(4) = &H4
ctt(5) = &H3
ctt(6) = &H2
st = dc_settime(icdev, ctt(0))
If st <> 0 Then
    List1.AddItem "settime Error"
    Exit Sub
End If
List1.AddItem "settime ok"
Exit Sub

    


st = dc_high_disp(icdev, 1, 5, dispdata(0))


st = dc_beep(ByVal icdev, 10)
If st <> 0 Then
      List1.AddItem ("调用 dc_beep()函数出错")
      Exit Sub
End If
List1.AddItem ("调用 dc_beep()函数成功")
DoEvents


data32 = "1122334455"
st = dc_swr_eepromhex(ByVal icdev, 100, 5, data32)
If st <> 0 Then
      List1.AddItem ("调用 dc_swr_eepromhex()函数出错")
      Exit Sub
End If
List1.AddItem ("调用 dc_swr_eepromhex()函数成功")
DoEvents

st = dc_srd_eepromhex(ByVal icdev, 100, 5, databuff32)
If st <> 0 Then
      List1.AddItem ("调用 dc_srd_eepromhex()函数出错")
      Exit Sub
End If
List1.AddItem ("调用 dc_srd_eepromhex()函数成功")
DoEvents




st = dc_disp_str(ByVal icdev, "a.b.c.d.e.F.12")
If st <> 0 Then
      List1.AddItem ("调用 dc_disp_str()函数出错")
      Exit Sub
End If
List1.AddItem ("调用 dc_disp_str()函数成功")
DoEvents
End Sub

Private Sub Command7_Click()
Dim akey(6) As Byte
Dim bkey(6) As Byte
'其实修改密码的操作就是用dc_write函数来写每个扇区的密码块,dc_changeb3是封装了dc_write操作
' dc_changeb3 (ByVal adr As Long, ByVal secer As Integer, ByRef KeyA As Byte, ByVal B0 As Integer, ByVal B1 As Integer, ByVal B2 As Integer, ByVal B3 As Integer, ByVal Bk As Integer, ByRef KeyB As Byte) As Integer

sector = 1
cardmode = 1
st = 0
st = dc_card(ByVal icdev, cardmode, snr)
If st <> 0 Then
      List1.AddItem "调用 dc_card()函数出错!。请退出"
      Exit Sub
End If

st = dc_authentication(ByVal icdev, 0, sector)
If st <> 0 Then
      List1.AddItem "调用 dc_authentication()函数出错!请退出。"
      Exit Sub
End If
 

'修改密码和控制位

akey(0) = &HFF 'A0
akey(1) = &HFF 'A1
akey(2) = &HFF 'A2
akey(3) = &HFF 'A3
akey(4) = &HFF 'A4
akey(5) = &HFF 'A5

bkey(0) = &HFF 'B0
bkey(1) = &HFF 'B1
bkey(2) = &HFF 'B2
bkey(3) = &HFF 'B3
bkey(4) = &HFF 'B4
bkey(5) = &HFF 'B5

'下列控制位参数值保证与原密码和控制位一致,一般建议不要改参数3,4,5,6,7
st = dc_changeb3(ByVal icdev, sector, akey(0), 0, 0, 0, 1, 0, bkey(0))
If st <> 0 Then
    List1.AddItem "调用 dc_changeb3()函数出错!请退出。"
    Exit Sub
End If
List1.AddItem "修改密码成功!!!"
End Sub



Private Sub Form_Load()

icdev = -1
End Sub

Private Sub Form_Unload(Cancel As Integer)
quit
End Sub