⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 15693_test_mini.c

📁 pos机contactless源码
💻 C
字号:
/*ISO15693 Test Program
  Wang Yue 2005-8-26
 */

#include <stdio.h>
#include <stdlib.h>
#include <api.h>
#include <ExEH0218.h>
#include <contactless.h>
#include "common.h"

static short ICODE1_test(void);
static short TI_ICODE2_test(unsigned char card_flag);
static short TI_ICODE2_read(unsigned char card_flag);
static short TI_ICODE2_write(unsigned char card_flag);


short ISO15693_test_mini(void)
{
	short 		ret;	
	BROWINFO  	INFO_main;	

	char menu_info[] =   "1.TI 测试       2.ICODE2 测试   "
	                     "3.ICODE1 测试   ";

	char menu_info_eng[]="1.TI Test       2.ICODE2 Test   "
	                     "3.ICODE1 Test   ";
	                     
	if(Get_Language()==LANG_CHN)
	{
		INFO_main.iStr = menu_info;
	}
	else
	{
		INFO_main.iStr = menu_info_eng;
	}
	INFO_main.lPtr = 0;
	INFO_main.cPtr = 0;
	INFO_main.startLine = 0;
	while(1)
	{		
		clr_scr();
		INFO_main.mInt = 2;
		INFO_main.lineMax = 16;
		INFO_main.sFont = 0;
		INFO_main.numEnable = 0;		
		INFO_main.qEvent = EXIT_KEY_F1|EXIT_AUTO_QUIT;	
		INFO_main.autoexit = 150;				
				
		ret = brow_select(&INFO_main);		
		switch( ret )
		{
			case 0:
				TI_ICODE2_test(0);
				break;
			case 1:
				TI_ICODE2_test(1);			
				break;			
			default:				
				return -1;					
				break;									
		}
	}

	return 0;
}

//card_flag==0 :TI
//card_flag==1 :ICODE2
static short TI_ICODE2_test(unsigned char card_flag)
{
	BROWINFO  	INFO_sub;		
	int	  	retint;	
	unsigned char 	errstr[30];		
	unsigned char	menu_info[50];
	
	if(Get_Language()==LANG_CHN)
	{
		strcpy(menu_info,"1.读测试        2.写测试        ");
		strcpy(errstr,"接口打开错误");
	}
	else
	{
		strcpy(menu_info,"1.Read Test     2.Write Test    ");
		strcpy(errstr,"Interface Error!");
	}	
				
	if(RCX_Init(CARD_TYPE_15693STD))
	{
		DispStr_CE(0,3,errstr,DISP_POSITION|DISP_CLRSCR);
		delay_and_wait_key(0,EXIT_KEY_ALL,0);
		RCX_Close();
		return -1;
	}            
        				
	INFO_sub.lPtr = 0;
	INFO_sub.cPtr = 0;
	INFO_sub.startLine = 0;
	while(1)
	{
		clr_scr();
		INFO_sub.iStr = menu_info;
		INFO_sub.mInt = 2;
		INFO_sub.lineMax = 16;
		INFO_sub.sFont = 0;
		INFO_sub.numEnable = 0;		
		INFO_sub.qEvent = EXIT_KEY_F1;		
		INFO_sub.autoexit = 0;			
				
		retint = brow_select(&INFO_sub);	
		switch( retint )
		{
			case 0:
				TI_ICODE2_read(card_flag);
				break;
			case 1:
				TI_ICODE2_write(card_flag);			
				break;
			default:				
				//RCX_Close();
				return -1;					
				break;									
		}
	}
	
	//RCX_Close();
	return 0;		
}


