📄 fujistu.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>
#include <io.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#include "fjt.h"
FILE *f_com;
void fst_dyzb(char *filename, char *dist_file)
{
FILE *f, *f1;
char s[81], s1[120], fs_p[3], fs_a[3];
int i, j, flag_e = 0;
sprintf(fs_p, "%c%c", 0x1c, 0x2e);
sprintf(fs_a, "%c%c", 0x1c, 0x26);
for (i = 0; i < 81; i++)
{
s1[i] = 0x20;
}
f = fopen(filename, "r");
f1 = fopen(dist_file, "w");
while (fgets(s, 80, f) != NULL)
{
j = 0;
flag_e = 0;
fputs(fs_p, f1);
for (i = 0; i < 80; i++)
{
if ((s[i] & 0x80) && (flag_e == 0))
{
s1[j++] = fs_a[0];
s1[j++] = fs_a[1];
flag_e = 1;
}
if (((s[i] & 0x80) == 0) && (flag_e == 1))
{
s1[j++] = fs_p[0];
s1[j++] = fs_p[1];
flag_e = 0;
}
s1[j++] = (char) (s[i] & 0x7f);
}
fputs(s1, f1);
}
sprintf(s1, "%c%c", 0x0a, 0x0d);
fputs(s1, f1);
fclose(f);
fclose(f1);
}
void fuj_outs(char *s, char row, char col)
{
f_com = fopen("COM4", "w");
fprintf(f_com, "%c%c%c%c%s", 0x1f, 0x24, col, row, s);
fclose(f_com);
}
void fuj_cls(void)
{
f_com = fopen("COM4", "w");
fprintf(f_com, "%c", 0x0c);
fclose(f_com);
}
void fuj_total(double ysje)
{
char s[51];
fuj_cls();
sprintf(s, "TOTAL:%14.2f", ysje);
fuj_outs(s, 2, 1);
}
void fuj_chg(double pay, double chg)
{
char s[51];
// int i; zh
fuj_cls();
sprintf(s, "PAY:%15.2f", pay);
fuj_outs(s, 1, 1);
sprintf(s, "CHG:%15.2f", chg);
fuj_outs(s, 2, 1);
}
void fuj_spmx(double sj, double sl, double ysje)
{
char s[51];
// int i; zh
fuj_cls();
sprintf(s, "%7.2fx%-3.0f%8.2f", sj, sl, sj * sl);
fuj_outs(s, 1, 1);
sprintf(s, "TOTAL:%13.2f", ysje);
fuj_outs(s, 2, 1);
}
void fuj_time(char *t)
{
// char s[51]; zh
fuj_outs("YTPOS", 1, 1);
fuj_outs(t, 2, 1);
}
/*
*文件名: CONSCARD.C
*
*描述:
*这个文件主要是为添加pos机的储值卡扣款功能而设置的,主要接口
*均在CONSCARD.H中
*
*作者: lyy
*
*时间: 2005年3月
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "mcs_sr.h"
#include "conscard.h"
#include "user.h"
#include "publ.h"
extern _SPLists *SPLists; //指向本次销售数据的指针
extern int MsgBoxEx(char *caption, int Att);
int getPort();
void balToStr(double money, unsigned char *str);
int checkCcard(double *bal, double bcfk);
int getVerifyPwd(int *pass1,int *pass2,int *pass3);
/*
*这个函数是用于从检查储值卡的接口,并将读出的当前余额
*存入&bal中
*
*返回值:
*
*SUCCESS 0 //从储值卡中扣款成功
*INIT_ERROR -1 //设备初始化失败
*TYPE_ERROR -2 //卡的类型不正确
*RW_ERROR -3 //读写卡操作失败
*BAL_LACK -4 //余额不足:balance lack
*CANCEL -5 //取消操作,提示插入卡时,如果键入ESC,表示放弃此次操作
*NO_CARD -6 //没有插卡
*/
int checkCcard(double *bal, double bcfk)
{
BYTE oriBal[10 + 1] =
{
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
}; //读取卡上40-49位的数据,
BYTE tempBal[10 + 1] =
{
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
}; //临时之用
DWORD baudrate[12] =
{
9600, 115200, 300, 600, 1200, 2400, 4800, 14400, 19200, 28800, 38400, 57600
};//单位:bps
int i = 0;
int j = 0;
int loop = 0;
//初始化读卡器
int port = getPort();
if (port < 0)
return INIT_ERROR;
for (j = 0; j < 12; j++) //12种波特率
{
for (i = port; i <= port; i++) //四个端口逐个测试
{
if (MCS_InitComm((BYTE) i, baudrate[j]) == MCS_SUCCESS) //串口初始化
{
loop = 1;
break;
}
}
if (loop == 1)
break;
if (i == port && j == 11) //全部测试完毕,均失败
{
MCS_ExitComm();
return INIT_ERROR;
}
}
//检查余额是否足够扣除
MCS_LED(0);
MCS_LED(1);
if (MCS_TestDoor() != MCS_SUCCESS)
{
MCS_LED(OFF);
MCS_ExitComm();
return NO_CARD;
}
if (SLE4442_OpenCard(tempBal) != MCS_SUCCESS)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
if (SLE4442_ReadChar(40, 10, oriBal) != MCS_SUCCESS) //原余额已经读出并存储
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
(*bal) = atof(oriBal); //目前使用这个转换已经足够了,注意溢出
if ((*bal) - bcfk < 0)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return BAL_LACK;
}
MCS_LED(0);
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return SUCCESS;
}
/*
*这个函数是用于从储值卡扣款的接口,它将从当前储值卡中扣
*除相应的值。
*
*返回值:
*
*SUCCESS 0 //从储值卡中扣款成功
*INIT_ERROR -1 //设备初始化失败
*TYPE_ERROR -2 //卡的类型不正确
*RW_ERROR -3 //读写卡操作失败
*BAL_LACK -4 //余额不足:balance lack
*CANCEL -5 //取消操作,提示插入卡时,如果键入ESC,表示放弃此次操作
*NO_CARD -6 //没有插卡
*/
int payByCcard(double money)
{
BYTE oriBal[10 + 1] =
{
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
}; //读取卡上40-49位的数据,
BYTE curBal[10 + 1] =
{
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
}; //写入卡上40-49位的数据
BYTE cardNo[CARDNOLEN + 1] =
{
'0', '0', '0', '0', '0', '0', '0', '0', '\0'
}; //备用的卡号
BYTE tempBal[10 + 1] =
{
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
}; //临时之用
double temporibal = 0; //临时保存转换后的原余额
double tempcurbal = 0; //临时保存当前余额
DWORD baudrate[12] =
{
9600, 115200, 300, 600, 1200, 2400, 4800, 14400, 19200, 28800, 38400, 57600
};//单位:bps
int goon = 0; //是否确定扣款
int loop = 0; //是否继续询问,看下面的代码
int i = 0;
int j = 0;
int pass1 = 0;
int pass2 = 0;
int pass3 = 0;
int tmpFlag = -1;
//假定要扣除的非负数;
//初始化读卡器
int port = getPort();
if (port < 0)
return INIT_ERROR;
for (j = 0; j < 12; j++) //12种波特率
{
for (i = port; i <= port; i++) //四个端口逐个测试
{
if (MCS_InitComm((BYTE) i, baudrate[j]) == MCS_SUCCESS) //串口初始化
{
loop = 1;
break;
}
}
if (loop == 1)
break;
if (i == port && j == 11) //全部测试完毕,均失败
{
MCS_ExitComm();
return INIT_ERROR;
}
}
//检查余额是否足够扣除
MCS_LED(0);
MCS_LED(1);
if (MCS_TestDoor() != MCS_SUCCESS)
{
MCS_LED(OFF);
MCS_ExitComm();
return NO_CARD;
}
if (SLE4442_OpenCard(tempBal) != MCS_SUCCESS)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
if (SLE4442_ReadChar(52, CARDNOLEN, cardNo) != MCS_SUCCESS) //get card no
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
if (SLE4442_ReadChar(40, 10, oriBal) != MCS_SUCCESS) //原余额已经读出并存储
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
temporibal = atof(oriBal); //目前使用这个转换已经足够了,注意溢出
if ((tempcurbal = temporibal - money) < 0)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return BAL_LACK;
}
//扣除相应的款项
//暂定40到49位存储余额,余额不能小于0
//格式为 xxxxxxx.xx (包括小数点),达到百万
//数量级,应该够了,否则,就要修改了
//if (SLE4442_VerifyPWD(0xff, 0xff, 0xff) != MCS_SUCCESS)
tmpFlag = getVerifyPwd(&pass1,&pass2,&pass3);
if (tmpFlag == -1)
return RW_ERROR;
// printf("\npass1:%x\npass2:%x\npass3%x\n",pass1,pass2,pass3);
if (SLE4442_VerifyPWD((BYTE)pass1, (BYTE)pass2, (BYTE)pass3) != MCS_SUCCESS)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
balToStr(tempcurbal, curBal); //我找不到合适的库函数,所以...,curBal也存储好了扣后余额
if (SLE4442_WriteChar(40, 10, curBal) != MCS_SUCCESS)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
//检查是否扣除成功
if (SLE4442_ReadChar(40, 10, tempBal) != MCS_SUCCESS)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
if (fabs(atof(tempBal) - tempcurbal) >= 0.01)
{
SLE4442_CloseCard();
MCS_LED(OFF);
MCS_ExitComm();
return RW_ERROR;
}
//完成
for (i = 0; i < MAXCCARD; i++)
{
if (SPLists->fklp.ccard[i].cardno[0] == '\0') //找一个还没有使用的卡
{
strcpy(SPLists->fklp.ccard[i].cardno, cardNo);
SPLists->fklp.ccard[i].pay = money;
SPLists->fklp.ccard[i].curbal = tempcurbal;
break;
}
}
MCS_LED(0);
SLE4442_CloseCard();
MCS_ExitComm();
return SUCCESS;
}//payByCcard()
/*
*这个函数将传入的money转化为符合存储卡格式的
*unsigned char 字符串存入str指向的字符串,
*money不应该大于百万级别,同时只处理小数点后
*两位,而传入的str一般长度应为11位,最后一位
*总是'\0',便于输出,同时,写入str前十位的格式
*应为:xxxxxxx.xx (包括小数点)
*/
void balToStr(double money, unsigned char *str)
{
//方法是笨了点,可是还管用,^_^
long intm = (long)money;
double decm = money - intm;
str[0] = (unsigned char) (intm / 1000000 % 10 + 48);
str[1] = (unsigned char) (intm / 100000 % 10 + 48);
str[2] = (unsigned char) (intm / 10000 % 10 + 48);
str[3] = (unsigned char) (intm / 1000 % 10 + 48);
str[4] = (unsigned char) (intm / 100 % 10 + 48);
str[5] = (unsigned char) (intm / 10 % 10 + 48);
str[6] = (unsigned char) (intm % 10 + 48);
str[7] = (unsigned char) ('.');
str[8] = (unsigned char) ((long)(decm * 10) % 10 + 48);
str[9] = (unsigned char) ((long)(decm * 100) % 10 + 48);
return ;
}//balToStr()
/*
*get port num for device initiation
* port >= 0
*return :
*-1:error
*/
int getPort()
{
int portCh = 0;
int flag = 1;
int port = -1;
//open file
FILE *fp = 0;
fp = fopen("port.txt","r");
if (fp == 0)
return -1;
while (((portCh = fgetc(fp)) != EOF) && (flag == 1))
{
if (portCh >= '0' && portCh <= '9')
{
if (port == -1)
port = 0;
port = port * 10 + portCh - '0';
}
else
flag = 0;
}
// printf("return port = %d",port);
if (port < 0)
{
fclose(fp);
return -1;
}
else
{
fclose(fp);
return port;
}
}
/*
*-1:error
*0:success
*/
int getVerifyPwd(int *pass1,int *pass2,int *pass3)
{
FILE *fp = 0;
int flag = EOF;
fp = fopen("pwd","r");
if (fp == 0)
return -1;
flag = fscanf(fp,"%x,%x,%x",pass1,pass2,pass3);
if (flag == EOF)
{
fclose(fp);
return -1;
}
else
{
fclose(fp);
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -