全局代码:
Public Declare Function CVR_InitComm Lib "termb.dll" Alias "CVR_InitComm" (ByVal Port As Integer) As Integer Public Declare Function CVR_Authenticate Lib "termb.dll" Alias "CVR_Authenticate" () As Integer Public Declare Function CVR_Read_Content Lib "termb.dll" Alias "CVR_Read_Content" (ByVal Active As Integer) As Integer Public Declare Function CVR_CloseComm Lib "termb.dll" Alias "CVR_CloseComm" () As Integer Public Declare Function GetPeopleName Lib "termb.dll" Alias "GetPeopleName" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetPeopleNation Lib "termb.dll" Alias "GetPeopleNation" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetPeopleBirthday Lib "termb.dll" Alias "GetPeopleBirthday" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetPeopleAddress Lib "termb.dll" Alias "GetPeopleAddress" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetPeopleIDCode Lib "termb.dll" Alias "GetPeopleIDCode" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetDepartment Lib "termb.dll" Alias "GetDepartment" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetStartDate Lib "termb.dll" Alias "GetStartDate" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetEndDate Lib "termb.dll" Alias "GetEndDate" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer Public Declare Function GetPeopleSex Lib "termb.dll" Alias "GetPeopleSex" (ByRef strTmp As Byte, ByRef strLen As Integer) As Integer
Public name As StringBuilder Public sex As String Public people As String Public birthday As String Public address As String Public number As String Public signdate As String Public validtermOfStart As String Public validtermOfEnd As String <StructLayout(LayoutKind.Sequential, Size:=16, CharSet:=CharSet.Ansi)> _ Public Structure IDCARD_ALL <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=30)> _ Public name As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=3)> _ Public sex As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4)> _ Public people As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _ Public birthday As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=70)> _ Public address As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=36)> _ Public number As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=30)> _ Public signdate As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _ Public validtermOfStart As Char <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _ Public validtermOfEnd As Char End Structure Public Sub FillData() Try pictureBox1.ImageLocation = (Application.StartupPath + "\\zp.bmp") Dim name() As Byte = New Byte((30) - 1) {} Dim length As Integer = 30 CVRSDK.GetPeopleName(name(0), length) 'MessageBox.Show(); Dim number() As Byte = New Byte((30) - 1) {} length = 36 CVRSDK.GetPeopleIDCode(number(0), length) Dim people() As Byte = New Byte((30) - 1) {} length = 3 CVRSDK.GetPeopleNation(people(0), length) Dim validtermOfStart() As Byte = New Byte((30) - 1) {} length = 16 CVRSDK.GetStartDate(validtermOfStart(0), length) Dim birthday() As Byte = New Byte((30) - 1) {} length = 16 CVRSDK.GetPeopleBirthday(birthday(0), length) Dim address() As Byte = New Byte((30) - 1) {} length = 70 CVRSDK.GetPeopleAddress(address(0), length) Dim validtermOfEnd() As Byte = New Byte((30) - 1) {} length = 16 CVRSDK.GetEndDate(validtermOfEnd(0), length) Dim signdate() As Byte = New Byte((30) - 1) {} length = 30 CVRSDK.GetDepartment(signdate(0), length) Dim sex() As Byte = New Byte((30) - 1) {} length = 3 CVRSDK.GetPeopleSex(sex(0), length) lblAddress.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(address) lblSex.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(sex) lblBirthday.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(birthday) lblDept.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(signdate) lblIdCard.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(number) lblName.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(name) lblNation.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(people) lblValidDate.Text = (System.Text.Encoding.GetEncoding("GB2312").GetString(validtermOfStart) + ("-" + System.Text.Encoding.GetEncoding("GB2312").GetString(validtermOfEnd))) Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub
public iRetUSB As Integer = 0 public isClose As Boolean = false public iRetCOM As Integer = 0 窗口的AfterLoad事件: Try Dim iPort As Integer iPort = 1001 Do While (iPort <= 1016) iRetUSB = CVRSDK.CVR_InitComm(iPort) If (iRetUSB = 1) Then Exit For End If iPort = (iPort + 1) Loop iPort = 1 Do While (iPort <= 4) iRetCOM = CVRSDK.CVR_InitComm(iPort) If (iRetCOM = 1) Then Exit For End If iPort = (iPort + 1) Loop If ((iRetCOM = 1) _ OrElse (iRetUSB = 1)) Then messagebox.show ("初始化成功") Else messagebox.show ("初始化失败") End If Catch ex As Exception MessageBox.Show(ex.ToString) End Try
窗口的BeforeClose事件: If Not isClose Then Try CVRSDK.CVR_CloseComm Me.Close Catch ex As Exception MessageBox.Show(ex.ToString) End Try End If
读取按钮事件: Try If ((iRetCOM = 1) _ OrElse (iRetUSB = 1)) Then Dim authenticate As Integer = CVRSDK.CVR_Authenticate If (authenticate = 1) Then Dim readContent As Integer = CVRSDK.CVR_Read_Content(4) If (readContent = 1) Then messagebox.show ("成功") FillData Else messagebox.show ("失败") End If Else MessageBox.Show("没有卡", cn, ")") End If Else 'MessageBox.Show("初始化失败") End If Catch ex As Exception MessageBox.Show(ex.ToString) End Try
|