⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 print.c.bak

📁 用于小商品消费的SMS消费机程序
💻 BAK
📖 第 1 页 / 共 2 页
字号:
#include <api.h>
#include <console.h>
#include "string.h"
#include "stdio.h"
#include "Ppos.h"

////************打印机的初始化*************************/
//unsigned char InitPrinter[2] = {0x1B, 0x40};//初始化打印机,清除缓冲区
//unsigned char LeftPrinterHead[2] = {0x1B, 0x3C};//打印头置左
//unsigned char PrintNoFeed[1] = {0x0D};//打印缓冲区并送纸
//unsigned char PrintAndFeed[1] = {0x0A};//打印缓冲区并送纸
//unsigned char SetPrinterModeEN[3] = {0x1B, 0x21, 0x00};//设置英文打印模式
//unsigned char SetPrinterTitle[3] = {0x1C, 0x21, 0x08};//设置中文标题打印模式
//unsigned char SetPrinterModeHZ[3] = {0x1C, 0x21, 0x00};//设置中文打印模式
//unsigned char MoveToNextHori[1] = {0x09};//移动到下一个表格位置
//unsigned char SetHoriPosition[35] = {0x1B, 0x44, 0x00, 0x00, 0x00};//设置表格
//unsigned char SetEmphasized[3] = {0x1B, 0x44, 0x00};//设置粗体,0为关闭,1为打开
//unsigned char PrintAndFeedL[3] = {0x1B, 0x4A, 0x00};//打印并进纸6+24*line
//unsigned char PrintAndRFeedL[3] = {0x1B, 0x4B, 0x00};//打印并退纸6+24*line
//unsigned char SetPanelButton[4] = {0x1b, 0x63, 0x35, 0x00};//面板按钮是否有效,0为有效,1为无效
//unsigned char PrintAndFeedN[3] = {0x1B, 0x64, 0x00};//打印并进纸N行
//unsigned char PrintAndRFeedN[3] = {0x1B, 0x65, 0x00};//打印并退纸N行
//unsigned char CutPaper1[2] = {0x1B, 0x69};//部分切纸1
//unsigned char CutPaper2[2] = {0x1B, 0x6d};//部分切纸2
//unsigned char GetPrintStatus[2] = {0x1B, 0x76};//获取打印机状态
//unsigned char SetPrintDir[3] = {0x1B, 0x7B, 0x00};//设置进纸方向,0为向下,1为向上
//unsigned char EnableSelectHZ[2] = {0x1C, 0x26};//选择汉字打印
//unsigned char DisableSelectHZ[2] = {0x1C, 0x2E};//取消汉字打印
//unsigned char SetHZMode[3] = {0x1C, 0x43, 0x01};//设置汉字编码方式
//unsigned char SetHZSpace[4] = {0x1C, 0x53, 0x04, 0x04};//选择汉字间距
//unsigned char SetQuadrupleHZ[3] = {0x1C, 0x57, 0x00};//设置四倍体积汉字,0为关闭,1为打开
//unsigned char SetPrinterColor[3] = {0x1B, 0x72, 0x00};//设置打印色彩,0为黑色,1为红色


//************打印机的初始化************************
unsigned char InitPrinter[2] = {0x1B, 0x40};//初始化打印机,清除缓冲区
//unsigned char LeftPrinterHead[2] = {0x1B, 0x3C};//打印头置左
//unsigned char PrintNoFeed[1] = {0x0D};//打印缓冲区并送纸
unsigned char PrintAndFeed[1] = {0x0A};//打印缓冲区并送纸
unsigned char SetPrinterModeEN[3] = {0x1B, 0x21, 0x00};//设置英文打印模式
unsigned char SetPrinterTitle[3] = {0x1B, 0x21, 0x10};//设置中文标题打印模式
unsigned char SetPrinterModeHZ[3] = {0x1B, 0x21, 0x00};//设置中文打印模式
//unsigned char MoveToNextHori[1] = {0x09};//移动到下一个表格位置
//unsigned char SetHoriPosition[35] = {0x1B, 0x44, 0x00, 0x00, 0x00};//设置表格
//unsigned char SetEmphasized[3] = {0x1B, 0x44, 0x00};//设置粗体,0为关闭,1为打开
unsigned char PrintAndFeedL[3] = {0x1B, 0x4A, 0x00};//打印并进纸6+24*line
//unsigned char PrintAndRFeedL[3] = {0x1B, 0x4B, 0x00};//打印并退纸6+24*line
//unsigned char SetPanelButton[4] = {0x1b, 0x63, 0x35, 0x00};//面板按钮是否有效,0为有效,1为无效
//unsigned char PrintAndFeedN[3] = {0x1B, 0x64, 0x00};//打印并进纸N行
//unsigned char PrintAndRFeedN[3] = {0x1B, 0x65, 0x00};//打印并退纸N行
unsigned char CutPaper1[2] = {0x1B, 0x69};//部分切纸1
unsigned char CutPaper2[2] = {0x1B, 0x6d};//部分切纸2
unsigned char GetPrintStatus[2] = {0x1B, 0x76};//获取打印机状态
//unsigned char SetPrintDir[3] = {0x1B, 0x7B, 0x00};//设置进纸方向,0为向下,1为向上
//unsigned char EnableSelectHZ[2] = {0x1C, 0x26};//选择汉字打印
//unsigned char DisableSelectHZ[2] = {0x1C, 0x2E};//取消汉字打印
//unsigned char SetHZMode[3] = {0x1C, 0x43, 0x01};//设置汉字编码方式
//unsigned char SetHZSpace[4] = {0x1C, 0x53, 0x04, 0x04};//选择汉字间距
//unsigned char SetQuadrupleHZ[3] = {0x1C, 0x57, 0x00};//设置四倍体积汉字,0为关闭,1为打开
//unsigned char SetPrinterColor[3] = {0x1B, 0x72, 0x00};//设置打印色彩,0为黑色,1为红色

