import Pcsc.*;
import AcsCommon.*;

public class ReaderFunctions {
	final static public int GET_SERIAL_EXPECTED_LENGTH = 2;

	private PcscReader pcscReader_;

	public PcscReader getPcscConnection() {
		return this.pcscReader_;
	}

	public void setPcscConnection(PcscReader pcscConnection) {
		this.pcscReader_ = pcscConnection;
	}

	public ReaderFunctions() {
		pcscReader_ = null;
	}

	public ReaderFunctions(PcscReader pcscReader) {
		setPcscConnection(pcscReader);
	}

	public void getSerialNumber() throws Exception {
		Apdu apdu = new Apdu();
		apdu.setCommand(new byte[] { (byte) 0xFF, (byte) 0xCA, (byte) 0x00, (byte) 0x00, (byte) 0x00 });
		apdu.setSendData(new byte[0]);
		apdu.setLengthExpected(GET_SERIAL_EXPECTED_LENGTH);

		getPcscConnection().sendApduCommand(apdu);

		if (apdu.getStatusWord()[0] != (byte) 0x90)
			throw new Exception(
					"[" + Helper.byteAsString(apdu.getStatusWord(), false) + "]" + " Get Serial Number failed");
	}
}
