我现在手头上有一款读卡器,卡的型号是SLE4442,现在就想将卡号写到其芯片里面,但却怎么也写不进去!不知哪位大哥做过类似的开发,望多多赐教!附源程序(里面所有的函数都是调用一个.dll文件,在此没有给出):
Dim Data1 As String * 16
Dim Data2 As String * 16
Dim databuff1(7) As Byte
Dim databuff2(7) As Byte
Dim offset As Integer
Dim length As Integer
Dim status As Integer
Dim password(2) As Byte
Dim proval As String * 8
Dim counter As Integer
Dim oldpass As String
Dim ptrdest(16) As Byte
Dim ptrsource As String * 16
Private Sub Command6_Click()'****************************测4442卡****************************
st = chk_4442(icdev)
If st < 0 Then
    List1.AddItem ("chk card error")
    Exit Sub
Else
    List1.AddItem ("chk card ok")
End If'******************************校验密码****************************
'password(0) = &HB6
'password(1) = &H23
'password(2) = &H7
oldpass = "b62307" 
st = asc_hex(oldpass, password(0), 3) '说明:将ASCII码转换为十六进制数据If st < 0 Then
    List1.AddItem ("asc_hex error")
    Exit Sub
Else
    List1.AddItem ("asc_hex ok")
End Ifst = csc_4442(icdev, 3, password(0))
If st < 0 Then
    List1.AddItem ("csc error")
    Exit Sub
Else
    List1.AddItem ("csc  ok")
End If'***********************读出卡密码***************************
'int rsc_4442(int icdev, int len, unsigned char* p_string)
'说明:读出卡密码 
'调用:icdev: 通讯设备标识符 
'len: 密码个数,其值为3
'p_string: 存放密码地址指针
'返回:<>0 错误
'=0 正确
'**************************************************************
st = rsc_4442(icdev, 3, password(0))
 
If st < 0 Then
    List1.AddItem ("rsc error")
    Exit Sub
Else
    List1.AddItem ("rsc  ok")
End If
'**********************改写密码******************************
'int wsc_4442(int icdev, int len,unsigned char* p_string)
'说明:改写卡密码
'调用:icdev: 通讯设备标识符 
'len: 密码个数,其值为3
'p_string: 新密码地址指针
'返回: <0 错误
'=0 正确
'**********************************************************
password(0) = &HB6
password(1) = &H23
password(2) = &H7
'st = wsc_4442(icdev, 3, password(0))
If st < 0 Then
    List1.AddItem ("wsc error")
Else
    List1.AddItem ("wsc ok")
End If
'*********************读出密码错误计数器**********************
'int rsct_4442(int icdev, int* counter)
'说明:读出密码错误计数器值
'调用:icdev: 通讯设备标识符
'counter: 密码错误记数值存放指针
'返回:<0 错误
'>=0 正确
'*************************************************************
st = rsct_4442(icdev, counter)
If st < 0 Then
    List1.AddItem ("rsct  error")
    Exit Sub
Else
    List1.AddItem ("rsct Ok")
    List1.AddItem (Str(counter))
End If'**********************读写卡 *******************************
'我的问题就出在这里,每次程序运行Data1就是写不进去,程序执行
'swr_4442(icdev, offset, length, Data1)后就返回一个写失败'int swr_4442(int icdev, int offset, int len, unsigned char *w_string)
'说明: 向指定地址写数据
'调用: icdev: 通讯设备标识符 
'offset: 偏移地址,其值范围0~255
'len: 字符串长度,其值范围1~256
'w_string: 写入数据
'返回:<0 错误
'=0 正确'int srd_4442(int icdev, int offset, int len, unsigned char* r_string )
'说明: 从指定地址读数据
'************************************************************
offset = 40
length = 10
Data1 = "1234567890"
st = swr_4442(icdev, offset, length, Data1)
If st < 0 Then
  List1.AddItem ("write error")
  Exit Sub
Else
  List1.AddItem ("write OK")
End Ifst = srd_4442(icdev, offset, length, Data2)
If st < 0 Then
  List1.AddItem ("read error")
  Exit Sub
Else
  List1.AddItem ("read OK")
  List1.AddItem (Data2)
  List1.AddItem ("liudengfeng")
End If'**********************读写保护区******************************
'int pwr_4442(int icdev, int offset, int len, unsigned char* w_string) 
'说明: 保护指定地址的数据 
'调用: icdev: 通讯设备标识符 
'offset: 偏移地址,其值范围0~31
'len: 字符串长度,其值范围1~32
'w_string: 保护数据,必须和卡中已存在的数据一致
'返回: <0 错误
'=0 正确'int prd_4442(int icdev,int len,unsigned char *r_string) 
'说明:读保护位
'****************************************************************
proval = "6"
'st = pwr_4442(icdev, 30, 1, proval)
If st < 0 Then
  List1.AddItem ("pwr error")
  Exit Sub
Else
  List1.AddItem ("pwr OK")
  List1.AddItem (proval)
End Ifst = prd_4442(icdev, 4, proval)
If st < 0 Then
  List1.AddItem ("prd error")
  Exit Sub
Else
  List1.AddItem ("prd OK")
End If
'*******************十六进制读写******************************offset = 56
length = 8
Data1 = "abcdef0123456789"
st = asc_hex(Data1, databuff1(0), 8)
If st < 0 Then
    List1.AddItem ("asc_hex error")
Else
    List1.AddItem ("asc_hex ok")
End If
    
st = swr_4442_hex(icdev, offset, length, databuff1(0))
If st < 0 Then
  List1.AddItem ("write error")
  Exit Sub
Else
  List1.AddItem ("write ok")
End If
st = srd_4442_hex(icdev, offset, length, databuff2(0))
If st < 0 Then
  List1.AddItem ("read error")
  Exit Sub
Else
  st = hex_asc(databuff2(0), Data2, 8)
  List1.AddItem ("read OK")
  List1.AddItem (Data2)
End If'****************************DES算法********************
st = ic_encrypt("12345678", "明华技术开发中心", 16, ptrdest(0))
If st < 0 Then
    List1.AddItem ("ic_encrypt error")
    Exit Sub
Else
    List1.AddItem ("ic_encrypt ok")
End Ifst = ic_decrypt("12345678", ptrdest(0), 16, ptrsource)
If st < 0 Then
    List1.AddItem ("ic_decrypt error")
    Exit Sub
Else
    List1.AddItem ("ic_decrypt ok")
    List1.AddItem (ptrsource)
End If
'**********************************************************
End SubPrivate Sub Form_Load()
icdev = auto_init(0, 9600)
If icdev < 0 Then
    List1.AddItem ("Init error!")
    Exit Sub
Else
    List1.AddItem ("Init OK")
End If
  
st = get_status(icdev, status)
If st < 0 Then
  List1.AddItem ("Status error")
  Exit Sub
Else
  List1.AddItem ("Status ok")
End IfEnd SubPrivate Sub Form_Unload(Cancel As Integer)
 st = ic_exit(icdev)
End Sub