📄 epsonmt532.cpp
字号:
// ePsonMT532.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "ePsonMT532.h"
#include "byprinter.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
#define SUCCESS 0
#define FAILUER -1
#define STATUS_NORMAL 0
#define STATUS_FEWPAPER 1
#define STATUS_DEVICEERROR 3
#define STATUS_NODEVICE 4
#define DEVICE_OK "0000"
#define PRINTER_ERROR "5040"
#define FEWPAPER_ERROR "5012"
#define NO_PAPER "5010"
#define NODEFINE_ERROR "5000"
#define OPEN_COM_ERROR "0001"
#define READ_DATA_ERROR "0002"
#define READ_DATA_TIMEOUT "0003"
#define READ_INVALIDATE_DATA "0004"
#define WRITE_DATA_ERROR "0005"
#define WRITE_INVALIDATE_DATA "0006"
#define CONNECT_ERROR "0007"
#define DEFINE_COMM_ERROR "0008"
#define NO_DEFINE_ERROR "3099"
/////////////////////////////////////////////////////////////////////////////
// CEPsonMT532App
BEGIN_MESSAGE_MAP(CEPsonMT532App, CWinApp)
//{{AFX_MSG_MAP(CEPsonMT532App)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEPsonMT532App construction
CEPsonMT532App::CEPsonMT532App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CEPsonMT532App object
CEPsonMT532App theApp;
BYPrinter oPrinter;
int iLeftDistance = 0;
char szComm[6];
int printFlag = 0; //打印标识
/*****************************************************
//Description :初始化凭条打印机,打开"ComPort"属性设置的串口。
//Input :输入端口号,com1 代表 端口1,com2 代表端口2,依次类推。
//Return :0->Success;-1->初始化端口Fail;1->初始化PRR Fail
*****************************************************/
int WINAPI PrinterInit(char *pszCom,char *pszRcCode)
{
//AfxMessageBox(pszCom);
if ( memcmp(pszCom,"COM",3) != 0 &&
memcmp(pszCom,"com",3) != 0 &&
memcmp(pszCom,"Com",3) != 0 &&
memcmp(pszCom,"LPT",3) != 0 &&
memcmp(pszCom,"lpt",3) != 0)
{
strcpy(pszRcCode,DEFINE_COMM_ERROR);
return FAILUER;
}
else
{
strcpy(szComm,pszCom);
return SUCCESS;
}
}
/*****************************************************
//Description :打开设备
//Return : 0->Success;-1->Fail
*****************************************************/
int WINAPI PrinterOpen(char *pszRcCode)
{
printFlag = 1;
int iResultVal = oPrinter.byprinter_opn(szComm,9600);
oPrinter.MYTRACE("iResultVal zrz=%d\n",iResultVal);
switch (iResultVal)
{
case 0: //成功
strcpy(pszRcCode,DEVICE_OK);
oPrinter.MYTRACE("iResultVal zrz=0\n");
return SUCCESS;
case 1: //开串口失败
strcpy(pszRcCode,OPEN_COM_ERROR);
oPrinter.MYTRACE("iResultVal zrz=1\n");
return FAILUER;
case 2: //写串口失败
strcpy(pszRcCode,WRITE_DATA_ERROR);
oPrinter.MYTRACE("iResultVal zrz=2\n");
return FAILUER;
default: //未定义
strcpy(pszRcCode,NO_DEFINE_ERROR);
oPrinter.MYTRACE("iResultVal zrz=3\n");
return FAILUER;
}
}
/*****************************************************
//Description :打印凭条,一次打印一行,支持换行
//Input :length - 打印数据长度
// data - 凭条数据
//Output :
//Return :0->Success;1->Fail
*****************************************************/
int WINAPI PrinterPrint(int length,char *data,char *pszRcCode)
{
int iResultVal;
char szNumber[100];
memset(szNumber,0,sizeof(szNumber));
itoa(length,szNumber,10);
if((length <= 0) || (length>900))
{
strcpy(pszRcCode,NO_DEFINE_ERROR);
return FAILUER;
}
oPrinter.byprinter_pit(iLeftDistance,0);
iResultVal = oPrinter.byprinter_ptw(data,length);
//oPrinter.byprinter_rtn(1);
//del by zrz iResultVal = oPrinter.byprinter_ptw("\n",1);
if(iResultVal!=0)
{
strcpy(pszRcCode,NO_DEFINE_ERROR);
return FAILUER;
}
else
{
strcpy(pszRcCode,DEVICE_OK);
return SUCCESS;
}
}
/*****************************************************
//Description :设置打印参数
//Return : 0->Success;1->Fail
*****************************************************/
int WINAPI PrinterSetParam(int LineSpace,int LeftSpace,int FontSize,int FontType)
{
//设置行间距
//oPrinter.byprinter_lsp(LineSpace);
//设置左边距
if ( LeftSpace > 300 )
{
return FAILUER;
}else
iLeftDistance = LeftSpace;
//设定字体大小
//oPrinter.byprinter_fon(FontSize,FontSize);
return SUCCESS;
}
/*****************************************************
//Description :凭条打印机状态
//Output : 0-正常;
1-纸少(针对凭条、流水等打印机,其它设备没有该值);
2-缺纸(针对凭条、流水等打印机,其它设备没有该值);
3-故障;
4-设备不存在。
*****************************************************/
int WINAPI PrinterStatus(char *pszRcCode)
{
int iResultVal;
BYTE StatusBuff[4];
/*
strcpy(pszRcCode,"0000");
return 0;
*/
if ( printFlag == 1 ) //正在打印
{
strcpy(pszRcCode,"0000");
return 0;
}
iResultVal = PrinterOpen(pszRcCode);
oPrinter.MYTRACE("iResultVal zrz1 PrinterStatus =%d\n",iResultVal);
if ( iResultVal < 0 )
{
strcpy(pszRcCode,"3040");
return 3; //故障
}
memset(StatusBuff,0,sizeof(StatusBuff));
iResultVal = oPrinter.byprinter_chk(StatusBuff);
//oPrinter.byprinter_cls(); //关闭打印机
if(iResultVal != 0)
{
strcpy(pszRcCode,"3000");
return 4; //设备不存在
}
oPrinter.MYTRACE(" zrz StatusBuff1 =%d\n",StatusBuff[1]);
oPrinter.MYTRACE(" zrz StatusBuff2 =%d\n",StatusBuff[2]);
oPrinter.MYTRACE(" zrz StatusBuff3 =%d\n",StatusBuff[3]);
if((StatusBuff[1] & 0x04) == 0x04)
{
strcpy(pszRcCode,DEVICE_OK);
return 2; //故障
}
if(StatusBuff[1] != 0x08)
{
strcpy(pszRcCode,"3040");
return 3; //故障
}
/* if((StatusBuff[1] & 0x0c) == 0x0c)
{
strcpy(pszRcCode,"3012");
return 1; //纸少
}*/
else
{
strcpy(pszRcCode,"0000");
return 0; //正常
}
}
/*****************************************************
//Description :切纸
//Return : 0->Success;1->Fail
*****************************************************/
int WINAPI PrinterCut()
{
int iResultVal;
//zrz del oPrinter.byprinter_rtn(2);
iResultVal = oPrinter.byprinter_cut(1);
oPrinter.MYTRACE("zrz success1=[%d]\n",iResultVal);
//del by oPrinter.byprinter_cls();
oPrinter.MYTRACE("zrz success2\n");
printFlag = 0;
if ( iResultVal != 0 )
return FAILUER;
else
return SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -