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
| Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet := CharSet.Ansi)> _
Public Structure CSC_FW_INFO
<MarshalAs(UnmanagedType.ByValTStr, SizeConst := 48)> Public blVersionName As String
Public blPushButtonGD As System.Byte
Public appStatus As System.Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst := 48)> Public appVersionName As String
Public fwExecutionFlag As System.Byte
<MarshalAs(UnmanagedType. ByValArray, SizeConst := 12)> Public serialNumber() As byte
End Structure
Public Delegate Sub fHookInstall (ByVal hCsc As System.UInt32, ByVal ratio As System.uint32, ByVal pArg As System.IntPtr) 'As System.Int16
Private shared ProcpHookFunc as fHookInstall
Public Class SocietyCscApi
<DllImport("SocietyCscApi.dll", EntryPoint:="sCSCReaderStartEx", SetLastError:=True, CharSet:=CharSet.ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCSCReaderStartEx(byval pszComName As System.String, byval ulSpeed As System.UInt32, byref phCsc As System.UInt32) As System.Int16
End Function
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscRebootEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscRebootEx(byval phCsc As System.UInt32) As System.Int16
End Function
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscGetFwInfoEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscGetFwInfoEx(byval hCsc As System.UInt32, byref pFwInfo As CSC_FW_INFO) As System.Int16
End Function
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscInstallFileEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscInstallFileEx(byval hCsc As System.UInt32, byval pszFileName As System.String) As System.Int16
End Function
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscSetInstallHookEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscSetInstallHookEx(byval hCsc As System.UInt32, byval pHookFunc As fHookInstall, byval pArg As System.IntPtr) As System.Int16
End Function
End Class
Public Partial Class MainForm
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
Dim retour As System.Int16
'Paramètre de la connexion avec le lecteur PORTCOM, SPEED, HANDLE
Dim PORTCOM As System.String = "COM11"
Dim SPEEDCOM As System.UInt32 = 0
Dim pCSCHANDLE As New System.UInt32
'Paramètre pour le firmware
Dim pFIRMINFO As New CSC_FW_INFO
Dim pFILENAME As System.String = "Firmware.dfl"
Dim ProcedurepHookFunc as New fHookInstall(AddressOf ProcpHookFunc)
'initialise la connexion avec le lecteur
retour = SocietyCscApi.sCSCReaderStartEx(PORTCOM, SPEEDCOM, pCSCHANDLE)
'reboot pour etre sur que le lecteur est dans un état initial
retour = SocietyCscApi.sCscRebootEx(pCSCHANDLE)
'on récupère les infos du firmware existant
retour = SocietyCscApi.sCscGetFwInfoEx(pCSCHANDLE, pFIRMINFO)
'paramètrage de la fonction de callback pour la mise à jour du firmware
retour = SocietyCscApi.sCscSetInstallHookEx(pCSCHANDLE, ProcedurepHookFunc, IntPtr.Zero)
'mise à jour du lecteur avec le nouveau firmware
retour = SocietyCscApi.sCscInstallFileEx(pCSCHANDLE, pFILENAME)
'on récupère les infos du firmware mis à jour
retour = SocietyCscApi.sCscGetFwInfoEx(pCSCHANDLE, pFIRMINFO)
End Sub
'Fonction de callback
Private sub ProcpHookFunc (ByVal hCsc As System.UInt32, ByVal ratio As System.uint32, ByVal pArg As System.IntPtr)
Msgbox(ratio) 'pour voir la valeur du ratio s'incrémenter
End Sub
End Class |
Partager