Epl2Immed.c 、//
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPLIMMED_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <string.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XPrtEng.h"
#include "XComm.h"
#include "..\Parser.h"
#include "..\ParserUtil.h"
#include "Epl2Immed.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#define EPL_IMM_CMD_LEN (sizeof(EplImmCmdTitle) - 1)
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
#if defined(EPL2)
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
#if defined(__HITACHI__)
#pragma section ISR
#endif
CONST CHAR EplImmCmdTitle[] = "^ee";
#if defined(__HITACHI__)
#pragma section
#endif
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
STATIC INT EplImmReceivePtr;
STATIC BOOL EplImmCommandEnable;
/******************************************************************************
*
* Function:
* SendUart
*
* Description:
* This global function Uart receive data.
*
* Input:
* None
*
* Output:
* None.
*
******************************************************************************/
VOID InitiaEplImmCmd(VOID)
{
EplImmReceivePtr = 0;
EplImmCommandEnable = TRUE;
}
VOID EplCtrlImmedCmd(BOOL Flag)
{
EplImmCommandEnable = Flag;
}
#if defined(__HITACHI__)
#pragma section ISR
#endif
#if defined(__HITACHI__)
#pragma inline(EplCheckImmedCmd)
#endif
INT EplCheckImmedCmd(CHAR Data, CHAR *pString, INT Port)
{
INT i;
if (EplImmCommandEnable)
{
if (EplImmReceivePtr >= EPL_IMM_CMD_LEN)
{
EplImmReceivePtr = 0;
EplErrorReportImmediate();
return 0;
}
else if (Data == EplImmCmdTitle[EplImmReceivePtr])
{
EplImmReceivePtr += 1;
return 0;
}
if (EplImmReceivePtr)
{
for (i = 0; i < EplImmReceivePtr; i++)
{
*pString = EplImmCmdTitle[i];
pString += 1;
}
*pString = Data;
EplImmReceivePtr = 0;
return (i + 1);
}
}
*pString = Data;
return 1;
}
#endif
Epl2Immed.h //
#ifndef EPLIMMED_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPLIMMED_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
#ifdef EPLIMMED_C
#define EXTERN
#else
#define EXTERN extern
#endif
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
VOID InitiaEplImmCmd(VOID);
#undef EXTERN
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif
Epl2Report.c //
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPL2REPORT_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XText.h"
#include "XAppVer.h"
#include "XPrtEng.h"
#include "XCodePage.h"
#include "..\Parser.h"
#include "..\ParserUtil.h"
#include "Epl2Func.h"
#include "Epl2Report.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#if defined(TDP225) || defined(TTP225)
#define REPORT_FONT "2.EFT"
#else
#define REPORT_FONT "3.EFT"
#endif
#if defined(TPH_DPI_200)
#define REPORT_LINEH 26
#elif defined(TPH_DPI_300) || defined(TPH_DPI_600)
#define REPORT_LINEH 39
#endif
#if defined(TDP225) || defined(TTP225) || defined(TTP323)
#define REPORT_WIDTH (INT)(TPH_DPI * 2)
#else
#define REPORT_WIDTH (INT)(TPH_DPI * 3)
#endif
#if defined(LEFT_ALIGN)
#define REPORT_X (INT)(MM_DOT * 2)
#elif defined(CENTER_ALIGN)
#define REPORT_X (INT)(MM_DOT * 2)//((TPH_WIDTH_DOT - REPORT_WIDTH) / 2 + (INT)(MM_DOT * 1))
#endif
#define REPORT_Y 10
#define PATTERN_LEN 40
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
#if defined(EPL2)
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
*
* Function:
*
*
* Description:
*
*
* Input:
* None.
*
* Output:
* None.
*
******************************************************************************/
VOID EplFormInfoReport(_OutputWay OutWay)
{
REPORT *Report = OpenReport(OutWay);
_PrintCfg Conf = *pPrintCfg; // copy print config
_FileList List;
CHAR Name[64];
Conf.Direction = 1;
Conf.Mirror = 0;
if (OutWay == OUTPUT_LABEL)
WriteReport(Report, "Form information:");
if (OutWay == OUTPUT_RS232)
WriteReport(Report, "%03d", GetFileTotal(FLASH_DEVICE, "*.FRM"));
OpenList(&List, FLASH_DEVICE);
while (NextFile(&List, "*.FRM"))
{
*strchr(strcpy(Name, List.FileName), '.') = '\0';
WriteReport(Report, "%s", Name);
}
if (OutWay == OUTPUT_LABEL)
WriteReport(Report, "Form memory left:%4dK", FreeSpace(FLASH_DEVICE));
CloseReport(Report, &Conf, REPORT_X, REPORT_Y, REPORT_LINEH, REPORT_FONT, LANG_EPL);
}
VOID EplGraphicInfoReport(_OutputWay OutWay)
{
REPORT *Report = OpenReport(OutWay);
_PrintCfg Conf = *pPrintCfg; // copy print config
_FileList List;
CHAR Name[64];
Conf.Direction = 1;
Conf.Mirror = 0;
if (OutWay == OUTPUT_LABEL)
WriteReport(Report, "Graphics information:");
if (OutWay == OUTPUT_RS232)
WriteReport(Report, "%03d", GetFileTotal(FLASH_DEVICE, "*.PCX"));
OpenList(&List, FLASH_DEVICE);
while (NextFile(&List, "*.PCX"))
{
*strchr(strcpy(Name, List.FileName), '.') = '\0';
WriteReport(Report, "%s", Name);
}
if (OutWay == OUTPUT_LABEL)
WriteReport(Report, "Graphics memory left:%4dK", FreeSpace(FLASH_DEVICE));
CloseReport(Report, &Conf, REPORT_X, REPORT_Y, REPORT_LINEH, REPORT_FONT, LANG_EPL);
}
VOID EplFontInfoReport(_OutputWay OutWay)
{
REPORT *Report = OpenReport(OutWay);
_PrintCfg Conf = *pPrintCfg; // copy print config
_FileHandle *Handle;
_FileList List;
CHAR Name[64];
BYTE Head[32];
Conf.Direction = 1;
Conf.Mirror = 0;
ClearImageBuffer(&sImageBuffer);
if (OutWay == OUTPUT_LABEL)
WriteReport(Report, "External fonts stored:");
if (OutWay == OUTPUT_RS232)
WriteReport(Report, "%03d", GetFileTotal(FLASH_DEVICE, "*.EFT"));
OpenList(&List, FLASH_DEVICE);
while (NextFile(&List, "*.EFT"))
{
if (Handle = Fopen(FLASH_DEVICE, List.FileName, "r"))
{
Fread(Head, sizeof(BYTE), sizeof(Head), Handle);
Fclose(Handle);
*strchr(strcpy(Name, List.FileName), '.') = '\0';
if (OutWay == OUTPUT_LABEL)
WriteReport(Report, "%s:%03dchar,%03ddots,%ddir.", Name, Head[15], Head[5], Head[14]);
if (OutWay == OUTPUT_RS232)
WriteReport(Report, "%s,%03d,%1d", Name, Head[5], Head[14]);
}
}
if (OutWay == OUTPUT_LABEL)
WriteReport(Report, "Ext font memory left:%4dK", FreeSpace(FLASH_DEVICE));
CloseReport(Report, &Conf, REPORT_X, REPORT_Y, REPORT_LINEH, REPORT_FONT, LANG_EPL);
}
VOID EplSelfTestReport(_OutputWay OutWay)
{
CONST STATIC CHAR *Baud[] = { "0","12","24","48","96","192","384","576","115" };
CONST STATIC CHAR *Parity[] = { "N","O","E" };
CONST STATIC CHAR *DataBits[] = { "7","8" };
CONST STATIC CHAR *Stop[] = { "1","2" };
CONST STATIC CHAR *rYesNo[] = { "rY","rN" };
CONST STATIC CHAR *JMode[] = { "JF","JB","JC" };
CONST STATIC CHAR *WMode[] = { "WY","WN" };
CONST STATIC CHAR *Direction[] = { "ZT","ZB" };
CONST STATIC CHAR *ErrorReport[] = { "UN","US" };
_PrintCfg Conf = *pPrintCfg; // copy print config
REPORT *Report = OpenReport(OutWay);
INT CodePage = (Conf.EplDataBit == 7) ? Conf.EplCodePage : (Conf.EplCodePage - 9);
INT Mode1 = (Conf.PrintOutMode == OFF_MODE) ? 1 : 0;
Conf.Direction = 1;
Conf.Mirror = 0;
WriteReport(Report, "%-15s V%s", ModelName, VerName);
WriteReport(Report, "Serial port:%s,%s,%s,%s",
Baud[Conf.UartSetting.Baud],
Parity[Conf.UartSetting.Parity],
DataBits[Conf.UartSetting.DataBits],
Stop[Conf.UartSetting.Stop]);
WriteReport(Report, "Page Mode");
PatternReport(Report, PATTERN_LEN);
WriteReport(Report, "Image buffer size:%04dK", (IMAGE_BUFFER_SIZE / 1024));
WriteReport(Report, "Fmem used: %d (bytes)", GetFileSize(FLASH_DEVICE, "*.FRM"));
WriteReport(Report, "Gmem used: %d (bytes)", GetFileSize(FLASH_DEVICE, "*.PCX"));
WriteReport(Report, "Emem used: %d (bytes)", GetFileSize(FLASH_DEVICE, "*.EFT"));
WriteReport(Report, "Available: %ld", FreeSpace(FLASH_DEVICE) * 1024);
WriteReport(Report, "I%d,%s,%s %s %s %s",
Conf.EplDataBit,
EplCodePageNameTable[CodePage],
EplCountryNameTable[Conf.EplCountryCode],
rYesNo[Conf.WaitPrint],
JMode[Mode1],
WMode[Conf.WinDriver]);
WriteReport(Report, "S%s D%02d R%d,%d %s %s",
ToSpeedString(Conf.Speed),
(INT)((Conf.fDensity - DensityMin) / (DensityMax - DensityMin) * 15),
Conf.ReferenceX,
Conf.ReferenceY,
Direction[Conf.Direction],
ErrorReport[Conf.ErrorReport]);
if (Conf.SensorMode == GAP_MODE)
{
WriteReport(Report, "q%d Q%d,%d+%d Ymax:%4d",
Conf.PaperWidth,
(INT)Conf.fPaperSize,
(INT)Conf.fGapSize,
(INT)Conf.fGapOffset,
HALF_IMAGE_LENGTH);
}
else if (Conf.SensorMode == BLINE_MODE)
{
WriteReport(Report, "q%d Q%d,B%d+%d Ymax:%4d",
Conf.PaperWidth,
(INT)Conf.fPaperSize,
(INT)Conf.fBlineSize,
(INT)Conf.fBlineOffset,
HALF_IMAGE_LENGTH);
}
else
{
WriteReport(Report, "q%d Q%d,0 Ymax:%4d",
Conf.PaperWidth,
Conf.ContinuePaperFeed,
HALF_IMAGE_LENGTH);
}
WriteReport(Report, "Option:");
CloseReport(Report, &Conf, REPORT_X, REPORT_Y, REPORT_LINEH, REPORT_FONT, LANG_EPL);
}
/*
* US Command (Printer's status reporting feature)
*
* If no errors occur, the printer will echo ACK(0x6) after each P command.
* If an error occurs, the printer will send a NACK(0x15), followed by the
* error number, to the computer.
*
* 00 No Error
* 01 Syntax Error
* 02 Object Exceeded Label Border
* 03 Bar Code Data Length Error (e.g.: EAN-13 is a 12 or 13 digit only)
* 04 Insufficient Memory to Store Data
* 05 Memory Configuration Error
* 06 RS-232 Interface Error
* 07 Paper or Ribbon Empty
* 08 Duplicate Name: Form, Graphic or Soft Font
* 09 Name Not Found: Form, Graphic or Soft Font
* 10 Not in Data Entry Mode
* 11 Print Head Up (Open)
* 12 Pause Mode or Paused in Peel mode
* 13 Mobile Printers: Print head too hot
* 14 Mobile Printers: Motor too hot
* 15 Mobile Printers: Battery low warning (. 40%)
* 16 Mobile Printers: Battery low limit (. 20%)
* 50 Does not fit in area specified
* 51 Data length to long
* 84 Media Error or Blackline not detected
* 93 PDF-417 coded data to large to fit in bar code
*/
VOID EplErrorReporting(BOOL PrintType)
{
WORD Error = GetJobErrorState();
INT Remain = GetPrintRemain();
CHAR Buffer[32] = "";
if (pPrintCfg->ErrorReport == FALSE)
return;
if (PrintType)
strcpy(Buffer, "\x06");
// Paper or Ribbon Empty
if (Error & ERROR_PAPER_JAM ||
Error & ERROR_PAPER_EMPTY ||
Error & ERROR_RIBBON_JAM ||
Error & ERROR_RIBBON_EMPTY)
{
// If paper or ribbon empty occurs, send a "-07" and "Pnnn"
// where nnn is the number of labels remaining to print.
if (PrintType)
sprintf(Buffer, "\x15" "07P%03u", Remain);
else
strcpy(Buffer, "\x15" "84");
}
// Print head too hot
if (Error & ERROR_TPH_OVERHEAT)
strcpy(Buffer, "\x15" "13");
// Motor too hot
if (Error & ERROR_MOTOR_OVERHEAT)
strcpy(Buffer, "\x15" "14");
// Cutter Jammed or Not Installed
if (Error & ERROR_CUTTER)
strcpy(Buffer, "\x15" "81");
#if defined(CARRIAGE_OPEN_MODEL)
// Print Head Up (Open)
if (IsCarriageOpen() && pPrintCfg->CarriageOpen)
strcpy(Buffer, "\x15" "11");
#endif
CommWrite(USB_PORT, Buffer, strlen(Buffer), 0);
CommWrite(UART_PORT, Buffer, strlen(Buffer), 0);
}
/*
* ^ee Command (Get printer errors and status reports immediately)
*
* 00 No Error
* 01 Syntax Error
* 02 Object Exceeded Label Border
* 03 Bar Code Data Length Error (e.g.: EAN-13 is a 12 or 13 digit only)
* 04 Insufficient Memory to Store Data
* 05 Memory Configuration Error
* 06 RS-232 Interface Error
* 07 Paper or Ribbon Empty
* 08 Duplicate Name: Form, Graphic or Soft Font
* 09 Name Not Found: Form, Graphic or Soft Font
* 10 Not in Data Entry Mode (See ? Com mand)
* 11 Print Head Up (Open)
* 12 Pause Mode or Paused in Peel mode
* 50 Printer Busy - Processing Print Job
* 80* Undefined
* 81* Cutter Jammed or Not Installed
* 82* AutoSense or Sensor Failure
* 83* Illegal Interrupt occurred
* 84* Excessive Media Feeding
*/
VOID EplErrorReportImmediate(VOID)
{
_eJobMonitor Monitor = GetJobMonitor();
WORD Error = GetJobErrorState();
BOOL Lock = CheckJobLock();
// No Error
CHAR Buffer[] = "00\r\n";
// Printer Busy - Processing Print Job
if (Monitor != MONITOR_IDLE)
strcpy(Buffer, "50\r\n");
// Pause Mode or Paused in Peel mode
if (Lock || Monitor == MONITOR_TAKE_LABEL)
strcpy(Buffer, "12\r\n");
// Paper or Ribbon Empty
if (Error & ERROR_PAPER_JAM ||
Error & ERROR_PAPER_EMPTY ||
Error & ERROR_RIBBON_JAM ||
Error & ERROR_RIBBON_EMPTY)
strcpy(Buffer, "07\r\n");
// Undefined
if (Error & ERROR_TPH_OVERHEAT ||
Error & ERROR_MOTOR_OVERHEAT)
strcpy(Buffer, "80\r\n");
// Cutter Jammed or Not Installed
if (Error & ERROR_CUTTER)
strcpy(Buffer, "81\r\n");
#if defined(CARRIAGE_OPEN_MODEL)
// Print Head Up (Open)
if (IsCarriageOpen() && pPrintCfg->CarriageOpen)
strcpy(Buffer, "11\r\n");
#endif
CommWrite(UART_PORT, Buffer, strlen(Buffer), 0);
}
#endif
Epl2Report.h
#ifndef EPL2REPORT_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPL2REPORT_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
#ifdef EPL2REPORT_C
#define EXTERN
#else
#define EXTERN extern
#endif
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
#undef EXTERN
VOID EplFormInfoReport(_OutputWay);
VOID EplGraphicInfoReport(_OutputWay);
VOID EplFontInfoReport(_OutputWay);
VOID EplSelfTestReport(_OutputWay);
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif
Epl2Util.c /
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPL2UTIL_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "Epl2Util.h"
#include "EPL2Var.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#if defined(EPL2)
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
*
* Function:
*
*
* Description:
*
*
* Input:
* None
*
* Output:
* None.
*
******************************************************************************/
BOOL EplGetToken(_eTokenEndMode Mode, CHAR *pToken, INT Limit)
{
CHAR Temp;
INT Len;
Len = 0;
while (Len < Limit - 1)
{
Len += GetToken(pToken + Len, &Temp, " \t\r\n,;", Limit - Len);
if (CheckChar(Temp, " \t") && (Mode == SPACE_END || Mode == BACK_WITH_SPACE))
break;
else if (CheckChar(Temp, "\r\n,;"))
break;
}
if (Len == 0)
{
BackByte(Temp);
return FALSE;
}
if (!CheckTokenEnd(Mode, Temp))
return FALSE;
// remove last space
while (CheckChar(*(pToken + Len - 1), " \t") && Len)
*(pToken + (--Len)) = '\0';
return TRUE;
}
BOOL EplGetNumber(_eTokenEndMode Mode, LONG *pLong, BOOL Null)
{
CHAR Token[INTEGER_MAX_LEN];
CHAR Temp;
INT Len;
Len = 0;
while (Len < sizeof(Token) - 1)
{
Temp = NextByte();
if (isdigit(Temp) || Temp == '+' || Temp == '-')
Token[Len++] = Temp;
else if (CheckChar(Temp, " \t\r\n,;"))
break;
else
{
BackByte(Temp);
return FALSE;
}
}
Token[Len] = '\0';
if (Len == 0 && Null == FALSE)
{
BackByte(Temp);
return FALSE;
}
if (CheckChar(Temp, " \t") && Mode != SPACE_END && Mode != BACK_WITH_SPACE)
{
RemoveSpace();
Temp = NextByte();
if (!CheckChar(Temp, "\r\n,;"))
{
BackByte(Temp);
return FALSE;
}
}
if (!CheckTokenEnd(Mode, Temp))
return FALSE;
*pLong = atol(Token);
return TRUE;
}
BOOL EplGetString(_eTokenEndMode Mode, CHAR *pString, INT Limit)
{
CHAR Temp;
INT Len;
Len = 0;
while (Len < Limit - 1)
{
Temp = NextByte();
if (Temp == '\"')
{
while ((Temp = NextByte()) != '\"')
{
if (Temp == '\\')
Temp = NextByte();
*(pString + Len++) = Temp;
if (Len >= Limit - 1)
break;
}
if (Mode == STRING_END)
{
*(pString + Len) = '\0';
return TRUE;
}
}
else if (CheckChar(Temp, " \t\r\n,;"))
break;
else
{
BackByte(Temp);
return FALSE;
}
}
*(pString + Len) = '\0';
if (CheckChar(Temp, " \t") && Mode != SPACE_END && Mode != BACK_WITH_SPACE)
{
RemoveSpace();
Temp = NextByte();
if (!CheckChar(Temp, "\r\n,;"))
{
BackByte(Temp);
return FALSE;
}
}
if (!CheckTokenEnd(Mode, Temp))
return FALSE;
return TRUE;
}
BOOL EplGetExpString(_eEplStringType *StrType, CHAR *String, CHAR *Exp)
{
BOOL VarType = FALSE;
BOOL CntType = FALSE;
CHAR Token[16];
CHAR Temp;
INT StrLen = 0;
INT ExpLen = 0;
INT TokLen = 0;
INT Num;
*StrType = EPL_STRING;
while (ExpLen < STRING_LEN - 1 && StrLen < STRING_LEN - 1)
{
Temp = *(Exp + ExpLen++) = NextByte();
if (ExpLen >= STRING_LEN - 1)
break;
if (Temp == '\"')
{
while ((Temp = *(Exp + ExpLen++) = NextByte()) != '\"')
{
if (Temp == '\\' && ExpLen < STRING_LEN - 1
&& (BYTE)*(String + StrLen - 1) <= 0xA1)
Temp = *(Exp + ExpLen++) = NextByte();
if (StrLen < STRING_LEN - 1)
*(String + StrLen++) = Temp;
if (ExpLen >= STRING_LEN - 1)
break;
}
}
// Code 128 Bar Code Function characters
else if (Temp == 'F')
{
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
if (Temp == '1') // FNC1
StrLen += sprintf(String + StrLen, "\"F1\"");
if (Temp == '2') // FNC2
StrLen += sprintf(String + StrLen, "\"F2\"");
if (Temp == '3') // FNC3
StrLen += sprintf(String + StrLen, "\"F3\"");
if (Temp == '4') // FNC4
StrLen += sprintf(String + StrLen, "\"F4\"");
}
// Vxx
else if (Temp == 'V')
{
VarType = TRUE;
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
}
// Cx
else if (Temp == 'C')
{
CntType = TRUE;
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
}
else if (Temp == 'T')
{
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
// get time string
if (Temp == 'T' && StrLen + 15 < STRING_LEN - 1)
StrLen += GetTimeString(String + StrLen);
// get date string
else if (Temp == 'D')
{
Num = 0;
Temp = NextByte();
if (Temp == '+')
{
if (ExpLen < STRING_LEN - 1)
*(Exp + ExpLen++) = Temp;
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
if (Temp == 'V')
{
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
VarType = TRUE;
}
else
{
TokLen = 0;
while (isdigit(Temp) && ExpLen < STRING_LEN - 1)
{
if (TokLen < sizeof(Token) - 1)
Token[TokLen++] = Temp;
if (ExpLen < STRING_LEN - 1)
Temp = *(Exp + ExpLen++) = NextByte();
}
ExpLen--;
BackByte(Temp);
Token[TokLen] = '\0';
Num = atoi(Token);
if (StrLen + 15 < STRING_LEN - 1)
StrLen += GetDateString(String + StrLen, Num);
}
}
else
{
BackByte(Temp);
if (StrLen + 15 < STRING_LEN - 1)
StrLen += GetDateString(String + StrLen, 0);
}
}
}
else if (Temp == '\r' || Temp == '\n')
break;
else
{
BackByte(Temp);
return FALSE;
}
}
*(String + StrLen) = '\0';
*(Exp + ExpLen) = '\0';
if (CntType)
*StrType = EPL_COUNTER;
else if (VarType)
*StrType = EPL_VARIABLE;
return TRUE;
}
BOOL EplPostalCode(_eTokenEndMode Mode, LONG *pLong)
{
#define POSTALCODE_MAX 9
CHAR Token[INTEGER_MAX_LEN];
CHAR Temp;
INT Len,Len1;
BOOL IgnoreFlag=0;
memset(Token, 0, sizeof(Token));
Len = 0;
while (Len <= POSTALCODE_MAX-1)
{
Temp = NextByte();
if (isdigit(Temp))
Token[Len++] = Temp;
else if (CheckChar(Temp, ",-"))
{
if(IgnoreFlag)
break;
else
{
IgnoreFlag = 1;
continue;
}
}
}
if (Len == 0)
{
BackByte(Temp);
return FALSE;
}
Len1 = 0;
while(Len1 <= POSTALCODE_MAX-1)
{
if(Token[Len1] == '\0')
Token[Len1] = 0x30;
Len1++;
}
Token[POSTALCODE_MAX] = '\0';
if(Len == POSTALCODE_MAX)
Temp = NextByte();
if (!CheckTokenEnd(Mode, Temp))
return FALSE;
*pLong = atol(Token);
return TRUE;
}
#endif
Epl2Util.h /
#ifndef EPL2UTIL_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPL2UTIL_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "..\ParserUtil.h"
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
typedef enum
{
EPL_STRING,
EPL_VARIABLE,
EPL_COUNTER,
}_eEplStringType;
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
#ifdef EPL2UTIL_C
#define EXTERN
#else
#define EXTERN extern
#endif
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
BOOL EplGetToken(_eTokenEndMode, CHAR *, INT);
BOOL EplGetNumber(_eTokenEndMode, LONG *, BOOL);
BOOL EplGetString(_eTokenEndMode, CHAR *, INT);
BOOL EplGetExpString(_eEplStringType *,CHAR *, CHAR*);
BOOL EplPostalCode(_eTokenEndMode, LONG *);
#undef EXTERN
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif
Epl2Var.c ///
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPL2VAR_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XRTC.h"
#include "XComm.h"
#include "..\Parser.h"
#include "..\ParserUtil.h"
#include "Epl2Form.h"
#include "Epl2Func.h"
#include "Epl2Var.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#define NARROW_LEVEL 6
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
#if defined(EPL2)
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
*
* Function:
*
*
* Description:
*
*
* Input:
* None.
*
* Output:
* None.
*
******************************************************************************/
VOID InitialEplVar(VOID)
{
INT i;
// clear variable table
for (i = 0 ; i < EPL_VAR_TOTAL ; i++)
{
sEplVariable[i].AllocLength = 0;
sEplVariable[i].Justification = 'N';
sEplVariable[i].RealLength = 0;
sEplVariable[i].Prompt[0] = '\0';
sEplVariable[i].VarData[0] = 0x01;
sEplVariable[i].VarData[1] = '\0';
}
// clear counter table
for (i = 0 ; i < EPL_COUNTER_TOTAL ; i++)
{
sEplCounter[i].AllocLength = 0;
sEplCounter[i].Justification = 'N';
sEplCounter[i].RealLength = 0;
sEplCounter[i].Sign = 0;
sEplCounter[i].IncDec = 0;
sEplCounter[i].Prompt[0] = '\0';
sEplCounter[i].CounterVarData[0] = '\0';
}
// clear Var link table
for (i = 0 ; i < VAR_LINK_TOTAL ; i++)
{
sEplVarLinkTbl[i].VarType = NO_VAR;
sEplVarLinkTbl[i].ConutFlag = FALSE;
}
}
INT SetVarFormat(INT VarNum, INT AllocLen, CHAR Justi, CHAR *pPrompt)
{
if (VarNum >= EPL_VAR_TOTAL)
return FALSE;
sEplVariable[VarNum].AllocLength = AllocLen;
sEplVariable[VarNum].Justification = Justi;
strcpy(sEplVariable[VarNum].Prompt, pPrompt);
return TRUE;
}
INT SetCounterFormat(INT VarNum, INT AllocLen, CHAR Justi, CHAR Sign, LONG IncDec, CHAR *pPrompt)
{
if (VarNum >= EPL_COUNTER_TOTAL)
return FALSE;
sEplCounter[VarNum].AllocLength = AllocLen;
sEplCounter[VarNum].Justification = Justi;
sEplCounter[VarNum].Sign = Sign;
sEplCounter[VarNum].IncDec = IncDec;
strcpy(sEplCounter[VarNum].Prompt, pPrompt);
return TRUE;
}
_EplVarLinkTable *SearchFreeLinkTable(VOID)
{
INT i = 0;
while (i < VAR_LINK_TOTAL)
{
if (sEplVarLinkTbl[i].VarType == NO_VAR)
return &sEplVarLinkTbl[i];
i += 1;
}
return _NULL;
}
INT ReceiveVariable(VOID)
{
CHAR Temp;
INT Ret = TRUE;
INT Len;
INT i;
for (i = 0; i < sFormData.VariableCnt; i++)
{
if (sEplSetData.PromptResponse)
{
SendPrintf("%s\r\n", sEplVariable[i].Prompt);
SendPrintf("%s\r\n", sEplVariable[i].VarData);
}
Len = 0;
while (1)
{
Temp = NextByte();
if (Temp == CR_CHAR)
IgnoreFollowLF();
if (Temp == CR_CHAR || Temp == LF_CHAR)
break;
if (Len == sEplVariable[i].AllocLength)
continue;
sEplVariable[i].VarData[Len++] = Temp;
if (Temp == _NULL || Temp == XOFF)
Ret = FALSE;
}
sEplVariable[i].VarData[Len] = '\0';
sEplVariable[i].RealLength = Len;
}
for (i = 0; i < sFormData.CounterCnt; i++)
{
if (sEplSetData.PromptResponse)
{
SendPrintf("%s\r\n", sEplCounter[i].Prompt);
SendPrintf("%s\r\n", sEplCounter[i].CounterVarData);
}
Len = 0;
while (1)
{
Temp = NextByte();
if (Temp == CR_CHAR)
IgnoreFollowLF();
if (Temp == CR_CHAR || Temp == LF_CHAR)
break;
if (Len == sEplCounter[i].AllocLength)
continue;
sEplCounter[i].CounterVarData[Len++] = Temp;
if (Temp == _NULL || Temp == XOFF)
Ret = FALSE;
}
sEplCounter[i].CounterVarData[Len] = '\0';
sEplCounter[i].RealLength = Len;
}
return Ret;
}
INT GetVarData(INT VarNum, INT Start, INT Length, INT AddData, CHAR *pData)
{
INT StrLen;
INT Temp;
CHAR * pToken;
CHAR TempStr[100];
LONG TempData;
if (Start == 0 && Length == 0)
StrLen = sEplVariable[VarNum].RealLength;
else
StrLen = Length;
pToken = sEplVariable[VarNum].VarData;
if (AddData != 0)
{
TempData = atol(pToken);
TempData += AddData;
sprintf(TempStr, "%ld", TempData);
pToken = TempStr;
if (Start == 0 && Length == 0)
StrLen = strlen(TempStr);
}
switch (sEplVariable[VarNum].Justification)
{
case 'N':
{
strncpy(pData, pToken + Start, StrLen);
break;
}
case 'L':
{
strncpy(pData, pToken + Start, StrLen);
memset(pData + StrLen, ' ', sEplVariable[VarNum].AllocLength - StrLen);
StrLen = sEplVariable[VarNum].AllocLength;
break;
}
case 'R':
{
memset(pData, ' ', sEplVariable[VarNum].AllocLength - StrLen);
strncpy(pData + sEplVariable[VarNum].AllocLength - StrLen, pToken + Start, StrLen);
StrLen = sEplVariable[VarNum].AllocLength;
break;
}
case 'C':
{
Temp = (sEplVariable[VarNum].AllocLength - StrLen) / 2;
memset(pData, ' ', Temp);
strncpy(pData + Temp, pToken + Start, StrLen);
memset(pData + Temp + StrLen, ' ', sEplVariable[VarNum].AllocLength - Temp - StrLen);
StrLen = sEplVariable[VarNum].AllocLength;
break;
}
}
*(pData + StrLen) = '\0';
return StrLen;
}
INT GetCounterData(INT VarNum, INT Start, INT Length, CHAR *pData)
{
INT StrLen;
INT Temp;
if (Start == 0 && Length == 0)
StrLen = sEplCounter[VarNum].RealLength;
else
StrLen = Length;
switch (sEplCounter[VarNum].Justification)
{
case 'N':
{
strncpy(pData, sEplCounter[VarNum].CounterVarData + Start, StrLen);
break;
}
case 'L':
{
strncpy(pData, sEplCounter[VarNum].CounterVarData + Start, StrLen);
memset(pData + StrLen, ' ', sEplCounter[VarNum].AllocLength - StrLen);
StrLen = sEplCounter[VarNum].AllocLength;
break;
}
case 'R':
{
memset(pData, ' ', sEplCounter[VarNum].AllocLength - StrLen);
strncpy(pData + sEplCounter[VarNum].AllocLength - StrLen, sEplCounter[VarNum].CounterVarData + Start, StrLen);
StrLen = sEplCounter[VarNum].AllocLength;
break;
}
case 'C':
{
Temp = (sEplCounter[VarNum].AllocLength - StrLen) / 2;
memset(pData, ' ', Temp);
strncpy(pData + Temp, sEplCounter[VarNum].CounterVarData + Start, StrLen);
memset(pData + Temp + StrLen, ' ', sEplCounter[VarNum].AllocLength - Temp - StrLen);
StrLen = sEplCounter[VarNum].AllocLength;
break;
}
}
*(pData + StrLen) = '\0';
return StrLen;
}
INT GetDateString(CHAR *pString, INT ExtAdd)
{
CONST STATIC CHAR *MON_ARRAY[] =
{
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC"
};
CONST STATIC INT MON_DAYS[] =
{
31, // "JAN",
28, // "FEB",
31, // "MAR",
30, // "APR",
31, // "MAY",
30, // "JUN",
31, // "JUL",
31, // "AUG",
30, // "SEP",
31, // "OCT",
30, // "NOV",
31 // "DEC"
};
CHAR *pFormat;
INT Year, Month, Date;
INT iTemp;
INT Length;
pFormat = sEplSetData.DateFormat; //get format's pointer
//read year, month and date first, if there is + follow, we can calc
Year = GetRTC(RTC_YEAR) % 100;
Month = GetRTC(RTC_MONTH);
Date = GetRTC(RTC_DATE);
//calc TD+XXX
while (TRUE)
{
//get days of current month
iTemp = MON_DAYS[ Month-1 ];
//leap year?
if ((Month == 2) && !(Year % 4))
iTemp++;
if ((Date + ExtAdd) > iTemp)
{
ExtAdd -= iTemp - Date;
Date = 0;
Month += 1;
if (Month == 13) //next year
{
Month = 1;
Year++;
}
}
else
break;
}
//final add, this will guarantee
Date += ExtAdd;
Length = 0;
while (*pFormat)
{
if (*pFormat == 'y') //year
{
pFormat++;
if (*pFormat == '4')
{
if (Year > 89) //90 -- 99
{
*pString++ = '1';
*pString++ = '9';
}
else //00 -- 89
{
*pString++ = '2';
*pString++ = '0';
}
*pString++ = (Year / 10) + '0';
*pString++ = (Year % 10) + '0';
Length += 4;
}
else if (*pFormat == '2')
{
*pString++ = (Year / 10) + '0';
*pString++ = (Year % 10) + '0';
Length += 2;
}
pFormat++;
}
else if (*pFormat == 'm') //month
{
pFormat++;
if (*pFormat == 'n') //regular 01-12
{
*pString++ = (Month / 10) + '0';
*pString++ = (Month % 10) + '0';
Length += 2;
}
else
{ //JAN, FEB, ...
strcpy(pString, MON_ARRAY[Month-1]);
pString += 3;
Length += 3;
}
pFormat++;
}
else if (*pFormat == 'd')
{
pFormat += 2; //always dd
*pString++ = (Date / 10) + '0';
*pString++ = (Date % 10) + '0';
Length += 2;
}
else //must be seperator
{
*pString++ = *pFormat++;
Length += 1;
}
}
return Length;
}
INT GetTimeString(CHAR *pString)
{
CHAR *pFormat;
INT AMPM;
LONG lData;
INT Length;
pFormat = sEplSetData.TimeFormat; //get format's pointer
// last char '+' meaning 12 hour + AM/PM
if (sEplSetData.TimeFormat[strlen(sEplSetData.TimeFormat) - 1] == '+')
AMPM = 1; // AM
else
AMPM = 0; // 24 houre
Length = 0;
while (*pFormat)
{
if (*pFormat == 'h') // year
{
lData = GetRTC(RTC_HOUR);
//check for AM/PM
if (AMPM && lData >= 12)
{
lData -= 12;
AMPM = 2;
}
//put into buffer
*pString++ = (lData / 10) + '0';
*pString++ = (lData % 10) + '0';
Length += 2;
pFormat++;
}
else if (*pFormat == 'm') // minute
{
//read MINUTE from RTC
lData = GetRTC(RTC_MIN);
//put into buffer
*pString++ = (lData / 10) + '0';
*pString++ = (lData % 10) + '0';
Length += 2;
pFormat++;
}
else if (*pFormat == 's') // year
{
// read SECOND from RTC
lData = GetRTC(RTC_SEC);
//put into buffer
*pString++ = (lData / 10) + '0';
*pString++ = (lData % 10) + '0';
Length += 2;
pFormat++;
}
else // must be seperator or end
{
if (*pFormat != '+') // '+' indicate AM/PM, should not print this
{
*pString++ = *pFormat;
Length += 1;
}
pFormat++;
}
}
if (AMPM == 1)
{
strcpy(pString, " AM");
pString += 3;
Length += 3;
}
else if (AMPM == 2)
{
strcpy(pString, " PM");
pString += 3;
Length += 3;
}
return Length;
}
INT ExplainString(CHAR *pTarget, CHAR *pSource)
{
INT num, i;
CHAR Token[64];
CHAR *pToken;
CHAR Operate;
LONG OpData1, OpData2;
INT Start, Len;
CHAR Temp;
INT DigiLen;
while (*pSource)
{
if (*pSource == '\"')
{
pSource++;
while (*pSource != '\"')
{
if (*pSource == '\\' && (BYTE)*(pTarget - 1) <= 0xa1)
pSource++;
*pTarget++ = *pSource++;
}
}
else if (*pSource == 'V')
{
pSource++;
num = (*pSource & 0x0f);
if (isdigit(*(pSource + 1)))
{
num *= 10;
pSource++;
num += *pSource & 0x0f ;
}
if (*(pSource + 1) == '[')
{
pSource++;
pSource++;
Start = 0;
Len = 0;
while (1)
{
Temp = *pSource++;
if (Temp == ',')
break;
Start *= 10;
Start += Temp & 0x0f;
}
// get Length
while (1)
{
Temp = *pSource;
if (Temp == ']')
break;
pSource++;
Len *= 10;
Len += Temp & 0x0f;
}
if (*(pSource + 1) == '+')
{
pSource++;
pSource++;
DigiLen = 0;
while (1)
{
if (isdigit(*pSource))
{
DigiLen++;
}
else
{
pSource--;
break;
}
pSource++;
}
i = GetVarData(num, Start, Len, 0, Token);
*(Token + i) = 0;
if (i < DigiLen)
{
memset(pTarget, '0', DigiLen - i);
pTarget += DigiLen - i;
}
strncpy(pTarget, Token, i);
pTarget += i;
}
else
pTarget += GetVarData(num, Start, Len, 0, pTarget);
}
else if (CheckChar(*(pSource + 1), "+*-/"))
{
GetVarData(num, 0, 0, 0, Token);
OpData1 = atol(Token);
while (CheckChar(*(pSource + 1), "+*-/"))
{
pSource++;
Operate = *pSource++;
if (*pSource == 'V')
{
pSource++;
num = (*pSource & 0x0f);
if (isdigit(*(pSource + 1)))
{
num *= 10;
pSource++;
num += *pSource & 0x0f ;
}
Token [ GetVarData(num, 0, 0, 0, Token)] = '\0';
}
else if (isdigit(*pSource))
{
pToken = Token;
i = 0;
while (isdigit(*pSource))
{
*pToken++ = *pSource++;
if (++i > 12)
break;
}
pSource--;
*pToken = '\0';
}
else
Operate = _NULL;
if (Operate)
{
OpData2 = atol(Token);
switch (Operate)
{
case '+':
OpData1 += OpData2;
break;
case '-':
OpData1 -= OpData2;
break;
case '*':
OpData1 *= OpData2;
break;
case '/':
if (OpData2)
OpData1 /= OpData2;
break;
default:
break;
}
}
}
pTarget += sprintf(pTarget, "%ld", OpData1);
}
else
pTarget += GetVarData(num, 0, 0, 0, pTarget);
}
else if (*pSource == 'C')
{
pSource++;
num = *pSource & 0x0f ;
pTarget += GetCounterData(num, 0, 0, pTarget);
}
else if (*pSource == 'T')
{
pSource++;
if (*pSource == 'T')
pTarget += GetTimeString(pTarget);
else if (*pSource == 'D')
{
pSource++;
if (*pSource == '+')
{
pSource++;
if (*pSource == 'V')
{
pSource++;
num = (*pSource & 0x0f) * 10;
pSource++;
num += *pSource & 0x0f ;
GetVarData(num, 0, 0, 0, Token);
num = atoi(Token);
pTarget += GetDateString(pTarget, num);
}
else
{
pToken = Token;
while (isdigit(*pSource))
*pToken++ = *pSource++;
*pToken = '\0';
num = atoi(Token);
pTarget += GetDateString(pTarget, num);
}
}
else
{
pSource--;
pTarget += GetDateString(pTarget, 0);
}
}
}
pSource++;
}
*pTarget = '\0';
return TRUE;
}
VOID EplStoreTextBox(_EraseBox *pEraseBox, _TextAttr *pTextAttr)
{
if (pTextAttr->iReverse == TRUE)
{
switch (pTextAttr->iDirection)
{
case 0:
{
pEraseBox->iX = pTextAttr->sCoord.iX - 2;
pEraseBox->iY = pTextAttr->sCoord.iY - 2;
pEraseBox->iWidth = pTextAttr->iRealWidth + 4;
pEraseBox->iHeight = pTextAttr->iRealHeight + 4;
break;
}
case 90:
{
pEraseBox->iX = pTextAttr->sCoord.iX - pTextAttr->iRealHeight - 2;
pEraseBox->iY = pTextAttr->sCoord.iY - 2;
pEraseBox->iWidth = pTextAttr->iRealHeight + 4;
pEraseBox->iHeight = pTextAttr->iRealWidth + 4;
break;
}
case 180:
{
pEraseBox->iX = pTextAttr->sCoord.iX - pTextAttr->iRealWidth - 2;
pEraseBox->iY = pTextAttr->sCoord.iY - pTextAttr->iRealHeight - 2;
pEraseBox->iWidth = pTextAttr->iRealWidth + 4;
pEraseBox->iHeight = pTextAttr->iRealHeight + 4;
break;
}
case 270:
{
pEraseBox->iX = pTextAttr->sCoord.iX - 2;
pEraseBox->iY = pTextAttr->sCoord.iY - pTextAttr->iRealWidth - 2;
pEraseBox->iWidth = pTextAttr->iRealHeight + 4;
pEraseBox->iHeight = pTextAttr->iRealWidth + 4;
break;
}
default:
break;
}
}
else
{
switch (pTextAttr->iDirection)
{
case 0:
{
pEraseBox->iX = pTextAttr->sCoord.iX;
pEraseBox->iY = pTextAttr->sCoord.iY;
pEraseBox->iWidth = pTextAttr->iRealWidth;
pEraseBox->iHeight = pTextAttr->iRealHeight;
break;
}
case 90:
{
pEraseBox->iX = pTextAttr->sCoord.iX - pTextAttr->iRealHeight;
pEraseBox->iY = pTextAttr->sCoord.iY;
pEraseBox->iWidth = pTextAttr->iRealHeight;
pEraseBox->iHeight = pTextAttr->iRealWidth;
break;
}
case 180:
{
pEraseBox->iX = pTextAttr->sCoord.iX - pTextAttr->iRealWidth;
pEraseBox->iY = pTextAttr->sCoord.iY - pTextAttr->iRealHeight;
pEraseBox->iWidth = pTextAttr->iRealWidth;
pEraseBox->iHeight = pTextAttr->iRealHeight;
break;
}
case 270:
{
pEraseBox->iX = pTextAttr->sCoord.iX ;
pEraseBox->iY = pTextAttr->sCoord.iY - pTextAttr->iRealWidth;
pEraseBox->iWidth = pTextAttr->iRealHeight;
pEraseBox->iHeight = pTextAttr->iRealWidth;
break;
}
default:
break;
}
}
if (pEraseBox->iX < 0)
pEraseBox->iX = 0;
if (pEraseBox->iY < 0)
pEraseBox->iY = 0;
}
VOID EplStoreBarcodeBox(_EraseBox *pEraseBox, _BarCodeAttr *pBarcodeAttr, _BarcodeTable *pBarcodeTable)
{
INT Height, Width = 0, iShift;
INT Data;
// normal barcode
if (pBarcodeTable->pEraseWidth == _NULL)
{
switch (pBarcodeAttr->iRotation)
{
case 0:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX;
pEraseBox->iY = pBarcodeAttr->sCoord.iY;
pEraseBox->iWidth = pBarcodeAttr->TotalWidth;
pEraseBox->iHeight = pBarcodeAttr->TotalHeight;
break;
}
case 90:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX - pBarcodeAttr->TotalHeight;
pEraseBox->iY = pBarcodeAttr->sCoord.iY;
pEraseBox->iWidth = pBarcodeAttr->TotalHeight;
pEraseBox->iHeight = pBarcodeAttr->TotalWidth;
break;
}
case 180:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX - pBarcodeAttr->TotalWidth;
pEraseBox->iY = pBarcodeAttr->sCoord.iY - pBarcodeAttr->TotalHeight;
pEraseBox->iWidth = pBarcodeAttr->TotalWidth;
pEraseBox->iHeight = pBarcodeAttr->TotalHeight;
break;
}
case 270:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX ;
pEraseBox->iY = pBarcodeAttr->sCoord.iY - pBarcodeAttr->TotalWidth;
pEraseBox->iWidth = pBarcodeAttr->TotalHeight;
pEraseBox->iHeight = pBarcodeAttr->TotalWidth;
break;
}
default:
break;
}
}
else
{
if (pBarcodeAttr->iHuman == 0)
{
Height = pBarcodeAttr->iHeight;
iShift = 0;
}
else
{
Height = pBarcodeAttr->iHeight + ((pBarcodeAttr->iNarrow + 1) << 3);
iShift = (pBarcodeAttr->iNarrow << 3);
}
if (pBarcodeAttr->iHuman)
Data = 1;
else
Data = 0;
Width = pBarcodeTable->pEraseWidth[ Data * NARROW_LEVEL + (pBarcodeAttr->iNarrow -1)];
Width += pBarcodeAttr->iNarrow << 3;
if (pBarcodeTable->Shift)
{
switch (pBarcodeAttr->iRotation)
{
case 0:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX - iShift;
pEraseBox->iY = pBarcodeAttr->sCoord.iY;
pEraseBox->iHeight = Height;
pEraseBox->iWidth = Width;
break;
}
case 90:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX - Height;
pEraseBox->iY = pBarcodeAttr->sCoord.iY - iShift;
pEraseBox->iHeight = Width;
pEraseBox->iWidth = Height;
break;
}
case 180:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX - Width + iShift;
pEraseBox->iY = pBarcodeAttr->sCoord.iY - Height;
pEraseBox->iHeight = Height;
pEraseBox->iWidth = Width;
break;
}
case 270:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX;
pEraseBox->iY = pBarcodeAttr->sCoord.iY - Width + iShift;
pEraseBox->iHeight = Width;
pEraseBox->iWidth = Height;
break;
}
default:
break;
}
}
else
{
switch (pBarcodeAttr->iRotation)
{
case 0:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX;
pEraseBox->iY = pBarcodeAttr->sCoord.iY;
pEraseBox->iHeight = Height;
pEraseBox->iWidth = Width;
break;
}
case 90:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX - Height;
pEraseBox->iY = pBarcodeAttr->sCoord.iY;
pEraseBox->iHeight = Width;
pEraseBox->iWidth = Height;
break;
}
case 180:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX - Width;
pEraseBox->iY = pBarcodeAttr->sCoord.iY - Height;
pEraseBox->iHeight = Height;
pEraseBox->iWidth = Width;
break;
}
case 270:
{
pEraseBox->iX = pBarcodeAttr->sCoord.iX;
pEraseBox->iY = pBarcodeAttr->sCoord.iY - Width;
pEraseBox->iHeight = Width;
pEraseBox->iWidth = Height;
break;
}
default:
break;
}
}
}
if (pEraseBox->iX < 0)
pEraseBox->iX = 0;
if (pEraseBox->iY < 0)
pEraseBox->iY = 0;
}
VOID EplEraseBox(_EraseBox *pEraseBox, _ImgBuf *pImgBuf)
{
_BarAttr sBarAttr;
sBarAttr.iType = DRAW_ERASE;
sBarAttr.psImageBuffer = pImgBuf;
sBarAttr.sCoord.iX = pEraseBox->iX;
sBarAttr.sCoord.iY = pEraseBox->iY;
sBarAttr.iWidth = pEraseBox->iWidth;
sBarAttr.iHeight = pEraseBox->iHeight;
DrawBar(&sBarAttr);
}
INT DrawTextReverseBox(_TextAttr *pTextAttr)
{
_BarAttr sBarAttr;
switch (pTextAttr->iRotation)
{
case 0:
//if reverse video is on, the erase box is 2 pixels wider on each side
sBarAttr.sCoord.iX = pTextAttr->sCoord.iX - 2;
sBarAttr.sCoord.iY = pTextAttr->sCoord.iY - 2;
sBarAttr.iWidth = pTextAttr->iRealWidth + 4;
sBarAttr.iHeight = pTextAttr->iRealHeight + 4;
break;
case 90:
sBarAttr.sCoord.iX = pTextAttr->sCoord.iX - pTextAttr->iRealHeight - 2;
sBarAttr.sCoord.iY = pTextAttr->sCoord.iY - 2;
sBarAttr.iWidth = pTextAttr->iRealHeight + 4;
sBarAttr.iHeight = pTextAttr->iRealWidth + 4;
break;
case 180:
sBarAttr.sCoord.iX = pTextAttr->sCoord.iX - pTextAttr->iRealWidth - 2;
sBarAttr.sCoord.iY = pTextAttr->sCoord.iY - pTextAttr->iRealHeight - 2;
sBarAttr.iWidth = pTextAttr->iRealWidth + 4;
sBarAttr.iHeight = pTextAttr->iRealHeight + 4;
break;
case 270:
sBarAttr.sCoord.iX = pTextAttr->sCoord.iX - 2;
sBarAttr.sCoord.iY = pTextAttr->sCoord.iY - pTextAttr->iRealWidth - 2;
sBarAttr.iWidth = pTextAttr->iRealHeight + 4;
sBarAttr.iHeight = pTextAttr->iRealWidth + 4;
break;
}
sBarAttr.psImageBuffer = pTextAttr->psImageBuffer;
//set reverse type
sBarAttr.iType = DRAW_REVERSE;
//call Bar routine to reverse it
DrawBar(&sBarAttr);
return TRUE;
}
INT DrawTextObject(_EplVarLinkTable *pEplVarLink)
{
_TextAttr *pTextAttr = &pEplVarLink->Data.sTextAttr;
CHAR StrData[STRING_LEN];
// explain expression to data
ExplainString(StrData, pEplVarLink->ExpData);
pTextAttr->ExpLength = strlen(StrData);
pTextAttr->pExp = (BYTE *)StrData;
pTextAttr->pFont = (BYTE *)pEplVarLink->FontName;
pTextAttr->psImageBuffer = &sImageBuffer;
OutText(pTextAttr);
if (pTextAttr->iReverse == TRUE && pTextAttr->iRealWidth > 0 && pTextAttr->iRealHeight > 0)
DrawTextReverseBox(pTextAttr);
if (pEplVarLink->ConutFlag || pEplVarLink->VarType == TEXT_VAR)
EplStoreTextBox(&pEplVarLink->sEraseBox, pTextAttr);
return TRUE;
}
INT DrawBarcodeObject(_EplVarLinkTable *pEplVarLink)
{
_BarCodeAttr *pBarCodeAttr = &pEplVarLink->Data.sBarcodeAttr;
CHAR StrData[STRING_LEN];
// explain expression to data
ExplainString(StrData, pEplVarLink->ExpData);
pBarCodeAttr->psImageBuffer = &sImageBuffer;
pBarCodeAttr->pFont = (BYTE *)pEplVarLink->FontName;
pBarCodeAttr->pExp = (BYTE *)StrData;
if (strlen((CHAR *)pBarCodeAttr->pExp) || pEplVarLink->ConutFlag)
pEplVarLink->psBarcodeTab->OutBarcode(pBarCodeAttr);
if (pEplVarLink->ConutFlag || pEplVarLink->VarType == BARCODE_VAR)
EplStoreBarcodeBox(&pEplVarLink->sEraseBox, pBarCodeAttr, pEplVarLink->psBarcodeTab);
return TRUE;
}
INT DrawGraphicObject(_EplVarLinkTable *pEplVarLink)
{
_PCXAttr *pPCXAttr = &pEplVarLink->Data.sPCXAttr;
CHAR StrData[STRING_LEN];
// explain expression to data
ExplainString(StrData, pEplVarLink->ExpData);
pPCXAttr->psImageBuffer = &sImageBuffer;
strcat(StrData, ".PCX");
pPCXAttr->pbFileName = (BYTE *)StrData;
PCXmain(pPCXAttr);
return TRUE;
}
VOID Draw2DBarcodeObject(_EplVarLinkTable *pEplVarLink)
{
CHAR StrData[STRING_LEN];
_PDFAttr *pPDFAttr;
_MaxiAttr *pMaxiAttr;
_DMatrixAttr *pDMatrixAttr;
_QRCodeAttr *pQRCodeAttr;
// explain expression to data
ExplainString(StrData, pEplVarLink->ExpData);
switch (pEplVarLink->VarType)
{
case PDF_VAR:
pPDFAttr = &(pEplVarLink->Data.sPDFAttr);
pPDFAttr->psImageBuffer = &sImageBuffer;
pPDFAttr->pExp = (BYTE *)StrData;
PDF(pPDFAttr);
break;
case MAXI_VAR:
pMaxiAttr = &(pEplVarLink->Data.sMaxiAttr);
pMaxiAttr->psImageBuffer = &sImageBuffer;
pMaxiAttr->pExp = (BYTE *)StrData;
Maxi(pMaxiAttr);
break;
case DMATRIX_VAR:
pDMatrixAttr = &(pEplVarLink->Data.sDMatrixAttr);
pDMatrixAttr->psImageBuffer = &sImageBuffer;
pDMatrixAttr->pExp = (BYTE *)StrData;
Dmatrix(pDMatrixAttr);
break;
case QRCODE_VAR:
pQRCodeAttr = &(pEplVarLink->Data.sQRCodeAttr);
pQRCodeAttr->psImageBuffer = &sImageBuffer;
pQRCodeAttr->pExp = (BYTE *)StrData;
QRCode(pQRCodeAttr);
break;
}
}
VOID DrawVariableObject(VOID)
{
INT i;
for (i = 0 ; i < VAR_LINK_TOTAL ; i++)
{
if (!sEplVarLinkTbl[i].ConutFlag)
{
if (sEplVarLinkTbl[i].VarType == NO_VAR)
return;
ReloadWaitTime();
EplEraseBox(&sEplVarLinkTbl[i].sEraseBox, &sImageBuffer);
switch (sEplVarLinkTbl[i].VarType)
{
case TEXT_VAR:
DrawTextObject(&sEplVarLinkTbl[i]);
break;
case BARCODE_VAR:
DrawBarcodeObject(&sEplVarLinkTbl[i]);
break;
case GRAPHIC_VAR:
DrawGraphicObject(&sEplVarLinkTbl[i]);
break;
// not support
case PDF_VAR:
case MAXI_VAR:
case DMATRIX_VAR:
case QRCODE_VAR:
Draw2DBarcodeObject(&sEplVarLinkTbl[i]);
break;
}
}
}
}
VOID ClearEplCounter(VOID)
{
INT i;
// clear counter link table
for (i = 0 ; i < VAR_LINK_TOTAL ; i++)
{
sEplVarLinkTbl[i].VarType = NO_VAR;
sEplVarLinkTbl[i].ConutFlag = FALSE;
memset((CHAR *)&sEplVarLinkTbl[i].sEraseBox, 0, sizeof(_EraseBox));
}
}
INT SearchEplCounter(VOID)
{
INT i;
INT Total = 0;
for (i = 0 ; i < VAR_LINK_TOTAL ; i++)
{
if ((sEplVarLinkTbl[i].VarType != NO_VAR) &&
(sEplVarLinkTbl[i].ConutFlag == TRUE))
{
Total += 1;
}
}
return Total;
}
VOID EplCounterAdd(CHAR *pData, INT Step)
{
INT i, Length = strlen(pData);
CHAR Buf[256];
CHAR *pString;
if (Step == 0)
return;
pString = pData + Length;
for (i = 0 ; i < Length ; i++)
Buf[i] = *(--pString);
for (i = 0 ; i < sizeof(Buf) ; i++)
{
if (Step == 0)
break;
if (i >= Length)
Buf[i] = '0';
if (isdigit(Buf[i]))
{
Buf[i] += Step % 10;
if (Buf[i] > '9')
{
Buf[i] -= 10;
Step = Step / 10 + 1;
}
else if (Buf[i] < '0')
{
Buf[i] += 10;
Step = Step / 10 - 1;
}
else
Step /= 10;
}
else if (isupper(Buf[i]))
{
Buf[i] += Step % 26;
if (Buf[i] > 'Z')
{
Buf[i] -= 26;
Step = (Step - Step % 26) / 26 + 1;
}
else if (Buf[i] < 'A')
{
Buf[i] += 26;
Step = Step / 26 - 1;
}
else
Step /= 26;
}
else if (islower(Buf[i]))
{
Buf[i] += Step % 26;
if (Buf[i] > 'z')
{
Buf[i] -= 26;
Step = (Step - Step % 26) / 26 + 1;
}
else if (Buf[i] < 'a')
{
Buf[i] += 26;
Step = Step / 26 - 1;
}
else
Step /= 26;
}
else
break;
}
if (Length < i)
Length = i;
pString = pData + Length;
for (i = 0 ; i < Length ; i++)
*(--pString) = Buf[i];
*(pData + Length) = '\0';
}
VOID EplCounterStep(VOID)
{
INT i;
for (i = 0 ; i < sFormData.CounterCnt ; i++)
{
if (sEplCounter[i].Sign == '-')
EplCounterAdd(sEplCounter[i].CounterVarData, -sEplCounter[i].IncDec);
else
EplCounterAdd(sEplCounter[i].CounterVarData, sEplCounter[i].IncDec);
sEplCounter[i].RealLength = strlen(sEplCounter[i].CounterVarData);
}
}
VOID EplRunCounter(VOID)
{
INT i;
for (i = 0 ; i < VAR_LINK_TOTAL ; i++)
{
if (sEplVarLinkTbl[i].ConutFlag)
{
ReloadWaitTime();
switch (sEplVarLinkTbl[i].VarType)
{
case NO_VAR:
return;
case TEXT_VAR:
EplEraseBox(&sEplVarLinkTbl[i].sEraseBox, &sImageBuffer);
DrawTextObject(&sEplVarLinkTbl[i]);
break;
case BARCODE_VAR:
EplEraseBox(&sEplVarLinkTbl[i].sEraseBox, &sImageBuffer);
DrawBarcodeObject(&sEplVarLinkTbl[i]);
break;
case GRAPHIC_VAR:
break;
// not support
case PDF_VAR:
case MAXI_VAR:
case DMATRIX_VAR:
case QRCODE_VAR:
// Draw2DBarcodeObject(&sEplVarLinkTbl[i]);
break;
}
}
}
EplCounterStep();
}
#endif
Epl2Var.h //
#ifndef EPL2VAR_H
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define EPL2VAR_H
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "XText.h"
#include "XBarcode.h"
#include "..\Parser.h"
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
/******************************************************************************
* *
* G L O B A L D E F I N E S *
* *
******************************************************************************/
#define VAR_LINK_TOTAL 50
#define EPL_VAR_TOTAL 50
#define EPL_COUNTER_TOTAL 20
/******************************************************************************
* *
* S T R U C T U R E D E F I N I T I O N S *
* *
******************************************************************************/
typedef enum
{
NO_VAR,
TEXT_VAR,
BARCODE_VAR,
PDF_VAR,
MAXI_VAR,
DMATRIX_VAR,
QRCODE_VAR,
GRAPHIC_VAR,
}_eEplVarType;
typedef struct
{
_eEplVarType VarType;
BYTE ConutFlag;
_EraseBox sEraseBox;
CHAR FontName[FONT_NAME_MAX];
_BarcodeTable *psBarcodeTab;
union
{
_TextAttr sTextAttr;
_BarCodeAttr sBarcodeAttr;
_PDFAttr sPDFAttr;
_MaxiAttr sMaxiAttr;
_DMatrixAttr sDMatrixAttr;
_QRCodeAttr sQRCodeAttr;
_PCXAttr sPCXAttr;
}Data;
CHAR ExpData[ STRING_LEN / 2 ];
}_EplVarLinkTable;
typedef struct
{
SHORT AllocLength;
SHORT RealLength;
CHAR Justification;
CHAR Prompt[40];
CHAR VarData[100];
}_EplVariable;
typedef struct
{
SHORT AllocLength;
SHORT RealLength;
CHAR Justification;
CHAR Sign;
LONG IncDec;
CHAR Prompt[40];
CHAR CounterVarData[30];
}_EplCounter;
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - N O I N I T I A L I Z E R S *
* *
******************************************************************************/
#ifdef EPL2VAR_C
#define EXTERN
#else
#define EXTERN extern
#endif
#if defined(__HITACHI__)
#pragma section HeapArea
#endif
EXTERN _EplVarLinkTable sEplVarLinkTbl[VAR_LINK_TOTAL];
#if defined(__HITACHI__)
#pragma section
#endif
EXTERN _EplVariable sEplVariable[EPL_VAR_TOTAL];
EXTERN _EplCounter sEplCounter[EPL_COUNTER_TOTAL];
/******************************************************************************
* *
* G L O B A L V A R I A B L E S - I N I T I A L I Z E R S *
* *
******************************************************************************/
/******************************************************************************
* *
* F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
VOID InitialEplVar(VOID);
INT SetVarFormat(INT, INT, CHAR, CHAR *);
INT SetCounterFormat(INT , INT , CHAR , CHAR , LONG , CHAR *);
_EplVarLinkTable *SearchFreeLinkTable(VOID);
INT ReceiveVariable(VOID);
INT GetVarData(INT , INT , INT , INT, CHAR *);
INT GetDateString(CHAR *, INT);
INT GetTimeString(CHAR *);
VOID EplStoreTextBox(_EraseBox *, _TextAttr *);
VOID EplStoreBarcodeBox(_EraseBox *, _BarCodeAttr *, _BarcodeTable *);
VOID EplEraseBox(_EraseBox *, _ImgBuf *);
INT DrawTextReverseBox(_TextAttr *);
VOID DrawVariableObject(VOID);
VOID ClearEplCounter(VOID);
INT SearchEplCounter(VOID);
VOID EplRunCounter(VOID);
#undef EXTERN
#ifdef __cplusplus
} /* End of extern "C" { */
#endif /* __cplusplus */
#endif
LineMode.c /
/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define LINEMODE_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <stdio.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XCore.h"
#include "XTimer.h"
#include "XProFile.h"
#include "..\Parser.h"
#include "..\ParserUtil.h"
#include "Epl2.h"
#if defined(EPL2)
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
STATIC _PrintCfg *pLineCfg;
STATIC BOOL LineModeEnable;
STATIC INT LineModeWaitTimeNum;
STATIC INT LineModeWaitTimeFF;
STATIC INT LineModeRow;
STATIC VOID InitLineMode(VOID)
{
FLOAT data;
pLineCfg = GrabPrintConfig();
LineModeEnable = FALSE;
if ( GetProfileInt("LINEMODE", &data) )
LineModeEnable = (BOOL)data;
LineModeWaitTimeNum = DELAY_TIME_NULL;
LineModeWaitTimeFF = 0;
if ( GetProfileInt("WAITING TIME FORM LINEMODE", &data) )
LineModeWaitTimeFF = (UINT)data;
LineModeRow = YCoord(pLineCfg->LineSpace);
if ( LineModeEnable )
ClearImageBuffer(&sImageBuffer); // clear image buffe
}
STATIC CHAR LineModeNextByte(VOID)
{
while ( 1 )
{
if ( CheckByte() )
{
ClrDelayTime(LineModeWaitTimeNum);
LineModeWaitTimeNum = SetDelayTime(LineModeWaitTimeFF);
return NextByte();
}
// auto form feed, even no <FORM FEED>(0x0C) is received.
if ( LineModeWaitTimeFF && !CheckDelayTimer(LineModeWaitTimeNum) )
{
if ( LineModeRow > YCoord(pLineCfg->LineSpace) )
{
LineModeRow = CheckPrint( (INT)pLineCfg->fPaperSize,
YCoord(pLineCfg->LineSpace),
0xFEED,
pLineCfg);
}
}
}
}
STATIC VOID LineModeEscCmd(VOID)
{
USHORT usNum;
UCHAR ucInput;
ucInput = LineModeNextByte();
switch ( ucInput )
{
case 'A': // select font 1..5
{
ucInput = LineModeNextByte();
if ( ucInput >= '1' && ucInput <= '5' )
{
pLineCfg->LineFontWidth = 1;
pLineCfg->LineFontHeight = 1;
sprintf((CHAR *)pLineCfg->LineFont, "%c.EFT", ucInput);
}
break;
}
case 'D': // set heating density
{
usNum = (LineModeNextByte()&0xf)*10
+ (LineModeNextByte()&0xf);
if ( /*usNum >= 0 && */usNum <= 15 ) // Acceptable Values: 0 - 15
pLineCfg->fDensity = (FLOAT)usNum / 15 * (DensityMax - DensityMin) + DensityMin;
break;
}
case 'F': // select ttf font
{
usNum = (LineModeNextByte()&0xf)*100
+ (LineModeNextByte()&0xf)*10
+ (LineModeNextByte()&0xf);
ucInput = LineModeNextByte(); // ignore delimiter
pLineCfg->LineFontWidth = usNum;
usNum = (LineModeNextByte()&0xf)*100
+ (LineModeNextByte()&0xf)*10
+ (LineModeNextByte()&0xf);
ucInput = LineModeNextByte(); // ignore delimiter
pLineCfg->LineFontHeight = usNum;
if ( (ucInput = LineModeNextByte()) == '"' )
{
INT i = 0;
while ( (ucInput = LineModeNextByte()) != '"' )
{
*(pLineCfg->LineFont + i) = ucInput;
if ( ++i >= sizeof(pLineCfg->LineFont) - 1 )
break;
}
*(pLineCfg->LineFont + i) = 0; // string end
}
break;
}
case 'L': // set row spacing in dot
{
usNum = (LineModeNextByte()&0xf)*100
+ (LineModeNextByte()&0xf)*10
+ (LineModeNextByte()&0xf);
pLineCfg->LineSpace = usNum;
break;
}
case 'M': // set left margin in mm
{
usNum = (LineModeNextByte()&0xf)*10
+ (LineModeNextByte()&0xf);
pLineCfg->ReferenceX = usNum * MM_DOT;
break;
}
case 'S': // set print speed
{
usNum = (LineModeNextByte()&0xf);
pLineCfg->Speed = SpeedRange((FLOAT)usNum);
break;
}
case 'Z': // <ESC>Z to go back to page mode
{
LineModeEnable = FALSE;
break;
}
}
}
VOID LineMode(VOID)
{
_TextAttr *pTextAttr;
UCHAR LineData[STRING_LEN];
UCHAR ucInput;
BOOL IgnoreLF = FALSE;
INT Column = 0;
InitLineMode();
while ( LineModeEnable )
{
ucInput = LineModeNextByte(); // get byte
switch ( ucInput )
{
case ESC_CHAR: // ESC sequence?
{
LineModeEscCmd();
break;
}
case CR_CHAR:
case LF_CHAR:
case FF_CHAR:
{
// if need to ignore LF
if ( ucInput == LF_CHAR && IgnoreLF )
{
IgnoreLF = FALSE;
break; // loop back
}
IgnoreLF = FALSE;
if ( ucInput == CR_CHAR ) // if is CR, ignore next LF
IgnoreLF = TRUE;
// print a line of LineData
LineData[Column] = 0; // line end
Column = 0;
pTextAttr = PutText( XCoord(0),
LineModeRow,
pLineCfg->LineFont,
pLineCfg->LineFontWidth,
pLineCfg->LineFontHeight,
LineData,
LANG_EPL );
// move to the next line
LineModeRow += pTextAttr->iRealHeight + pLineCfg->LineSpace;
if ( ucInput == FF_CHAR ) // form feed?
LineModeRow = (INT)pLineCfg->fPaperSize + 0xFEED;
// check it is last line, if it is, print label
LineModeRow = CheckPrint( LineModeRow,
YCoord(pLineCfg->LineSpace),
pTextAttr->iRealHeight,
pLineCfg );
break;
}
default:
{
// it's not special commands, read all the bytes
if ( Column < sizeof(LineData) - 1 )
LineData[Column++] = ucInput;
break;
}
}
}
ClrDelayTime(LineModeWaitTimeNum);
LineModeWaitTimeNum = DELAY_TIME_NULL;
}
#endif