Foxtable(狐表)用户栏目专家坐堂 → [求助]还是关于读卡写卡的问题求助!


  共有9576人关注过本帖树形打印复制链接

主题:[求助]还是关于读卡写卡的问题求助!

帅哥哟,离线,有人找我吗?
狐狸爸爸
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/4/1 16:35:00 [显示全部帖子]

Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.Text
Imports System.Runtime.InteropServices
''' <summary>
''' DUKa 的摘要说明
''' </summary>
Public Class DUKa
    '
    ' TODO: 在此处添加构造函数逻辑
    '
    Public Sub New()
    End Sub
#Region "对USB接口的使用(PHILIPH卡)"
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_init(ByVal port As Int32, ByVal baud As Long) As Integer
    End Function
    '初试化
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_exit(ByVal icdev As Integer) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_reset(ByVal icdev As Integer, ByVal sec As UInteger) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_request(ByVal icdev As Integer, ByVal _Mode As Char, ByRef TagType As UInteger) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_card(ByVal icdev As Integer, ByVal _Mode As Char, ByRef Snr As ULong) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_halt(ByVal icdev As Integer) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_anticoll(ByVal icdev As Integer, ByVal _Bcnt As Char, ByRef IcCardNo As ULong) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_beep(ByVal icdev As Integer, ByVal _Msec As UInteger) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_authentication(ByVal icdev As Integer, ByVal _Mode As Integer, ByVal _SecNr As Integer) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_load_key(ByVal icdev As Integer, ByVal mode As Integer, ByVal secnr As Integer, <[In]()> ByVal nkey As Byte()) As Short
    End Function
    '密码装载到读写模块中
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_load_key_hex(ByVal icdev As Integer, ByVal mode As Integer, ByVal secnr As Integer, ByVal nkey As String) As Short
    End Function
    '密码装载到读写模块中
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_write(ByVal icdev As Integer, ByVal adr As Integer, <[In]()> ByVal sdata As Byte()) As Short
    End Function
    '向卡中写入数据
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_write(ByVal icdev As Integer, ByVal adr As Integer, <[In]()> ByVal sdata As String) As Short
    End Function
    '向卡中写入数据
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_write_hex(ByVal icdev As Integer, ByVal adr As Integer, <[In]()> ByVal sdata As String) As Short
    End Function
    '向卡中写入数据(转换为16进制)
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_read(ByVal icdev As Integer, ByVal adr As Integer, <Out()> ByVal sdata As Byte()) As Short
    End Function
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_read(ByVal icdev As Integer, ByVal adr As Integer, <MarshalAs(UnmanagedType.LPStr)> ByVal sdata As StringBuilder) As Short
    End Function
    '从卡中读数据
    <DllImport("dcrf32.dll")> _
    Public Shared Function dc_read_hex(ByVal icdev As Integer, ByVal adr As Integer, <MarshalAs(UnmanagedType.LPStr)> ByVal sdata As StringBuilder) As Short
    End Function
    '从卡中读数据(转换为16进制)
    <DllImport("dcrf32.dll")> _
    Public Shared Function a_hex(ByVal oldValue As String, ByRef newValue As String, ByVal len As Int16) As Integer
    End Function
    '普通字符转换成十六进制字符
    <DllImport("dcrf32.dll")> _
    Public Shared Sub hex_a(ByRef oldValue As String, ByRef newValue As String, ByVal len As Integer)
    End Sub
    '十六进制字符转换成普通字符
#End Region
    Public Shared Function WriteIn(ByVal str As String) As Boolean
        Dim _icdev As Int32 = -1
        Try
            If _icdev < 0 Then
                _icdev = dc_init(100, 115200)
            End If
            Dim st As Integer
            '1.初始化
            If _icdev > 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            '蜂鸣
            st = dc_beep(_icdev, 10)
            If st = 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            Dim icCardNo As ULong = 0
            Dim tt As Char = ChrW(0)
            Dim ss As UInteger = 0
            st = dc_reset(_icdev, ss)
            st = dc_card(_icdev, tt, icCardNo)
            If icCardNo <> 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            Dim hexkey As Byte() = New Byte(5) {&HFF, &HFF, &HFF, &HFF, &HFF, &HFF}

            st = dc_load_key(_icdev, 0, 1, hexkey)
            '核对密码
            Dim sector As Integer = 1
            st = dc_authentication(_icdev, 0, sector)
            If st = 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            Dim address As Integer = 1
            Dim data32 As Byte()
            data32 = New Byte(15) {&H6A, &HC2, &H92, &HFA, &HA1, &H31, _
             &H5B, &H4D, &H6A, &HC2, &H92, &HFA, _
             &HA1, &H31, &H5B, &H4D}
            '= "12345678901234561234567890123456";
            Dim data32_hex As String = "".PadLeft(32, " "c)
            address = sector * 4 + 2
            '写卡操作
            data32_hex = str
            st = dc_write(_icdev, address, data32_hex)
            If st = 0 Then
                dc_exit(_icdev)
            Else
                dc_exit(_icdev)
                Return False
            End If
            dc_exit(_icdev)
            Return True
        Catch
            dc_exit(_icdev)
            Return False
        End Try
    End Function

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/4/1 16:35:00 [显示全部帖子]


    Public Shared Function ReadCard(ByVal str As String, ByRef CardNo As String) As Boolean
        CardNo = ""
        Dim _icdev As Int32 = -1
        Try
            If _icdev < 0 Then
                _icdev = dc_init(100, 115200)
            End If
            Dim st As Integer
            '1.初始化
            If _icdev > 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            '蜂鸣
            st = dc_beep(_icdev, 10)
            If st = 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            Dim icCardNo As ULong = 0
            Dim tt As Char = ChrW(0)
            Dim ss As UInteger = 0
            st = dc_reset(_icdev, ss)
            st = dc_card(_icdev, tt, icCardNo)
            If icCardNo <> 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            Dim hexkey As Byte() = New Byte(5) {&HFF, &HFF, &HFF, &HFF, &HFF, &HFF}
            st = dc_load_key(_icdev, 0, 1, hexkey)
            '核对密码
            Dim sector As Integer = 1
            st = dc_authentication(_icdev, 0, sector)
            If st = 0 Then
            Else
                dc_exit(_icdev)
                Return False
            End If
            Dim temp As New StringBuilder(64)
            Dim temp1 As New StringBuilder(64)
            Dim address As Integer = 1
            Dim data32 As Byte()
            data32 = New Byte(15) {&H6A, &HC2, &H92, &HFA, &HA1, &H31, _
             &H5B, &H4D, &H6A, &HC2, &H92, &HFA, _
             &HA1, &H31, &H5B, &H4D}
            '= "12345678901234561234567890123456";
            Dim data32_hex As String = "".PadLeft(32, " "c)
            address = sector * 4 + 2
            Dim databuff32 As String = String.Empty
            st = dc_read(_icdev, address, temp1)
            If st = 0 Then
                CardNo = temp1.ToString()
            End If
            dc_exit(_icdev)
            Return True
        Catch
            dc_exit(_icdev)
            Return False
        End Try
    End Function
End Class


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2013/4/1 16:36:00 [显示全部帖子]

我帮你转换为vb.net的语法,你调整一下。

一个帖子发不下,分成两个了


 回到顶部