www.pudn.com > CPPstar.rar > star-i1.40.cpp


#include 
#include 
 
#include "../linux/abds.h" 
#include "../abds4win/driver_printstr.h" 
 
#include "device.h" 
#include "portools.cpp" 
 
 
PRT_star star ;	/* 创建star打印机类的对象 */ 
 
char * getMajorName( ) 
{ 
	return MAJOR_NAME ; 
} 
 
typedef struct 
{ 
	PRINTSTR_PDO majorPDO ; 
 
	// config data for pr2 driver 
	// middle data for pr2 driver 
} PR2_PRINTSTR_PDO, *PPR2_PRINTSTR_PDO ; 
 
#ifndef _LINUX_ 
	__declspec(dllexport) PPDO addDevice( char* minor ) ;	//for win32 
#else 
 extern "C" { PPDO addDevice( char* minor );} 
#endif 
 
 
/* 以下函数是提供给应用使用的标准方法。 */ 
/* ------------------------------------------------------------------------- */ 
 
int printer_exchange( PPDO pdo, char *buf, int length, int control_mode ) 
{ 
	return( star.printer_exchange( pdo, buf,length, control_mode ) ) ; 
} 
 
int get_answer( PPDO pdo, int ans_type ) 
{ 
	return 0;//( star.get_answer( pdo, ans_type ) ) ;	/* 取打印机状态方法:开放给应用(交易)的方法 */ 
} 
 
/* ------------------------------------------------------------------------- */ 
 
 
/* 以下是为了兼容北京银行AB而提供的方法。 */ 
/* ------------------------------------------------------------------------- */ 
 
int eject( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x0c", 1, 0 ) ; 
} 
 
int change_line( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x0d\x0a", 2, 0 ) ; 
} 
 
int nextLine( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x0d\x0a", 2, 0 ) ; 
} 
 
int resetRowSpacing( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x1b\x03\x1a", 3, 0 ) ; 
} 
 
int setColSpacing( PPDO pdo, int unit ) 
{ 
	char buff[8] ; 
	 
	sprintf( buff, "\x1b\x01%c", 180/unit ) ; 
	return printer_exchange( pdo, buff, 3, 0 ) ;	 
} 
 
int setDoubleHeight( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x1b\x05\x31", 3, 0 ) ; 
} 
 
int unsetDoubleHeight( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x1b\x05\x30", 3, 0 ) ; 
} 
 
int setDoubleWidth( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x1b\x06\x31", 3, 0 ) ; 
} 
 
int unsetDoubleWidth( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x1b\x06\x30", 3, 0 ) ; 
} 
 
int setRowSpacing_120( PPDO pdo, int unit ) 
{ 
	char buff[8] ; 
	 
	sprintf( buff, "\x1b\x03%c", unit ) ; 
	return printer_exchange( pdo, buff, 3, 0 ) ; 
} 
 
int setTripleHeight( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x1b\x05\x31", 3, 0 ) ; 
} 
 
int unsetTripleHeight( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x1b\x05\x30", 3, 0 ) ; 
} 
 
int changePage( PPDO pdo ) 
{ 
	return printer_exchange( pdo, "\x0c", 1, 0 ) ; 
} 
 
int setPaperLength( PPDO pdo, int length ) 
{ 
	char param[8] ; 
  	 
	sprintf( param, "\x1b\x08%c", length ) ;  
	return printer_exchange( pdo, param, 3, 0 ) ; 
} 
 
int setTop( PPDO pdo, int top ) 
{ 
	char res[16] ; 
	 
	sprintf( res, "\x1b\x2c%c", top ) ; 
	return printer_exchange( pdo, res, 3, 0 ) ; 
} 
 
char * sendRequest( PPDO pdo, char * request ) 
{ 
	return( request ) ; 
} 
     
int setHorizontalLocation( PPDO pdo, int loc, char * unit ) 
{ 
	char res[16] ; 
	 
	sprintf( res, "\x1b\x4c%c", loc ) ; 
	return printer_exchange( pdo, res, 3, 0 ) ; 
} 
     
int setVerticalLocation( PPDO pdo, int loc, char * unit ) 
{ 
	char res[16] ; 
	 
	loc=loc+1 ; 
	sprintf( res, "\x1b\x4a%c", loc ) ; 
	return printer_exchange( pdo, res, 3, 0 ) ; 
} 
     
