1 /*
  2  *  ---------
  3  * |.##> <##.|  Open Smart Card Development Platform (www.openscdp.org)
  4  * |#       #|  
  5  * |#       #|  Copyright (c) 1999-2006 CardContact Software & System Consulting
  6  * |'##> <##'|  Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de)
  7  *  --------- 
  8  *
  9  *  This file is part of OpenSCDP.
 10  *
 11  *  OpenSCDP is free software; you can redistribute it and/or modify
 12  *  it under the terms of the GNU General Public License version 2 as
 13  *  published by the Free Software Foundation.
 14  *
 15  *  OpenSCDP is distributed in the hope that it will be useful,
 16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18  *  GNU General Public License for more details.
 19  *
 20  *  You should have received a copy of the GNU General Public License
 21  *  along with OpenSCDP; if not, write to the Free Software
 22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 23  *
 24  *  Read balance from German Geldkarte
 25  */
 26 
 27 
 28 try	{
 29 	var card = new Card(_scsh3.reader);
 30 
 31 	var record;
 32 	
 33 	try	{
 34 		var mf = new CardFile(card, ":3F00");
 35 		var df_boerse = new CardFile(card, "#D27600002545500200");
 36 		var ef_betrag = new CardFile(df_boerse, ":0104");
 37 
 38 		record = ef_betrag.readRecord(1);
 39 	}
 40 	catch(e) {
 41 		print("Trying old GeldKarte version");
 42 		card.sendApdu(0x00, 0xA4, 0x04, 0x0C, new ByteString("D27600002545500100", HEX), [0x9000]);
 43 		record = card.sendApdu(0x00, 0xB2, 0x01, 0xC4, 0x09, [0x9000]);
 44 	}
 45 	
 46 	// Convert ByteString to String and read BCD coded value
 47 	var balance = record.bytes(0, 3).toString(HEX).valueOf();
 48 	print("Current balance : " + (balance / 100).toFixed(2) + " EUR");
 49 	
 50 }
 51 
 52 catch(e) {
 53 	print("Exception reading from GeldKarte: " + e);
 54 }
 55 
 56 
 57 
 58