availiable memory in JCOP31

hello guys.... i need some help.

I am using jcop31 and i try to get the memory availiable in my card with this code

short m = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT);

then i create the following class to give me the short m in apdu

private void rd_memory(APDU apdu) {

byte[] buffer = apdu.getBuffer();

short le = apdu.setOutgoing();apdu.setOutgoingLength((byte)2);

buffer[0] = (byte)(m >> 8);

buffer[1] = (byte)(m & 0xFF);

apdu.sendBytes((short)0, (short)2);

}

is this code right? i am getting 6FFF......

[611 byte] By [flasholinosa] at [2007-11-27 9:29:53]
# 1

Please use the code formatting.

Here is a hint:

short m = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT); // example: m = 0x1234

buffer[0] = (byte)(m >> 8); // --> buffer[0] = 0x12

buffer[1] = (byte)(m & 0xFF); // --> equivalent to 0x1234 & 0x00FF --> buffer[1]=0x12

You can use the more convinient way to set short and send:

Util.setShort(buffer, (short) 0, m); // instead of buffer[0/1] = ..

apdu.setOutgoingAndSend((short) 0, (short) 2);

Be aware that the JCSystem.getAvailableMemory() method returns a max of 32kB.

Java Card API:

" ..

If the number of available bytes is greater than 32767, then this method returns 32767. "

lexdabeara at 2007-7-12 22:39:39 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

thank you for your replay

when i am using this code:

private void rd_memory(APDU apdu) {

short m = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT);

byte[] buffer = apdu.getBuffer();

short le = apdu.setOutgoing();

if ( le < 2 )

ISOException.throwIt

(ISO7816.SW_WRONG_LENGTH);

apdu.setOutgoingLength((byte)2);

buffer[0] = (byte)(m >> 8);

buffer[1] = (byte)(m & 0xFF);

apdu.sendBytes((short)0, (short)2);

}

i am getting 7D 90 90 00 as a result

i try to put Util.setShort(buffer, (short) 0, m); // instead of buffer[0/1]

and the result was 7D 9C 90 00

is this ok?

flasholinosa at 2007-7-12 22:39:39 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 3
Yes, it looks correct. You have approx. 32kB left.
lexdabeara at 2007-7-12 22:39:39 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 4
THANK YOU!!!
flasholinosa at 2007-7-12 22:39:39 > top of Java-index,Java Mobility Forums,Consumer and Commerce...