//金额显示牌驱动
int com_flag = 0, overrun_flag, *error_code;
int com_port, fd1;
int thr, rbr, ier, lcr, mcr, lsr, msr; //串口控制寄存器地址
/*--------------------------------------------*/
/* COMMUNICATION FUNCTION */
void open_com(int Cport,int baud,int parity,int stopbits,int numbits,int *error_code )
{
int comdata; //串口控制寄存器数据
*error_code = 0;
//错误代码
com_port = Cport; //串口号
comdata = 0;
if ((numbits == 7) || (numbits == 8)) //数据位
comdata = comdata | (numbits-5) ;
else
*error_code = 5;
if ((stopbits == 2) || (stopbits == 1)) //停止位
comdata = comdata | (stopbits-1) << 2 ;
else
*error_code = 4;
if ((parity == 1) || (parity == 3) || (parity == 0)) //奇偶位校验
comdata = comdata | (parity << 3) ;
else
*error_code = 3;
switch (baud){ //波特率选择
case 110: comdata = comdata | 0x00;
break;
case 150: comdata = comdata | 0x20;
break;
case 300: comdata = comdata | 0x40;
break;
case 600: comdata = comdata | 0x60;
break;
case 1200: comdata = comdata | 0x80;
break;
case 2400: comdata = comdata | 0xA0;
break;
case 4800: comdata = comdata | 0xC0;
break;
case 9600 : comdata = comdata | 0xE0;
break;
default : *error_code = 2;
break;
}
if ((Cport <0) || (Cport >1 )) *error_code = 1;
//通信端口设置错误
if (*error_code == 0)
bioscom( 0,comdata,Cport); //初始化串口控制寄存器
if(Cport == 0) {
thr = 0x3f8;
rbr = 0x3f8;
ier = 0x3f9;
lcr = 0x3fb;
mcr = 0x3fc;
lsr = 0x3fd;
msr = 0x3fe;
}
else
{
thr = 0x2f8;
rbr = 0x2f8;
ier = 0x2f9;
lcr = 0x2fb;
mcr = 0x2fc;
lsr = 0x2fd;
msr = 0x2fe;
}
inp(lsr);
/*Reset any pending errors*/
inp(rbr);
/*Read any pending character*/
*error_code = 0;
/*Set error code to 0*/
com_flag = 1;
overrun_flag = 0;
/*Set overrun flag to false */
}
void send_com(int date, int *error_code)
{
int handshake;
long counter;
if (com_flag == 0)
*error_code = 10;
else
{
counter = 0;
handshake = 0x00;
do {
counter += 1;
delay(1);
} while ((((inp(msr) &
handshake) != handshake) ||
((inp(lsr) &
0x20) != 0x20)) &&
(counter < TIMEOUT));
if (counter == TIMEOUT) *error_code = 8;
else
{
outp(thr,date); //输出数据
*error_code = 0;
}
}
}
void InitComm()
{
if(HW_LEDFLAG) {
open_com(HW_LEDPORT,1200,ODD,1,8,error_code);
}
}
void DispFee(int cartype, int money)
{
char tmpstr[3], tmpstr1[2];
int tmpint;
itoa(money, tmpstr, 10);
tmpstr1[0] = tmpstr[0];
tmpint = atoi(tmpstr1);
send_com(tmpint, error_code);
tmpstr1[0] = tmpstr[1] ;
tmpint = atoi(tmpstr1);
send_com(tmpint, error_code);
send_com(cartype,error_code);
}
void ClearLEDFee()
{
send_com(0, error_code);
send_com(0, error_code);
send_com(0, error_code);
}
能否写成delphi程序,用spcomm控件