社保卡信息读取 使用读卡器对社保卡信息读取,联通公司使用的代码,对硬件控制学习有所帮助吧

源代码在线查看: ok.frm

软件大小: 1823 K
上传用户: wentianliang
关键词: 社保卡 读取 代码 硬件
下载地址: 免注册下载 普通下载 VIP

相关代码

				VERSION 5.00
				Begin VB.Form FrmOK 
				   BackColor       =   &H00FFFFFF&
				   BorderStyle     =   0  'None
				   Caption         =   "Form1"
				   ClientHeight    =   2655
				   ClientLeft      =   5190
				   ClientTop       =   3780
				   ClientWidth     =   4095
				   LinkTopic       =   "Form1"
				   Picture         =   "OK.frx":0000
				   ScaleHeight     =   2655
				   ScaleWidth      =   4095
				   ShowInTaskbar   =   0   'False
				   Begin VB.CommandButton Command2 
				      Appearance      =   0  'Flat
				      BackColor       =   &H00FFFFFF&
				      Caption         =   "取消"
				      BeginProperty Font 
				         Name            =   "宋体"
				         Size            =   14.25
				         Charset         =   134
				         Weight          =   700
				         Underline       =   0   'False
				         Italic          =   0   'False
				         Strikethrough   =   0   'False
				      EndProperty
				      Height          =   495
				      Left            =   2280
				      Style           =   1  'Graphical
				      TabIndex        =   2
				      Top             =   1680
				      Width           =   1095
				   End
				   Begin VB.CommandButton Command1 
				      Appearance      =   0  'Flat
				      BackColor       =   &H00FFFFFF&
				      Caption         =   "确定"
				      BeginProperty Font 
				         Name            =   "宋体"
				         Size            =   14.25
				         Charset         =   134
				         Weight          =   700
				         Underline       =   0   'False
				         Italic          =   0   'False
				         Strikethrough   =   0   'False
				      EndProperty
				      Height          =   495
				      Left            =   600
				      Style           =   1  'Graphical
				      TabIndex        =   1
				      Top             =   1680
				      Width           =   1095
				   End
				   Begin VB.Line Line2 
				      BorderColor     =   &H00FFC0C0&
				      BorderWidth     =   5
				      Index           =   1
				      X1              =   0
				      X2              =   0
				      Y1              =   0
				      Y2              =   2640
				   End
				   Begin VB.Line Line2 
				      BorderColor     =   &H00FFC0C0&
				      BorderWidth     =   5
				      Index           =   0
				      X1              =   4080
				      X2              =   4080
				      Y1              =   0
				      Y2              =   2640
				   End
				   Begin VB.Line Line1 
				      BorderColor     =   &H00FFC0C0&
				      BorderWidth     =   5
				      Index           =   1
				      X1              =   0
				      X2              =   4080
				      Y1              =   2640
				      Y2              =   2640
				   End
				   Begin VB.Line Line1 
				      BorderColor     =   &H00FFC0C0&
				      BorderWidth     =   5
				      Index           =   0
				      X1              =   0
				      X2              =   4080
				      Y1              =   0
				      Y2              =   0
				   End
				   Begin VB.Label Label1 
				      BackStyle       =   0  'Transparent
				      Caption         =   "请确认插入IC卡..."
				      BeginProperty Font 
				         Name            =   "宋体"
				         Size            =   18
				         Charset         =   134
				         Weight          =   700
				         Underline       =   0   'False
				         Italic          =   0   'False
				         Strikethrough   =   0   'False
				      EndProperty
				      ForeColor       =   &H00FF0000&
				      Height          =   615
				      Left            =   480
				      TabIndex        =   0
				      Top             =   600
				      Width           =   3375
				   End
				End
				Attribute VB_Name = "FrmOK"
				Attribute VB_GlobalNameSpace = False
				Attribute VB_Creatable = False
				Attribute VB_PredeclaredId = True
				Attribute VB_Exposed = False
				Private Sub Command1_Click()
				Label1.Caption = "运行中,请等待..."
				MF_Get_Data
				frmsb.Show
				Unload Me
				End Sub
				
				Private Sub Command2_Click()
				Unload Me
				End Sub
				
				''  本地读取IC卡函数部分
				
				
				'打开串口
				 Private Sub cmdOpen()
				    If Not PortOpened Then
				        fd = ICC_Reader_Open("COM2")
				        PortOpened = True
				        If fd < 0 Then
				             MsgBox "串口已经被打开"
				            'List_Error.Show
				             End
				        Else
				            PortOpened = True
				        End If
				    End If
				End Sub
				
				
				'关闭串口
				Private Sub cmdClose()
				    If PortOpened Then
				        ICC_Reader_Close (fd)
				        PortOpened = False
				    End If
				
				End Sub
				
				
				'上电
				Private Sub cmdPowerOn()
				    Dim ret As Long
				    Dim resp(0 To 255) As Byte
				    ret = ICC_Reader_InsertCard(fd, ICC_CONNECTOR_USER, ICC_T0, 32, resp(0))
				    If ret < 0 Then
				        MsgBox "ATR fail"
				    End If
				    
				End Sub
				
				
				'下电
				Private Sub cmdPowerOff()
				    ICC_Reader_RemoveCard fd, ICC_CONNECTOR_USER, 0
				End Sub
				
				
				'选择 MF_DF
				Private Function Switch(Handel As String) As Long
				    Dim mf_df As String
				    Dim ret As Long
				    Dim errmsg As String
				    mf_df = Handel + vbNullChar
				    errmsg = Space(256)
				    If Handel = "DF08" Then
				        ret = switch_service(fd, mf_df, AUTH_READ + AUTH_WRITE, errmsg)
				    Else
				        ret = switch_service(fd, mf_df, 0, errmsg)
				    End If
				    
				    If ret < 0 Then
				        MsgBox errmsg
				    End If
				
				End Function
				
				
				'读取数据
				Private Function ReadRec(ef As String, recno As String, transform As String) As Long
				    Dim ret As Long
				    Dim EF1 As String
				    Dim RecNo1 As Long
				    Dim data As String
				    Dim tf As Long
				    Dim errmsg As String
				    EF1 = ef
				    RecNo1 = CInt(recno)
				    data = Space(256)
				    
				    tf = -1
				    Select Case transform
				        Case "CN": tf = TF_CN
				        Case "AN": tf = TF_AN
				        Case "BIN": tf = TF_BIN
				    End Select
				    If tf = -1 Then
				        MsgBox "Error set TransForm"
				        Exit Function
				    End If
				    
				    
				    errmsg = Space(256)
				    ret = read_record(fd, EF1, RecNo1, data, tf, errmsg)
				    If ret < 0 Then
				        End
				    Else
				        Data_A(Count_No) = data
				    End If
				    
				    Count_No = Count_No + 1
				
				End Function
				
				
				
				
				  
				'MF GET DATA
				Private Sub MF_Get_Data()
				If Not PortOpened Then
				         cmdOpen
				End If
				Count_No = 0
				Dim ret As Long
				ret = Switch("MF")
				
				'EFO5 数据进库(发卡机关数据)
				ret = ReadRec("EF05", "07", "AN")
				
				'EF06 数据进库(个人基本信息)
				ret = ReadRec("EF06", "01", "AN")
				ret = ReadRec("EF06", "02", "AN")
				ret = ReadRec("EF06", "03", "AN")
				ret = ReadRec("EF06", "04", "CN")
				ret = ReadRec("EF06", "06", "CN")
				
				''EF07 数据进库(指纹信息)
				
				'DF01 GET data
				
				ret = Switch("DF01")
				
				'EFO5 数据进库(户籍信息)
				ret = ReadRec("EF05", "02", "AN")
				ret = ReadRec("EF05", "04", "CN")
				
				'EF06 数据进库(通讯信息)
				ret = ReadRec("EF06", "04", "AN")
				
				'EF08 数据进库(婚姻状况信息)
				ret = ReadRec("EF08", "01", "AN")
				
				'EFO9
				ret = ReadRec("EF09", "01", "AN")
				
				
				    ICC_Reader_RemoveCard fd, ICC_CONNECTOR_USER, 0
				    cmdClose
				End Sub
				
				Private Sub Form_Load()
				Dim Rtn
				Rtn = SetWindowPos(FrmOK.hwnd, -1, 0, 0, 0, 0, 3)
				End Sub
							

相关资源