Page 1 of 1

How to save variables to EEPROM of Java Card JC30M48CR

Posted: Fri Jan 28, 2022 6:08 am
by mbsysde99
I want to store a variable in memory that is not lost when the power supply is lost and I can update the contents of that memory while the program is running. In short, How to save variables to EEPROM of Java Card JC30M48CR? Thanks.

Regards,
Yudha

Re: How to save variables to EEPROM of Java Card JC30M48CR

Posted: Fri Jan 28, 2022 11:42 am
by mbsysde99

Code: Select all

                
		A. PERSISTENT MEMORY 
 
 		1. // Persistent Memory (EEPROM) =  Memory still exist while lost power.
		//  Without set as transient object,  it immediately becomes a persistent object and save to EEPROM.
		byte[] SRC = new byte[]{1, 2};
               
                   OR
               
		2. // Persistent Memory (EEPROM) =  Memory still exist while lost power
		byte[] PM = JCSystem.makeTransientByteArray((short)2, JCSystem.MEMORY_TYPE_PERSISTENT);		
		JCSystem.beginTransaction();		
		Util.arrayCopyNonAtomic(SRC, (short)0, PM, (short)0, (short)2);		
		JCSystem.commitTransaction();
		

 		B. TEMPORARY MEMORY
 
		1. // Clear On Deselect Memory = Clear memory when applet is deselect.
		byte[] COD = JCSystem.makeTransientByteArray((short)2, JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT);		
		JCSystem.beginTransaction();		
		Util.arrayCopyNonAtomic(SRC, (short)0, COD, (short)0, (short)2);		
		JCSystem.commitTransaction();

		2. // Clear On Reset Memory = Clear memory when card pull up / lost power.
		byte[] COR = JCSystem.makeTransientByteArray((short)2, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);		
		JCSystem.beginTransaction();		
		Util.arrayCopyNonAtomic(SRC, (short)0, COR, (short)0, (short)2);		
		JCSystem.commitTransaction();