extern struct sttMenu stPrintReport;

void OpenPrinter()
{
	typ_msg_word msg_buffer;
        typ_UART_stat_word Ustat;
	unsigned char recBuf[1024];
	unsigned char sendBuf[6];
	unsigned short checksum=0,recLen=0; 
		
	SPT_set(64);
	UART_disconnect();
	
	msg_buffer.s_word = sys_msg(SM_STAY_AWAKE);
	
	UART_init(UART_ON | UART_232_ON | UART_8_DATA_BITS | UART_BAUD_9600);
	UART_fcntl(UART_fcntl(UART_F_INQ) | UART_F_NO_CTS);
	delay_n_ms(3);
	
	SPT_set(64);	
}

void ClosePrinter()
{
	typ_UART_stat_word Ustat;
	
	Ustat.l_word = UART_stat();
	if (Ustat.bits.UART_on)
	{
		UART_init(UART_OFF);
		sys_msg(SM_GOTO_SLEEP);
	}
}

void InitlizePrinter(void)
{
	unsigned  int  status;
	unsigned  char i;
	
	UART_puts(InitPrinter, 2);

	UART_puts(SetPrinterModeEN, 3);

	UART_puts(SetPrinterModeHZ, 3);

	//UART_puts(SetHZMode, 2);

	//UART_puts(SetHZSpace, 4);

	//UART_puts(EnableSelectHZ, 2);
//	for(i=0;i<2;i++)       
//		UART_send_char(*(InitPrinter+i));
//
//	for(i=0;i<3;i++)       
//		UART_send_char(*(SetPrinterModeEN+i));
//
//	for(i=0;i<3;i++)       
//		UART_send_char(*(SetPrinterModeHZ+i));
//
//	for(i=0;i<2;i++)       
//		UART_send_char(*(SetHZMode+i));
//
//	for(i=0;i<4;i++)       
//		UART_send_char(*(SetHZSpace+i));
//
//	for(i=0;i<2;i++)       
//		UART_send_char(*(EnableSelectHZ+i));
}

void  Print_Cut(unsigned char mode)
{
	unsigned  int  status;
	unsigned  char i;

	if(mode==0)
		UART_puts(CutPaper1, 2);
	else
		UART_puts(CutPaper2, 2);
//	for(i=0;i<2;i++)
//	{
//		if(mode==0)
//			UART_send_char(*(CutPaper1+i));
//		else
//			UART_send_char(*(CutPaper2+i));
//	}
}	   

//void Printer_CreateTable(unsigned char TableNum, unsigned char *TableWidth)
//{
//	unsigned int  status;
//	unsigned char i;
//	unsigned char buf[35];
//
//	buf[0] = SetHoriPosition[0];
//	buf[1] = SetHoriPosition[1];
//	memcpy(buf+2, TableWidth, TableNum);
//	buf[2+TableNum] = 0x00;
//
//	UART_puts(buf, 3+TableNum);
////	for(i=0;i<3+TableNum;i++)       
////		UART_send_char(*(buf+i));
//
//}
//
//void Printer_MoveTable(unsigned char n)
//{
//	unsigned  int  status;
//	unsigned char i;
//
//	for(i=0;i<n;i++)
//		UART_send_char(*(MoveToNextHori));
//}


void Print_Line(unsigned char *ptr,unsigned char size)  //在一行中打印
{
	unsigned  int  status;
	unsigned  char i;

//	if((mode>>1)&0x01 == 1)
//	{
//		UART_puts(EnableSelectHZ, 2);
////		for(i=0;i<2;i++)       
////			UART_send_char(*(EnableSelectHZ+i));
//	}
//	else
//	{
//		UART_puts(DisableSelectHZ, 2);
////		for(i=0;i<2;i++)       
////			UART_send_char(*(DisableSelectHZ+i));
//	}

	UART_puts(ptr, size);
//	for(i=0;i<size;i++)
//	{
//		UART_send_char(*(ptr+i));        //发送要打印数据处理
//	}
//	if(mode&0x01 == 1)
		UART_send_char(*(PrintAndFeed));
//	else
//		UART_send_char(*(PrintNoFeed));
}	   

void  Print_Title(unsigned char *title, unsigned char size)
{
	unsigned  int  status;
	unsigned  char i;

	UART_puts(SetPrinterTitle, 3);
//	for(i=0;i<3;i++)
//	{
//		UART_send_char(*(SetPrinterTitle+i));
//	}
//	Print_SetColor(1);
	Print_Line(title, size);
//	Print_SetColor(0);
	UART_puts(SetPrinterModeHZ, 3);
//	for(i=0;i<3;i++)
//	{
//		UART_send_char(*(SetPrinterModeHZ+i));
//	}
}

//void  Print_SetColor(unsigned char color)
//{
//	unsigned  int  status;
//	unsigned  char i;
//
//	if(color==0)
//		SetPrinterColor[2] = 0;
//	else
//		SetPrinterColor[2] = 1;
//	UART_puts(SetPrinterColor, 3);
////	for(i=0;i<3;i++)
////	{
////		UART_send_char(*(SetPrinterColor+i));
////	}
//}

void PrintTable()
{
	unsigned char buf[40],i;

	OpenPrinter();
	InitlizePrinter();
	
	Print_Line(stPrintReport.pTitle, 17);		
	for(i=0;i<stPrintReport.cItemNum;i++)
	{
		Print_Line(stPrintReport.ppItem[i], 17);		
	}
	ClosePrinter();	
		

//	if(mode==0)
//	{
//		buf[0] = 1;
//		buf[1] = 7;
//		Printer_CreateTable(2, buf);
//		Printer_MoveTable(2);		
//		Print_Title((unsigned char*)"", 22);
//
//		Print_SetColor(1);
//		Print_Line((unsigned char*)"=================================", 33, 1);
//		Print_SetColor(0);
//
//		buf[0] = 1;
//		buf[1] = 7;
//		Printer_CreateTable(2, buf);
//		Printer_MoveTable(1);
//		Print_Line((unsigned char*)"客户卡号", 8, 2);
//		Printer_MoveTable(2);
//		memset(buf, 0 ,40);
//		sprintf(buf, ": %012ld", CardInfo.CardNo);
//		Print_Line(buf, 14, 1);
//
//		buf[0] = 1;
//		buf[1] = 7;
//		buf[2] = 18;
//		buf[3] = 22;
//		Printer_CreateTable(4, buf);
//		Printer_MoveTable(1);
//		Print_Line((unsigned char*)"充值机号", 8, 2);
//		Printer_MoveTable(2);
//		memset(buf, 0 ,40);
//		buf[20] = DeviceNo[3];
//		buf[21] = DeviceNo[2];
//		buf[22] = DeviceNo[1];
//		buf[23] = DeviceNo[0];
//		sprintf(buf, ": %8s", BCD2ASC(buf+20,4));
//		Print_Line(buf, 10, 0);
//		Printer_MoveTable(3);
//		Print_Line((unsigned char*)"流水号", 6, 2);
//		Printer_MoveTable(4);
//		memset(buf, 0 ,40);
//		sprintf(buf, ": %08ld", TradeCounter);
//		Print_Line(buf, 10, 1);
//
//		buf[0] = 1;
//		buf[1] = 7;
//		buf[2] = 17;
//		Printer_CreateTable(3, buf);
//		Printer_MoveTable(1);
//		Print_Line((unsigned char*)"交易原额", 8, 2);
//		Printer_MoveTable(2);
//		memset(buf, 0 ,40);
//		if(ChargeMode2 ==MODE_CHARGE_INC)
//		{
//			sprintf(buf, ": %7.2f", ((float)(CardInfo.Money-CardInfo.hChargeMoney))/100);
//		}
//		else
//		{
//			sprintf(buf, ": %7.2f", ((float)(CardInfo.Money+CardInfo.hChargeMoney))/100);
//		}
//		for(i=10;i>1;i--)
//		{
//			if(buf[i]==' ')
//			{
//				buf[i] = '*';
//				break;
//			}
//		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -