Send EPL Command to a USB printer

Send EPL Command to a USB printer

Postby JimTheo » Mon Jul 01, 2013 9:48 am

I try to send EPL commands to a USB Zebra Printer but I cannot.
How may I Use the tPrinter class to send only commands (raw data?)

With lpt printer i send data to lpt1. With usb I cannot do this.
JimTheo
 
Posts: 15
Joined: Thu Sep 21, 2006 5:01 pm

Re: Send EPL Command to a USB printer

Postby Marc Vanzegbroeck » Mon Jul 01, 2013 10:16 am

With the USB Zebra Printer, you don't need to send EPL-commands.
Normaly there is a windows-driver, and you can use that printer with FWH, like a normal printer
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Send EPL Command to a USB printer

Postby JimTheo » Mon Jul 01, 2013 4:10 pm

Marc Vanzegbroeck wrote:With the USB Zebra Printer, you don't need to send EPL-commands.
Normaly there is a windows-driver, and you can use that printer with FWH, like a normal printer


Marc Thanks for your reply.
I allready use the Zebra Driver to print Labels. But now I need to print to "too small" labels and special printouts :
a. Small Barcode 129
b. Vertical Description
and some other that i must use EPL commands to do it.
JimTheo
 
Posts: 15
Joined: Thu Sep 21, 2006 5:01 pm

Re: Send EPL Command to a USB printer

Postby Marc Vanzegbroeck » Mon Jul 01, 2013 4:15 pm

JimTheo,

You can also print barcode and vertical text using the windows printer-driver.

I don't know what you mean with 'too small'. Is it a small font?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Send EPL Command to a USB printer

Postby JimTheo » Thu Jul 04, 2013 6:17 am

I Finally, used the Zebra Designer Driver Pass-through Mode and it works nice.
Here is the link https://km.zebra.com/kb/index?page=content&id=SO8099 with more information.

EPL2 is usefull when you need to print i.e. vertical Barcode and Horizontal description an price to a Label.
JimTheo
 
Posts: 15
Joined: Thu Sep 21, 2006 5:01 pm

Re: Send EPL Command to a USB printer

Postby JimTheo » Thu Jul 04, 2013 6:19 am

I found code to .net for send raw data to a printer driver.
It uses winspool.drv functions.
My problem is how to declare the DOCINFO type

Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As DOCINFO) As Long

Is there any idea?
JimTheo
 
Posts: 15
Joined: Thu Sep 21, 2006 5:01 pm

Re: Send EPL Command to a USB printer

Postby fafi » Thu Jul 04, 2013 11:16 am

Code: Select all  Expand view

#include "fivewin.ch"

#define FONT_BESAR    chr(27)+chr(33)+chr(16)
#define FONT_KECIL_1  chr(27)+chr(33)+chr(4)
#define FONT_KECIL_2  chr(27)+chr(33)+chr(5)

function Main()

   local cNext := "",i,cFile,nHandle
   local cPrinter := "Epson LX-300+" // this printer connected to USB port
   
   cFile := "printer.prn"
   
   if file(cFile)
      DeleteFile(cFile)
   endif
   
   nHandle := fcreate(cFile)
   
   
   if nHandle <= 0
      ?"Error Create File "+cFile
      return .f.
   endif  
           cNext += FONT_KECIL_1+"----------------------------------------------------------------"+CRLF                    
           cNext += ""+CRLF
           cNext += FONT_BESAR+"BIG FONT"+FONT_KECIL_1+" SMALL FONT"+CRLF
           cNext += ""+CRLF
           cNext += FONT_KECIL_1+"----------------------------------------------------------------"+CRLF                    
           
               fwrite(nHandle,cNext)
               fClose( nHandle )
               nHasil := PrintFileRaw(cPrinter,cFile)
               
               ferase(cFile)
               
               if nHasil < 0
                  ?"Error to print "+cFile
                  return .f.
               endif  
   
RETURN .t.
 


