Si on utilise l'api fourni avec le lecteur, essaie ceci:
Télécharge l'api et dézippe
http://www.acs.com.hk/download-driver-u ... 1001-P.zip
Commence par lire le petit chm car il y a une histoire de fichier ini à créer qui n'est pas très clair.
Dans le dossier lib\x86 ou lib\x64, crée le fichier ctacs.ini avec ceci à l'intérieur:
; Sample ctacs.ini (Windows)
[CardTerminal]
CTN1=ACR122U
[ACR122U]
ICC1=ACS CCID USB Reader 0
Avec l’éditeur PureBasic , crée un fichier ct_api.pbi
C'est l'importation des fonctions de la dll
Code : Tout sélectionner
;/**
; * @file
; * ACS CT-API library header file.
; * @version 1.0
; * @date 7 September 2011
;* @copyright Copyright (C) 2011 Advanced Card Systems Ltd. All rights reserved.
;*/
;/**
;* @mainpage Using CT-API
;*
;* @section Introduction Introduction
;*
;* This documentation covers the APIs provided by ACS CT-API library. This
;* library implements CT-API functions For ACS smart card readers.
;*
;* @section DefiningCardTerminals Defining Card Terminals
;*
;* To use CT-API With ACS smart card readers, you must place a initialization
;* file "ctacs.ini" To the current directory With your application program. This
;* file is To Map PC/SC readers To card terminal numbers And ICC interfaces.
;*
;* The following sample INI file defines 2 card terminals. CTN1 is mapped To
;* ACR38U-CCID While CTN2 is mapped To ACR128U And each ICC Interface is mapped
;* To PC/SC reader name.
;*
;* @subsection Windows Windows
;*
;* @code
;* ; Sample ctacs.ini (Windows)
;*
;* [CardTerminal]
;* CTN1=ACR38U-CCID
;* CTN2=ACR128U
;*
;* [ACR38U-CCID]
;* ICC1=ACS CCID USB Reader 0
;*
;* [ACR128U]
;* ICC1=ACS ACR128U ICC Interface 0
;* ICC2=ACS ACR128U PICC Interface 0
;* ICC3=ACS ACR128U SAM Interface 0
;* @endcode
;*
;* @subsection LinuxMacOSX Linux/Mac OS X
;*
;* @code
;* ; Sample ctacs.ini (Linux/Mac OS X)
;*
;* [CardTerminal]
;* CTN1=ACR38U-CCID
;* CTN2=ACR128U
;*
;* [ACR38U-CCID]
;* ICC1=ACS ACR38U-CCID 00 00
;*
;* [ACR128U]
;* ICC1=ACS ACR128U 00 00
;* ICC2=ACS ACR128U 00 01
;* ICC3=ACS ACR128U 00 02
;* @endcode
;*
;* @section CallingCTAPIFunctions Calling CT-API Functions
;*
;* Your source code must include a header file "ct_api.h" IN order To CALL the
;* CT-API functions.
;*
;* @code
; * #include <stdio.h>
; * #include <ct_api.h>
; *
; * INT main(INT argc, char; *argv[])
; * {
; * char RET;
; * unsigned short ctn;
; * unsigned short pn;
; * unsigned short sad;
; * unsigned short dad;
; *
; * // REQUEST ICC
; * unsigned char command[] = { 0x20, 0x12, 0x01, 0x00, 0x00 };
; * unsigned short lenc = SizeOf(command);
; *
; * unsigned char response[300];
; * unsigned short lenr = SizeOf(response);
; *
; * ctn = 1;
; * pn = 1;
; *
; * // Initialize card terminal
; * RET = CT_init(ctn, pn);
; * If (RET != OK)
; * {
; * printf("Error: CT_init failed with error %d\n", RET);
; * Return 1;
; * }
; *
; * sad = 2; // Source = Host
; * dad = 1; // Destination = Card Terminal
; *
; * // Send command
; * RET = CT_data(ctn, &dad, &sad, lenc, command, &lenr, response);
; * If (RET != OK)
; * printf("Error: CT_data failed with error %d\n", RET);
; * Else
; * {
; * // Display response
; * printf("Response: ");
; * For (i = 0; i < lenr; i++)
; * printf("%02X ", response[i]);
; * printf("\n");
; * }
; *
; * // Close card terminal
; * RET = CT_close(ctn);
; * If (RET != OK)
; * printf("Error: CT_close failed with error %d\n", RET);
; *
; * Return 0;
; * }
; * @endcode
; */
;/**
; * @page ReturnValues Return Values
; *
; * @section CTAPIReturnValues CT-API Return Values
; *
; * CT-API functions Return the following values:
; *
; * <table>
; * <tr><th>Error Code</th><th>Value</th><th>Description</th></tr>
; * <tr><td>OK</td><td>0</td><td>Function CALL was successful.</td></tr>
; * <tr><td>ERR_INVALID</td><td>-1</td><td>Invalid parameter Or value.</td></tr>
; * <tr><td>ERR_CT</td><td>-8</td><td>CT error.</td></tr>
; * <tr><td>ERR_TRANS</td><td>-10</td><td>Non-eliminable transmission error.</td></tr>
; * <tr><td>ERR_MEMORY</td><td>-11</td><td>Memory assignment error IN HTSI.</td></tr>
; * <tr><td>ERR_HOST</td><td>-127</td><td>Abort of function by host/OS.</td></tr>
; * <tr><td>ERR_HTSI</td><td>-128</td><td>HTSI error.</td></tr>
; * </table>
; */
;#ifndef CT_API_H
;#define CT_API_H
;#ifdef _WIN32
;#include <windows.h>
;#else
;#define WINAPI ///< Calling convention.
;#endif
;// Error codes
; Ici je préfère créer des variables globales plutôt que des constante
Global OK=0;#define OK 0 ///< Function CALL was successful.
Global ERR_INVALID =-1;#define ERR_INVALID -1 ///< Invalid parameter Or value.
Global ERR_CT = -8;#define ERR_CT -8 ///< CT error.
Global ERR_TRANS = -10;#define ERR_TRANS -10 ///< Non-eliminable transmission error.
Global ERR_MEMORY= -11;#define ERR_MEMORY -11 ///< Memory assignment error IN HTSI.
Global ERR_HOST = -127;#define ERR_HOST -127 ///< Abort of function by host/OS.
Global ERR_HTSI = -128;ERR_HTSI -128#define ERR_HTSI -128 ///< HTSI error.
dll=OpenLibrary(0,"ctacs.dll")
If dll = 0
Debug "dll introuvable"
End
EndIf
;/**
;* Pointer To CT_init() function.
;*/
;typedef char (WINAPI *CT_INIT)(unsigned short ctn, unsigned short pn);
Prototype ProtoCT_init(ctn.u, pn.u)
CT_init.ProtoCT_init = GetFunction(0, "CT_init")
; Initiation of the host/CT connection.
;
; Parameters:
; ctn Logical CardTerminal number.
; pn Port number of the physical Interface. This parameter is reserved For future use And it must be 1.
;
; Returns:
; If the function succeeds, the function returns OK.
; If the function fails, it returns an error code. For more information, see CT-API Return Values.
;/**
; * Pointer To CT_data() function.
; */
;typedef char (WINAPI *CT_DATA)(unsigned short ctn, unsigned char *dad, unsigned char *sad,
; unsigned short lenc, unsigned char *command, unsigned short *lenr, unsigned char *response);
Prototype ProtoCT_data(ctn.u, *dad, *sad, lenc.u, *command, *lenr, *response)
CT_data.ProtoCT_data = GetFunction(0, "CT_data")
; Transmission of a command To a CardTerminal Or To an ICC And give back the response.
;
; Parameters:
; ctn Logical CardTerminal number.
; dad Destination address. Destination Address (Hex) Receiver
; 00 ICC1 (IC card 1)
; 01 CT
; 02 ICC1 (IC card 2)
; ... ...
; 0E ICC14 (IC card 14)
; XX other values reserved
;
;
; sad Source address. Source Address (Hex) Sender
; 02 HOST
; 05 REMOTE HOST
;
;
; lenc Command length IN byte.
; command ICC-command Or CT-command.
; lenr Passing of the max. buffer size of the response field To the function And Return of the actual length of the response IN byte.
; response Response To the command.
;
; Returns:
; If the function succeeds, the function returns OK.
; If the function fails, it returns an error code. For more information, see CT-API Return Values.
; /**
; * Pointer To CT_close() function.
; */
; typedef char (WINAPI *CT_CLOSE)(unsigned short ctn);
Prototype ProtoCT_close(ctn.u)
CT_close.ProtoCT_close = GetFunction(0, "CT_close")
; Close the host/CT connection.
;
; Parameters:
; ctn Logical CardTerminal number.
;
; Returns:
; If the function succeeds, the function returns OK.
; If the function fails, it returns an error code. For more information, see CT-API Return Values.
;#ifdef __cplusplus
;extern "C" {
;#endif
;/**
;* Initiation of the host/CT connection.
; * @param ctn Logical CardTerminal number.
; * @param pn Port number of the physical Interface. This parameter is reserved
; * For future use And it must be 1.
;* @return If the function succeeds, the function returns OK.<br />
;* If the function fails, it returns an error code. For more
;* information, see @ref CTAPIReturnValues.
; */
; char WINAPI CT_init(unsigned short ctn, unsigned short pn);
;
; /**
; * Transmission of a command To a CardTerminal Or To an ICC And give back the
; * response.
; * @param ctn Logical CardTerminal number.
; * @param dad Destination address.
; * <table>
; * <tr><th>Destination Address (Hex)</th><th>Receiver</th></tr>
; * <tr><td>00</td><td>ICC1 (IC card 1)</td></tr>
; * <tr><td>01</td><td>CT</td></tr>
; * <tr><td>02</td><td>ICC1 (IC card 2)</td></tr>
; * <tr><td>...</td><td>...</td></tr>
; * <tr><td>0E</td><td>ICC14 (IC card 14)</td></tr>
; * <tr><td>XX</td><td>other values reserved</td></tr>
; * </table><br />
; * @param sad Source address.
; * <table>
; * <tr><th>Source Address (Hex)</th><th>Sender</th></tr>
; * <tr><td>02</td><td>HOST</td></tr>
; * <tr><td>05</td><td>REMOTE HOST</td></tr>
; * </table><br />
; * @param lenc Command length IN byte.
; * @param command ICC-command Or CT-command.
; * @param lenr Passing of the max. buffer size of the response field To the
; function And Return of the actual length of the response IN
; byte.
; * @param response Response To the command.
; * @return If the function succeeds, the function returns OK.<br />
; * If the function fails, it returns an error code. For more
; * information, see @ref CTAPIReturnValues.
; */
; char WINAPI CT_data(unsigned short ctn, unsigned char *dad, unsigned char *sad,
; unsigned short lenc, unsigned char *command, unsigned short *lenr, unsigned char *response);
;
; /**
; * Close the host/CT connection.
; * @param ctn Logical CardTerminal number.
; * @return If the function succeeds, the function returns OK.<br />
; * If the function fails, it returns an error code. For more
; * information, see @ref CTAPIReturnValues.
; */
; char WINAPI CT_close(unsigned short ctn);
;
; #ifdef __cplusplus
; }
; #endif
;
; #endif
(En fait, je me suis compliqué inutilement la tache, j'aurais pu utiliser la fonction Import ou ImportC de PB ce qui aurait donné ce code:
Code : Tout sélectionner
Global OK=0 ;#define OK 0 ///< Function CALL was successful.
Global ERR_INVALID =-1 ;#define ERR_INVALID -1 ///< Invalid parameter Or value.
Global ERR_CT = -8 ;#define ERR_CT -8 ///< CT error.
Global ERR_TRANS = -10 ;#define ERR_TRANS -10 ///< Non-eliminable transmission error.
Global ERR_MEMORY= -11 ;#define ERR_MEMORY -11 ///< Memory assignment error IN HTSI.
Global ERR_HOST = -127;#define ERR_HOST -127 ///< Abort of function by host/OS.
Global ERR_HTSI = -128;#define ERR_HTSI -128 ///< HTSI error.
Import "ctacs.lib"
CT_close(ctn.u) As "CT_close"
CT_data(ctn.u, *dad, *sad, lenc.u, *command, *lenr, *response) As "CT_data"
CT_init(ctn.u, pn.u) As "CT_init"
EndImport
fin de la parenthèse)
Crée un fichier Test.pb, qui est la traduction du code c en pb du chm
Code : Tout sélectionner
;exemple trouvé dans le chm
;#include <stdio.h>
IncludeFile "ct_api.pbi" ; #include <ct_api.h>
;INT main(INT argc, char *argv[])
; {
RET.a ;char RET;
ct.u ;unsigned short ctn;
pn.u ;unsigned short pn;
sad.u ;unsigned short sad;
dad.u ;unsigned short dad;
;// REQUEST ICC
*command=AllocateMemory(5);unsigned char command[] = { 0x20, 0x12, 0x01, 0x00, 0x00 };
PokeA(*command,$20)
PokeA(*command+1,$12)
PokeA(*command+2,$01)
PokeA(*command+3,$00)
PokeA(*command+4,$00)
lenc.u=MemorySize(*command);unsigned short lenc = SizeOf(command);
*reponse=AllocateMemory(300);unsigned char response[300];
lent.u=MemorySize(*reponse) ;unsigned short lenr = SizeOf(response);
ctn = 1;
pn = 1 ;
;// Initialize card terminal
RET = CT_init(ctn, pn);
If RET <> OK ;If (RET != OK)
;{
Debug "Error: CT_init failed with error " + Str(RET);printf("Error: CT_init failed With error %d\n", RET);
;Retour=1;Return 1;
EndIf ;}
sad = 2; // Source = Host
dad = 1; // Destination = Card Terminal
;// Send command
RET = CT_data(ctn, @dad, @sad, lenc, command, @lenr, response);RET = CT_data(ctn, &dad, &sad, lenc, command, &lenr, response);
If RET <> OK ;If (RET != OK)
Debug "Error: CT_data failed With error " + Str(RET) ;printf("Error: CT_data failed With error %d\n", RET);
Else
;{
;// Display response
Debug "Response: ";printf("Response: ");
For i = 0 To lenr -1; i++);For (i = 0; i < lenr; i++)
Debug Hex(PeekA(*response+i),#PB_Ascii);printf("%02X ", response[i]);
;printf("\n");
Next i
EndIf;}
;// Close card terminal
RET = CT_close(ctn);
If RET <> OK ;If (RET != OK)
Debug "Error: CT_close failed With error " + Str(RET);printf("Error: CT_close failed With error %d\n", RET);
EndIf
;Retour=0;Return 0;
;}
Il faut que tous les fichiers le .pb, le .pbi, le .ini et la dll, la .lib soient dans le même dossier.
Ça devrait fonctionner en x64 comme en x86
Si ça donne du chinois, c'est une histoire d'unicode/ascii
Lance Test.pb
Ça donne quelque chose ?
[Edition] J'ai corrigé le .pbi
Mesa.