RFID-recharge consumption system


Preface

       Radio Frequency Identification (RFID) is the abbreviation of Radio Frequency Identification.
       The principle is non-contact data communication between the reader and the tag to achieve the purpose of identifying the target. RFID has a wide range of applications. Typical applications include animal chips, car chip anti-theft devices, access control, parking lot control, production line automation, and material management.


Tip: The following is the content of this article, the following cases are for reference

One, the compilation environment

       This system is based on VC++6.0 version. Readers who have not installed this software can download the software through Baidu Netdisk.
       Link: https://pan.baidu.com/s/1_pUq7swULst7plceOAQpSA
       Extraction code: l0x5

Second, realize the recharge consumption system

1. Create a project

        Open the software -> file -> new, you can see the interface below, follow the prompts in turn to complete the creation of the project! ! !
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

2. Add mwf32 related API documentation

(1) Copy the three files mwrf32.* under the API folder to the folder of the project you created.
Insert picture description here
   Related documents have been put into the entire system project! ! !

(2) Add header file
Insert picture description here
(3) Project -> Settings -> Connection -> Object/Library Module
Insert picture description here

3. Introduction to commonly used functions

    Function Description
rf_usbinit() Initialize the USB communication
rf_get_status() Get the version number
rf_load_key() Download the authorization password to the reader
rf_beep() Buzzer
rf_card() Find card
rf_authentication() Authentication
rf_write() Write card
rf_read() Read card
rf_halt() Terminate card operation
rf_exit() Close the serial port

4. Build the interface

   Select static text, edit box, button, list box through controls, build the following interface
Insert picture description here

5. Set variables

       Right click->Create Class Wizard->Member variables->Add Variable, select variable name and variable type
Insert picture description here

6. Write a program

       Double-click to read the card, initialize the information, recharge, and directly write the program after consumption.

(1) [Define global variables] The corresponding code is as follows:

	HANDLE icdev;
	int st;
	int sector=1;

	CString str1;	//余额
	CString str2;	//充值金额
	CString str3;	//消费金额

(2) [Reading card] The corresponding codes are as follows:

	icdev=rf_usbinit();
	if (icdev>0) {
    
    list.AddString("设备连接成功!");}
	else {
    
    list.AddString("连接失败!");}

	unsigned long snr;
	st=rf_card(icdev,1,&snr);
	if(st!=0) {
    
    list.AddString("请放置卡片!!!");}

    st=rf_authentication(icdev,0,sector);
	if(st!=0) {
    
    list.AddString("认证失败!");}

	//UpdateData();

	unsigned char databuff[17];
	ZeroMemory(databuff,17); 
	st=rf_read(icdev,sector*4,databuff);
	if(st==0) {
    
    list.AddString((char*)databuff);xingming=databuff;}

	st=rf_read(icdev,sector*4+1,databuff);
	if(st==0) {
    
    list.AddString((char*)databuff);xuehao=databuff;}

	st=rf_read(icdev,sector*4+2,databuff);
	str1=databuff;	//类型转换
	if(st==0) {
    
    list.AddString((char*)databuff);yue=atof(str1);}

	UpdateData(false);

	st=rf_halt(icdev);
	st=rf_exit(icdev); 
	//if(st==0) {list.AddString("断开连接!");}

(3) [Initialization information] The corresponding code is as follows:

	icdev=rf_usbinit();
	if (icdev>0) {
    
    list.AddString("设备连接成功!");}
	else {
    
    list.AddString("连接失败!");}

	unsigned long snr;
	st=rf_card(icdev,1,&snr);
	if(st!=0) {
    
    list.AddString("请放置卡片!!!");}

    st=rf_authentication(icdev,0,sector);
	if(st!=0) 
	{
    
    
		list.AddString("认证失败!");
	}
	
	else
	{
    
    
		UpdateData();
		str1.Format(_T("%.2f"),yue);	//余额

		char* data1=xingming.GetBuffer(xingming.GetLength());	//姓名
		char* data2=xuehao.GetBuffer(xuehao.GetLength());	//学号
		char* data3=str1.GetBuffer(str1.GetLength());	//余额

		st=rf_write(icdev,sector*4,(unsigned char*)data1);
		if(st==0) {
    
    list.AddString("写姓名成功!");}
		else {
    
    list.AddString("写姓名失败!");}

		st=rf_write(icdev,sector*4+1,(unsigned char*)data2);
		if(st==0) {
    
    list.AddString("写学号成功!");}
		else {
    
    list.AddString("写学号失败!");}

		st=rf_write(icdev,sector*4+2,(unsigned char*)data3);
		if(st==0) {
    
    list.AddString("写余额成功!");}
		else {
    
    list.AddString("写余额失败!");}

		unsigned char databuff[17];
		ZeroMemory(databuff,17);
		st=rf_read(icdev,sector*4,databuff);
		if(st==0) {
    
    list.AddString((char*)databuff);}
		st=rf_read(icdev,sector*4+1,databuff);
		if(st==0) {
    
    list.AddString((char*)databuff);}
		st=rf_read(icdev,sector*4+2,databuff);
		if(st==0) {
    
    list.AddString((char*)databuff);}

		UpdateData(false);
	}

	st=rf_halt(icdev);
	st=rf_exit(icdev); 
	//if(st==0) {list.AddString("断开连接!");}