Best Regards
Fafi
User avatar
fafi
 
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: Send EPL Command to a USB printer

Postby JimTheo » Thu Jul 04, 2013 1:37 pm

Where may I find PrintFileRaw() code?
JimTheo
 
Posts: 15
Joined: Thu Sep 21, 2006 5:01 pm

Re: Send EPL Command to a USB printer

Postby fafi » Fri Jul 05, 2013 11:29 pm

Code: Select all  Expand view


#pragma BEGINDUMP

#undef UNICODE

#include <windows.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"

#ifndef __XHARBOUR__
   #define ISCHAR( n )           HB_ISCHAR( n )
#endif

#define MAX_FILE_NAME 1024
#define BIG_BUFFER (1024*32)

HB_FUNC ( ENUMPRINTERS )
{
  UCHAR *Result ;
  DWORD x, Flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS ;
  LPSTR Name = NULL ;
  DWORD Level = 5 ;
  PRINTER_INFO_5 *pPrinterEnum, *pFree;
  PRINTER_INFO_4 *pPrinterEnum4, *pFree4;
  DWORD cbBuf  ;
  DWORD BytesNeeded=0 ;
  DWORD NumOfPrinters=0 ;
  OSVERSIONINFO osvi ;  //  altered to check Windows Version
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  GetVersionEx (&osvi);
  if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  {
    Level = 4 ;
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *) hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree4 = pPrinterEnum4 = (PRINTER_INFO_4 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x < NumOfPrinters ; x++, pPrinterEnum4++ )
        {
          strcat(Result,pPrinterEnum4->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree4) ;
    }
    else
      hb_retc("") ;
  }
  else
   {
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *) hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree = pPrinterEnum = (PRINTER_INFO_5 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x < NumOfPrinters ; x++, pPrinterEnum++ )
        {
          strcat(Result,pPrinterEnum->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree) ;
    }
    else
      hb_retc("") ;
  }
}

HB_FUNC( WINDEFAULTPRINTER )
{
  DWORD x, y ;
  UCHAR lpReturnedString[MAX_FILE_NAME] ;
  x = GetProfileString("windows","device","",lpReturnedString,MAX_FILE_NAME-1);
  y = 0 ;
  while ( y < x && lpReturnedString[y] != ',' )
    y++ ;
  hb_retclen(lpReturnedString,y) ;
}

HB_FUNC( PRINTFILERAW )
{
  UCHAR  printBuffer[BIG_BUFFER], *cPrinterName, *cFileName, *cDocName ;
  HANDLE  hPrinter, hFile ;
  DOC_INFO_1 DocInfo ;
  DWORD nRead, nWritten, rVal = -1 ;
  if (ISCHAR(1) && ISCHAR(2))
  {
    cPrinterName= (UCHAR*)hb_parc(1) ;
    cFileName= (UCHAR*)hb_parc(2) ;
    if ( OpenPrinter(cPrinterName, &hPrinter, NULL) != 0 )
    {
      DocInfo.pDocName = (UCHAR*)hb_parc(3) ;
      DocInfo.pOutputFile = NULL ;
      DocInfo.pDatatype = "RAW" ;
      if ( StartDocPrinter(hPrinter,1,(char *) &DocInfo) != 0 )
      {
        if ( StartPagePrinter(hPrinter) != 0 )
        {
          hFile = CreateFile(cFileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)   ;
          if (hFile != INVALID_HANDLE_VALUE )
           {
            while (ReadFile(hFile, printBuffer, BIG_BUFFER, &nRead, NULL) && (nRead > 0))
            {
              if (printBuffer[nRead-1] == 26 )
                nRead-- ; // Skip the EOF() character
              WritePrinter(hPrinter, printBuffer, nRead, &nWritten) ;
            }
            rVal = 1 ;
            CloseHandle(hFile) ;
          }
          else
            rVal= -6 ;
          EndPagePrinter(hPrinter) ;  // 28/11/2001 10:16
        }
        else
          rVal = -4 ;
        EndDocPrinter(hPrinter);
      }
      else
        rVal= -3 ;
      ClosePrinter(hPrinter) ;
    }
    else
      rVal= -2 ;
  }
  hb_retnl(rVal) ;
}

#pragma ENDUMP

 
User avatar
fafi
 
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: Send EPL Command to a USB printer

Postby JimTheo » Tue Jul 09, 2013 7:00 am

Fafi thanks a lot for help.
I'll try the code.
I must compile it with bcc? (I'm not so familiar to C)
JimTheo
 
Posts: 15
Joined: Thu Sep 21, 2006 5:01 pm

Re: Send EPL Command to a USB printer

Postby cnavarro » Tue Jul 09, 2013 7:25 am

Add all that code at the end of your fichero.prg and compile as you normally
Regards
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Send EPL Command to a USB printer

Postby fafi » Tue Jul 09, 2013 1:58 pm

cnavarro wrote:Add all that code at the end of your fichero.prg and compile as you normally
Regards


Yes like this :

Code: Select all  Expand view


#include "fivewin.ch"

#define FONT_BESAR    chr(27)+chr(33)+chr(16)
#define FONT_KECIL_1  chr(27)+chr(33)+chr(4)
#define FONT_KECIL_2  chr(27)+chr(33)+chr(5)

function Main()

   local cNext := "",i,cFile,nHandle
   local cPrinter := "Epson LX-300+" // this printer connected to USB port
   
   cFile := "printer.prn"
   
   if file(cFile)
      DeleteFile(cFile)
   endif
   
   nHandle := fcreate(cFile)
   
   
   if nHandle <= 0
      ?"Error Create File "+cFile
      return .f.
   endif  
           cNext += FONT_KECIL_1+"----------------------------------------------------------------"+CRLF                    
           cNext += ""+CRLF
           cNext += FONT_BESAR+"BIG FONT"+FONT_KECIL_1+" SMALL FONT"+CRLF
           cNext += ""+CRLF
           cNext += FONT_KECIL_1+"----------------------------------------------------------------"+CRLF                    
           
               fwrite(nHandle,cNext)
               fClose( nHandle )
               nHasil := PrintFileRaw(cPrinter,cFile)
               
               ferase(cFile)
               
               if nHasil < 0
                  ?"Error to print "+cFile
                  return .f.
               endif  
   
RETURN .t.



#pragma BEGINDUMP

#undef UNICODE

#include <windows.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"

#ifndef __XHARBOUR__
   #define ISCHAR( n )           HB_ISCHAR( n )
#endif

#define MAX_FILE_NAME 1024
#define BIG_BUFFER (1024*32)

HB_FUNC ( ENUMPRINTERS )
{
  UCHAR *Result ;
  DWORD x, Flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS ;
  LPSTR Name = NULL ;
  DWORD Level = 5 ;
  PRINTER_INFO_5 *pPrinterEnum, *pFree;
  PRINTER_INFO_4 *pPrinterEnum4, *pFree4;
  DWORD cbBuf  ;
  DWORD BytesNeeded=0 ;
  DWORD NumOfPrinters=0 ;
  OSVERSIONINFO osvi ;  //  altered to check Windows Version
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  GetVersionEx (&osvi);
  if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  {
    Level = 4 ;
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *) hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree4 = pPrinterEnum4 = (PRINTER_INFO_4 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum4,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x < NumOfPrinters ; x++, pPrinterEnum4++ )
        {
          strcat(Result,pPrinterEnum4->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree4) ;
    }
    else
      hb_retc("") ;
  }
  else
   {
    EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,0,&BytesNeeded,&NumOfPrinters) ;
    if (BytesNeeded > 0)
    {
      Result = (UCHAR *) hb_xgrab(BytesNeeded) ;
      *Result = '\0' ;
      pFree = pPrinterEnum = (PRINTER_INFO_5 *)  hb_xgrab(BytesNeeded) ;
      cbBuf = BytesNeeded ;
      if (EnumPrinters(Flags,Name,Level,(LPBYTE) pPrinterEnum,cbBuf,&BytesNeeded,&NumOfPrinters))
      {
        for (x=0 ; x < NumOfPrinters ; x++, pPrinterEnum++ )
        {
          strcat(Result,pPrinterEnum->pPrinterName) ;
          strcat(Result,";") ;
        }
      }
      hb_retc(Result) ;
      hb_xfree(Result) ;
      hb_xfree(pFree) ;
    }
    else
      hb_retc("") ;
  }
}