//card_flag==0 :TI
//card_flag==1 :ICODE2
static short TI_ICODE2_read(unsigned char card_flag) 
{
	unsigned char 		databuf[1024];	
	unsigned char 		tmpbuf[30];
	char 			ret;
	short 			retshort;
	unsigned short  	datalen;	
	Tag_Info		tag;	
	unsigned char		trycnt;
	unsigned char		read_ok = 0;
	unsigned char		bno;		
	unsigned char 		hintstr1[20];
	unsigned char 		hintstr2[20];
	unsigned char 		hintstr3[20];
	unsigned char 		hintstr4[20];
	
	if(Get_Language()==LANG_CHN)
	{
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"读错误");
		strcpy(hintstr4,"第%d块内容为:");
	}
	else
	{
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"read error");
		strcpy(hintstr4,"Block %d:");
	}
	
	if( card_flag == 0 )
	{
		if( input_block_num(63,&bno) != 0 )
		{
			return 2;
		}
	}
	else
	{
		if( input_block_num(27,&bno) != 0 )
		{
			return 2;
		}
	}
	
	memset(tag.UID,0,8);	
	SPT_set(1);
	for ( trycnt=11; trycnt>0; )	
	{
		if(!SPT_read())
		{			
			sprintf(tmpbuf,hintstr1,--trycnt);
			DispStr_CE(0,0,tmpbuf,DISP_POSITION|DISP_CLRLINE);
			SPT_set(64);
  		}
  	
		retshort = ISO15693_FindOneCard(0x26, 0x00, &tag);
		if ( retshort==RCX_OK )
		{
			read_ok = 1;
			break;
		}			
	}
	
	if ( !read_ok )
	{		
		DispStr_CE(0,3,hintstr2,DISP_POSITION|DISP_CLRSCR);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
	
	clr_scr();
	
	retshort = ISO15693_ReadOneBlock(0x22,tag.UID,bno,&datalen,databuf);
	if(retshort != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRLINE);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
	
	sprintf(tmpbuf,hintstr4,bno);
	DispStr_CE(0,2,tmpbuf,DISP_POSITION|DISP_CLRLINE);
	sprintf(tmpbuf,"%02X %02X %02X %02X",databuf[0],databuf[1],databuf[2],databuf[3]);
	DispStr_CE(0,4,tmpbuf,DISP_CENTER|DISP_CLRLINE);
	delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
	
	return 0;	
}


//card_flag: 0--TI
//           1--ICODE2
static short TI_ICODE2_write(unsigned char card_flag)
{
	unsigned char 		databuf[1024];	
	unsigned char 		tmpbuf[30];
	char 			ret;
	short 			retshort;
	unsigned short  	datalen;	
	Tag_Info		tag;	
	unsigned char		trycnt;
	unsigned char		read_ok = 0;
	unsigned char		bno;		
	unsigned char 		hintstr1[20];
	unsigned char 		hintstr2[20];
	unsigned char 		hintstr3[20];
	unsigned char 		hintstr4[20];
	
	if(Get_Language()==LANG_CHN)
	{
		strcpy(hintstr1,"请在%d秒内刷卡");
		strcpy(hintstr2,"未读到合法卡!");
		strcpy(hintstr3,"写错误");
		strcpy(hintstr4,"写成功");
	}	
	else
	{
		strcpy(hintstr1,"put card:%d sec");
		strcpy(hintstr2,"no legal card");
		strcpy(hintstr3,"write error");
		strcpy(hintstr4,"write success");
	}	
	
	if( card_flag == 0 )
	{
		if( input_block_num(63,&bno) != 0 )
		{
			return 2;
		}
	}
	else
	{
		if( input_block_num(27,&bno) != 0 )
		{
			return 2;
		}
	}
	
	if(input_block_content(databuf)!=0)
	{
		return 2;
	}
	ASCIIHex2Char(databuf,8);
	
	clr_scr();	
		
	memset(tag.UID,0,8);
	SPT_set(1);
	for ( trycnt=11; trycnt>0; )	
	{
		if(!SPT_read())
		{			
			sprintf(tmpbuf,hintstr1,--trycnt);
			DispStr_CE(0,0,tmpbuf,DISP_POSITION|DISP_CLRLINE);
			SPT_set(64);
  		}
  	
		retshort = ISO15693_FindOneCard(0x26, 0x00, &tag);
		if ( retshort==RCX_OK )
		{
			read_ok = 1;
			break;
		}			
	}
	
	if ( !read_ok )
	{		
		DispStr_CE(0,3,hintstr2,DISP_POSITION|DISP_CLRSCR);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
	
	clr_scr();
		
	if(card_flag==0)
	{
		retshort = ISO15693_WriteOneBlock(0x62,tag.UID,bno,4,databuf);
	}
	else
	{
		retshort = ISO15693_WriteOneBlock(0x22,tag.UID,bno,4,databuf);
	}
	if(retshort != RCX_OK)
	{
		DispStr_CE(0,3,hintstr3,DISP_POSITION|DISP_CLRSCR);		
		delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
		return 1;
	}
		
	DispStr_CE(0,3,hintstr4,DISP_POSITION|DISP_CLRLINE);
	delay_and_wait_key( 0, EXIT_KEY_ALL, 0 );
	
	return 0;	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -