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 84 85 86 87 88 89 90 91 92 93 94 95 96
|
//Propriétés
public static int CType_carte = 1;
public static string pCom_Port = "COM4";
public static long pAmount = 30; //30 valeur de TEST
public static int pNbrOfRetry = 3; //Nbr d'essai par défaut
private static int pAction = 0;
private static int pChoix = 0;
private static int CptTrame = 10; //Compteur de trame
private static int numError = 0;
//CONSTANTES
//FIELDS
const int Field_VIC_TX_AMT = 3; //Montant en eurocent
const int Field_CARD_ID_DISP = 11;
const int Field_TX_TYPE = 12;
const int Field_VIC_CARD_IND = 16;
const int Field_VIC_CMD_CODE = 17;
const int Field_VIC_TO = 20; //Délai d'insertion de carte
const int Field_VIC_TX_ID = 21; //Identification de la transaction
const int Field_CURCY = 23;
const int Field_VIC_CUST_IND = 25;
const int Field_VIC_TYPE = 31;
const int Field_OPERATOR_NR = 143;
const int Field_VIC_BM_APP_ID = 171;
//Erreurs
const int Erreur_TrameNonRecue = 1;
//VIC_MSG_CODE
const int vmc_debit_request = 1;
const int vmc_cancel = 2;
const int pdv_debit_result = 3;
const int pdv_error = 4;
//Méthodes
private static SerialPort sp;
public static void Action(int Par_Action)
{
switch (Par_Action)
{
case 1: //Annuler une transaction (VMC_Annule)
pAction = vmc_cancel;
pChoix = 3;
break;
case 4: //BC-MC
pAction = 5;
pChoix = 4;
break;
case 5: //Transaction BC avec montant dans pAmount
pAction = vmc_debit_request;
pChoix = 5;
break;
}
InitTerminal();
}
public static void InitTerminal()
{
//Procédure qui initialise le Terminal Bancontact
//on initialise la trame a envoyer
MemoryStream _memoryStream = new MemoryStream();
BinaryWriter _binaryWriter = new BinaryWriter(_memoryStream, Encoding.UTF8);
_binaryWriter.Write(Trame_KISS());
byte[] monBufferEcriture = new byte[_memoryStream.Length];
monBufferEcriture = _memoryStream.ToArray();
//Il faut maintenant envoyer le tout sur le port.
sp.Write(monBufferEcriture, 0, monBufferEcriture.Length);
bool sw=false;
int Cpt = 0;
while (sw == false && Cpt < pNbrOfRetry)
{
Cpt++;
sw = AckNack(CptTrame);
if (sw)
{
Console.Write("Commande passée\n" );
}
else
{
Console.Write("Commande non passée\n");
}
}
///on lit le port dans un thread pour un retour éventuel.
Thread t = new Thread(new ThreadStart(Com_Read));
t.Start();
} |
Partager