int __stdcall SetCardBalance_NN(HANDLE icdev, long Money, LPCSTR UserPassword,UCHAR sector,unsigned long CardSN,unsigned long SetData)
{ //Money的值表示为多少分钱 , 注意: 充钱可以充入负钱
unsigned long snr;
UINT BasicInfoSec;//基础信息扇区
UCHAR BlockData[16];
UCHAR UserCard_KeyB[6];
union
{
UINT time;//消费流水号
UCHAR ch[4];
}ConsumeSN;
union
{
unsigned long Money;
UCHAR ch[4];
}amount;//存放金额
union
{
unsigned long data;
UCHAR ch[4];
}Wtdata;//写卡时间
…//验证用户密码
BasicInfoSec=SI.sec_assigned.basicinfosec;//基础信息扇区
…判断所给定的扇区信息的正确性
….
…装载消费扇区密码
…装载基础扇区密码
SETTIMEOUT(WaitTime);//寻卡
do
{
if(rf_card(icdev,ALL,&snr) == MI_OK) break;
if(rf_halt(icdev)!=MI_OK) return Reader_Err;
}while(!TIMEOUT);
if (TIMEOUT) return (No_Card);
if(CardSN != snr) return NOT_SPECCARD_ERR;
SetData=SetData&0x0000FFFF;
if( SetData==0x0000){ //手工充值
…
if (rf_write(icdev,sector*4+1,BlockData) != MI_OK) return(Writeblock1_Err);
return 0 ;
}
else {
// 自动充值开始
..只需验证KEY即可
…
Wtdata.data=Wtdata.data&0x0000FFFF;
if(Wtdata.data==0xFFFF)Wtdata.data=0x0000;
if(SetData<=Wtdata.data) return -30; //自动充值已经完成
//新一轮的充值数据
Wtdata.data = SetData;
…准备写新的充值时间
if (rf_write(icdev,BasicInfoSec*4+2,BlockData) != MI_OK) return(WriteCard_Err);
SETTIMEOUT(WaitTime);//寻卡
do
{
if(rf_card(icdev,ALL,&snr) == MI_OK) break;
if(rf_halt(icdev)!=MI_OK) return Reader_Err;
}while(!TIMEOUT);
if (TIMEOUT) return (No_Card);
if(CardSN != snr) return NOT_SPECCARD_ERR;
…需验证KEY可
…写充值数据
return 0 ;
}