* ==========================================================================
* Demo: Get ATR and volume information.
* Caution: no error check for the sake of briefness and understandability
* Tips:
* (1) Card Info Include 2 parts: ATR and volume name of ROCKEY device.     
* (2) ATR file is always generated after format, it's a system file for every card. 
*     Software developers decide how to use ATR. In general we recommend software 
*	   developers to write their company information into it. That way after a DIC_Open 
*	   command you may get this information and tell whether it is your dongle. ATR can only
*	   be setted when format, and its maximum length is 15 bytes.
* (3) there is a integrated file system in the card, its same as file system in PC, so it have 
*	   volume name. you can get vulume name after open operation. the maximum length of volume name 
*	   is 16 bytes.     
* (4) When using DIC_Get, if the mode macro is ATR or VOLUME, the data is always returned 
*     by BY_ARRAY mode, no matter how the returned mode is set. Then, the return value of DIC_Get 
*	   is the length of ATR or volume information in the buffer.   
* (5) You must call DIC_Command to do GET_CARD_INFO operation before DIC_Get. it will store ATR and volume
* 	   to buffer.

* ==========================================================================
#include "Dic32_Vfp.h"
clear 
DECLARE integer   DIC_Find IN DIC32U.dll
DECLARE integer   DIC_Open IN DIC32U.dll integer hic, string @  reader_name
DECLARE integer   DIC_Close  IN DIC32U.dll  integer   hic
DECLARE integer   DIC_Command  IN DIC32U.dll  integer  hic, integer cmd, string @  cmddata
DECLARE integer   DIC_Get  IN DIC32U.dll  string @  xdata, integer  p1, integer   p2, string @  buffer
DECLARE integer   DIC_Set  IN DIC32U.dll  string @  xdata, integer  p1, integer  p2, integer   p3, string @  buffer


store 0 to  errcode		   && error code
store 0 to  num		   && number of founded card reader(s)
store 0 to  hic		   && handle of ROCKEY device.
store 0 to  i
cmddata=space(256)
buffer =space(256)

	num = DIC_Find()
	for i=0 to num-1
		hic = DIC_Open(i, NULL)
		if (hic >= 0) 
		  exit  	&& Stop searching when found one.
  	  endif
	endfor
	if (i == num) 
	     return
    endif

	errcode = DIC_Command(hic, GET_CARD_INFO, @cmddata)  
	DIC_Get(@cmddata, ATR, BY_ARRAY, @buffer)  	&& Transfer ATR from cmddata to buffer
	?"ATR:", buffer  
	DIC_Get(@cmddata,VOLUME, BY_ARRAY, @buffer)   && Transfer VOLUME from cmddata to buffer
	?"VOLUME: ", buffer  

	errcode = DIC_Close(hic)  
clear dlls
return 	