HB_FUNC( WINDEFAULTPRINTER )
{
  DWORD x, y ;
  UCHAR lpReturnedString[MAX_FILE_NAME] ;
  x = GetProfileString("windows","device","",lpReturnedString,MAX_FILE_NAME-1);
  y = 0 ;
  while ( y < x && lpReturnedString[y] != ',' )
    y++ ;
  hb_retclen(lpReturnedString,y) ;
}

HB_FUNC( PRINTFILERAW )
{
  UCHAR  printBuffer[BIG_BUFFER], *cPrinterName, *cFileName, *cDocName ;
  HANDLE  hPrinter, hFile ;
  DOC_INFO_1 DocInfo ;
  DWORD nRead, nWritten, rVal = -1 ;
  if (ISCHAR(1) && ISCHAR(2))
  {
    cPrinterName= (UCHAR*)hb_parc(1) ;
    cFileName= (UCHAR*)hb_parc(2) ;
    if ( OpenPrinter(cPrinterName, &hPrinter, NULL) != 0 )
    {
      DocInfo.pDocName = (UCHAR*)hb_parc(3) ;
      DocInfo.pOutputFile = NULL ;
      DocInfo.pDatatype = "RAW" ;
      if ( StartDocPrinter(hPrinter,1,(char *) &DocInfo) != 0 )
      {
        if ( StartPagePrinter(hPrinter) != 0 )
        {
          hFile = CreateFile(cFileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)   ;
          if (hFile != INVALID_HANDLE_VALUE )
           {
            while (ReadFile(hFile, printBuffer, BIG_BUFFER, &nRead, NULL) && (nRead > 0))
            {
              if (printBuffer[nRead-1] == 26 )
                nRead-- ; // Skip the EOF() character
              WritePrinter(hPrinter, printBuffer, nRead, &nWritten) ;
            }
            rVal = 1 ;
            CloseHandle(hFile) ;
          }
          else
            rVal= -6 ;
          EndPagePrinter(hPrinter) ;  // 28/11/2001 10:16
        }
        else
          rVal = -4 ;
        EndDocPrinter(hPrinter);
      }
      else
        rVal= -3 ;
      ClosePrinter(hPrinter) ;
    }
    else
      rVal= -2 ;
  }
  hb_retnl(rVal) ;
}

#pragma ENDUMP

 
 
 
User avatar
fafi
 
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: Send EPL Command to a USB printer

Postby JimTheo » Wed Jul 10, 2013 7:27 am

Thanks a lot.
I'll Try it.
JimTheo
 
Posts: 15
Joined: Thu Sep 21, 2006 5:01 pm

Re: Send EPL Command to a USB printer

Postby Jack » Sun Jul 14, 2013 10:24 am

Hi,

Could you post some code using USB Zebra Printer .

How to fix the size of labels ?

How to use a Isbt128 Font .

Thanks .
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: Send EPL Command to a USB printer

Postby fafi » Sun Jul 14, 2013 8:11 pm

Jack wrote:Hi,

Could you post some code using USB Zebra Printer .

How to fix the size of labels ?

How to use a Isbt128 Font .

Thanks .


Tell me about ESC Command.. for Zebra Printer...
Please post here..thanks

Fafi,
User avatar
fafi
 
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 53 guests