int setRelativeVerticalLocation( PPDO pdo, int loc ) 
{ 
	char res[16] ; 
	 
	sprintf( res, "\x1b\x4b%c", loc ) ; 
	return printer_exchange( pdo, res, 3, 0 ) ; 
} 
 
char * checkPaper( PPDO pdo ) 
{ 
	return PAPER_STATUS_HAS_PAPER ; 
} 
 
char * getPrinterStatus( PPDO pdo ) 
{ 
	return STATUS_OK ; 
} 
 
int init( PPDO pdo ) 
{ 
	int i=0 ; 
	 
	i=printer_exchange( pdo, "\x1b\x08\x0b", 3, 0 ) ; 
	return i ; 
} 
 
/////////////////////////////////////// 
int setHorizontalCompress( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int unsetHorizontalCompress( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setTripleWidth( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int unsetTripleWidth( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setNegative( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setPositive( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setNegative1( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setPositive1( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setNegative2( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setPositive2( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setLeftTurn( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setRightTurn( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int clearTurn( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setUpLine( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int clearUpLine( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setDownLine(PPDO pdo) 
{ 
	return 0 ; 
} 
 
int clearDownLine( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setUpDownLine( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int clearUpDownLine( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setUpMark( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int clearUpMark( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setDownMark( PPDO pdo ) 
{ 
	return 0 ; 
}  
    
int clearDownMark( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setFont( PPDO pdo, char* font ) 
{ 
	return 0 ; 
} 
 
int unsetFont( PPDO pdo, char* font ) 
{ 
	return 0 ; 
} 
 
int reset( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int clearErrors( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int selectMode( PPDO pdo, char* mode ) 
{ 
	return 0 ; 
} 
 
int selectDocHandMode( PPDO pdo, char* mode ) 
{ 
	return 0 ; 
} 
 
int setReturn( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setChinese( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int clearChinese( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int halfCorner( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int fullCorner( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setPR( PPDO pdo ) 
{ 
	return 0 ; 
} 
 
int setLeftMargin( PPDO pdo, int margin ) 
{ 
	return 0 ; 
} 
 
int setBottom( PPDO pdo, int bottom ) 
{ 
	return 0 ; 
} 
 
char * measuerPaperSize( PPDO pdo ) 
{ 
	return NULL ; 
} 
 
int setPaperType( PPDO pdo, char* type ) 
{ 
	return 0 ; 
} 
 
////////////////////////////////////////////////// 
PPDO addDevice( char * minor ) 
{ 
	PPR2_PRINTSTR_PDO pdo ; 
	 
	pdo = (PPR2_PRINTSTR_PDO)malloc( sizeof(PR2_PRINTSTR_PDO) ) ;   
	if (pdo == NULL) 
		return NULL ; 
 
	((PPDO)pdo)->getMajorName = getMajorName ; 
	// print_str函数的原型已经发生变化,请相应更改,否则这里编译不过去   
	((PPRINTSTR_PDO)pdo)->printer_exchange = printer_exchange ; 
			 
	((PPRINTSTR_PDO)pdo)->init = init ; 
	((PPRINTSTR_PDO)pdo)->eject = eject ; 
	((PPRINTSTR_PDO)pdo)->change_line = change_line ; 
	((PPRINTSTR_PDO)pdo)->nextLine = nextLine ; 
	((PPRINTSTR_PDO)pdo)->resetRowSpacing = resetRowSpacing ; 
	((PPRINTSTR_PDO)pdo)->setColSpacing = setColSpacing ; 
	((PPRINTSTR_PDO)pdo)->setDoubleHeight = setDoubleHeight ; 
	((PPRINTSTR_PDO)pdo)->unsetDoubleHeight = unsetDoubleHeight ; 
	((PPRINTSTR_PDO)pdo)->setDoubleWidth = setDoubleWidth ; 
	((PPRINTSTR_PDO)pdo)->unsetDoubleWidth = unsetDoubleWidth ; 
	//((PPRINTSTR_PDO)pdo)->setHorizontalCompress = setHorizontalCompress ; 
	((PPRINTSTR_PDO)pdo)->setRowSpacing_120 = setRowSpacing_120 ; 
	//((PPRINTSTR_PDO)pdo)->unsetHorizontalCompress = unsetHorizontalCompress ; 
	((PPRINTSTR_PDO)pdo)->setTripleHeight = setTripleHeight ; 
	((PPRINTSTR_PDO)pdo)->unsetTripleHeight = unsetTripleHeight ; 
	((PPRINTSTR_PDO)pdo)->setTripleWidth = setTripleWidth ; 
	((PPRINTSTR_PDO)pdo)->unsetTripleWidth = unsetTripleWidth ; 
	((PPRINTSTR_PDO)pdo)->setNegative = setNegative ; 
	((PPRINTSTR_PDO)pdo)->setPositive = setPositive ; 
	((PPRINTSTR_PDO)pdo)->setNegative1 = setNegative1 ; 
	((PPRINTSTR_PDO)pdo)->setPositive1 = setPositive1 ; 
	((PPRINTSTR_PDO)pdo)->setNegative2 = setNegative2 ; 
	((PPRINTSTR_PDO)pdo)->setPositive2 = setPositive2 ; 
	((PPRINTSTR_PDO)pdo)->setLeftTurn = setLeftTurn ; 
	((PPRINTSTR_PDO)pdo)->setRightTurn = setRightTurn ; 
	((PPRINTSTR_PDO)pdo)->clearTurn = clearTurn ; 
	((PPRINTSTR_PDO)pdo)->setUpLine = setUpLine ; 
	((PPRINTSTR_PDO)pdo)->clearUpLine = clearUpLine ; 
	((PPRINTSTR_PDO)pdo)->setDownLine = setDownLine ; 
	((PPRINTSTR_PDO)pdo)->clearDownLine = clearDownLine ; 
	((PPRINTSTR_PDO)pdo)->setUpDownLine = setUpDownLine ; 
	((PPRINTSTR_PDO)pdo)->clearUpDownLine = clearUpDownLine ; 
	((PPRINTSTR_PDO)pdo)->setUpMark = setUpMark ; 
	((PPRINTSTR_PDO)pdo)->clearUpMark = clearUpMark ; 
	((PPRINTSTR_PDO)pdo)->setDownMark=setDownMark ; 
	((PPRINTSTR_PDO)pdo)->clearDownMark=clearDownMark ; 
	((PPRINTSTR_PDO)pdo)->setFont = setFont ; 
	((PPRINTSTR_PDO)pdo)->unsetFont = unsetFont ; 
	((PPRINTSTR_PDO)pdo)->reset = reset ; 
	((PPRINTSTR_PDO)pdo)->clearErrors = clearErrors ; 
	((PPRINTSTR_PDO)pdo)->selectMode = selectMode ; 
	((PPRINTSTR_PDO)pdo)->selectDocHandMode = selectDocHandMode ; 
	((PPRINTSTR_PDO)pdo)->setReturn = setReturn ; 
	((PPRINTSTR_PDO)pdo)->changePage = changePage ; 
	((PPRINTSTR_PDO)pdo)->setChinese = setChinese ; 
	((PPRINTSTR_PDO)pdo)->clearChinese = clearChinese ; 
	((PPRINTSTR_PDO)pdo)->halfCorner = halfCorner ; 
	((PPRINTSTR_PDO)pdo)->fullCorner = fullCorner ; 
	((PPRINTSTR_PDO)pdo)->setPR = setPR ; 
	((PPRINTSTR_PDO)pdo)->setPaperLength = setPaperLength ; 
	((PPRINTSTR_PDO)pdo)->setLeftMargin = setLeftMargin ; 
	((PPRINTSTR_PDO)pdo)->setTop = setTop ; 
	((PPRINTSTR_PDO)pdo)->setBottom = setBottom ; 
	((PPRINTSTR_PDO)pdo)->sendRequest = sendRequest ; 
	((PPRINTSTR_PDO)pdo)->setHorizontalLocation = setHorizontalLocation ; 
	((PPRINTSTR_PDO)pdo)->setVerticalLocation = setVerticalLocation ; 
	((PPRINTSTR_PDO)pdo)->setRelativeVerticalLocation = setRelativeVerticalLocation ; 
	((PPRINTSTR_PDO)pdo)->setPaperType = setPaperType ; 
	((PPRINTSTR_PDO)pdo)->checkPaper = checkPaper ; 
	((PPRINTSTR_PDO)pdo)->measuerPaperSize = measuerPaperSize ; 
	((PPRINTSTR_PDO)pdo)->getPrinterStatus = getPrinterStatus ; 
 	((PPRINTSTR_PDO)pdo)->getPortType=getPortType; 
 	((PPRINTSTR_PDO)pdo)->checkPrinterStatus=checkPrinterStatus; 
 	((PPRINTSTR_PDO)pdo)->get_answer = get_answer ; 
	return (PPDO)pdo ; 
}