(4) [Recharge] The corresponding code is as follows:

	icdev=rf_usbinit();

	unsigned long snr;
	st=rf_card(icdev,1,&snr);
	if(st!=0) {
    
    list.AddString("请放置卡片!!!");}

    st=rf_authentication(icdev,0,sector);
	if(st!=0) {
    
    list.AddString("认证失败!");}

	else	//读卡才能进行操作
	{
    
    
		UpdateData();
		yue=yue+chongzhi;	//充值
		chongzhi=0;	//充值置零
		str1.Format(_T("%.2f"),yue);	//余额
		str2.Format(_T("%.2f"),chongzhi);  //充值置零

		char* data3=str1.GetBuffer(str1.GetLength());	//余额
		st=rf_write(icdev,sector*4+2,(unsigned char*)data3);
		if(st==0) {
    
    list.AddString("充值成功!");}
		else {
    
    list.AddString("充值失败!");}

		unsigned char databuff[17];
		ZeroMemory(databuff,17);
		st=rf_read(icdev,sector*4+2,databuff);
		if(st==0) {
    
    list.AddString((char*)databuff);}

		UpdateData(false);
    }
	st=rf_halt(icdev);
	st=rf_exit(icdev); 
	//if(st==0) {list.AddString("断开连接!");}

(5) [Consumption] The corresponding code is as follows:

	icdev=rf_usbinit();
	unsigned long snr;
	st=rf_card(icdev,1,&snr);
	if(st!=0) {
    
    list.AddString("请放置卡片!!!");}

    st=rf_authentication(icdev,0,sector);
	if(st!=0) {
    
    list.AddString("认证失败!");}

	else	//读卡才能操作
	{
    
    
		UpdateData();
		yue=yue-xiaofei;	//消费
		xiaofei=0;	//消费置零
		str1.Format(_T("%.2f"),yue);	//消费
		str3.Format(_T("%.2f"),xiaofei);	//消费置零

		char* data3=str1.GetBuffer(str1.GetLength());	//余额
		st=rf_write(icdev,sector*4+2,(unsigned char*)data3);
		if(st==0) {
    
    list.AddString("消费成功!");}
		else {
    
    list.AddString("消费失败!");}

		unsigned char databuff[17];
		ZeroMemory(databuff,17);
		st=rf_read(icdev,sector*4+2,databuff);
		if(st==0) {
    
    list.AddString((char*)databuff);}

		UpdateData(false);
	}
	st=rf_halt(icdev);
	st=rf_exit(icdev); 
	//if(st==0) {list.AddString("断开连接!");}

You can download the project files of this system through Baidu network disk.
       Link: https://pan.baidu.com/s/1de7lseleJFXQEJ2XosY0Pg
       Extraction code: 4na5


to sum up

       First of all, as a junior, I really feel so tired as a junior, as if I can't finish it. Haha, I really should make a complaint! ! ! As a small test of our RFID course, this recharge consumption system feels quite meaningful. It allows us to understand the basic principles of the so-called "swiping card" in our lives, and it really gives me the frog at the bottom of the well. I am about to graduate, and I wrote this blog to commemorate the passing RFID course. Maybe it's really goodbye~bye
Insert picture description here
can't reprint without my permission!!!

Guess you like

Origin blog.csdn.net/weixin_44935259/article/details/111392684