! ==========================================================
! 这个例子演示如何查找(Find), 打开(Open), 关闭(Close)
! 遍历所有加密锁的流程
! ==========================================================

!DEC$FREEFORM

INCLUDE 'head.F90'

integer*4 errcode 			! 错误码
integer*4 num 				! 查找到的读卡器个数
integer*4 hic 				! 设备的句柄
integer*4 i 
CHARACTER*256 reader_name

	write(*,*) '查找加密锁: ' 
	num = DIC_Find() 
	write(*,*) num 
	if (num <= 0) then	
		write(*,*)'未找到任何读卡器' 
		stop
	endif 

	do i=0, num-1
		write(*,*) '打开加密锁' 
		hic = DIC_Open(i, loc(reader_name))
		if (hic < 0) then		
			if (hic == SCARD_W_REMOVED_CARD) then
				write(*,*)'没找到 IC 卡' 
				continue 
			endif 
			write(*,'(" 错误码:",z8)') hic
			stop 
		endif
		write(*,'(A16)') reader_name 

		! ...
		! 对加密锁的具体操作部分
		! ...

	write(*,*)'关闭加密锁 '
	errcode = DIC_Close(hic) 
	if (errcode /= SCARD_S_SUCCESS) then
        write(*,'(" 错误码:",z8)') errcode
		stop
	endif 
enddo
end

	