FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How Open Cash Drawer via printer? *working great*
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
How Open Cash Drawer via printer? *working great*
Posted: Sat Feb 14, 2009 02:37 PM
Dear All,

I need to open cash drawer that connect via printer (Epson TM-U220b).
The Cash Drawer is connect via RJ11 connect to printer. I've to send command to printer with FONT NAME 'control' but it must print a piece a paper every time to open.
I try to send command to open it but it do nothing.

What I do wrong?
Code (fw): Select all Collapse
 
*------------------*
Function OpenDrawer
local oFnt, oPrinter
 
   PRINTER oPrinter FROM USER
   // DEFINE FONT oFnt NAME 'Courier' SIZE 0, -8 OF oPrinter
   DEFINE FONT oFnt NAME 'control' SIZE 0, -8 OF oPrinter
   
//   oPrinter:StartPage()
   oPrinter:Say( 1, 1, 'A', oFnt )
   
   ENDPRINT
   
   oFnt:End()
 
return


Regards,
Dutch
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: How Open Cash Drawer via printer?
Posted: Sat Feb 14, 2009 02:53 PM
Hello Dutch,
this is my code. Maybe it is of some use for you.
Best regards,
Otto
Code (fw): Select all Collapse
<ol><li style="" class="li1">     if GetPvProfString( "Kassenlade", "UEBERDRUCKER" , "N", ".\INI\TOUCH.INI" ) ="J"</li><li style="" class="li2">                    oPrnDOS := TDosPrn():New("LPT1")</li><li style="" class="li1">                    *oPrnDOS:write(chr(27)+chr(112)+chr(15)+chr(15))</li><li style="" class="li2">                    oPrnDOS:write(chr(27)+chr(112)+chr(0)+chr(10)+chr(100))</li><li style="" class="li1">                    oPrnDOS:cFormFeed:="0"</li><li style="" class="li2">                    oPrnDOS:EndPage()           // optional</li><li style="" class="li1">                    oPrnDOS:End()</li><li style="" class="li2"> </li><li style="" class="li1">                else</li><li style="" class="li2"> </li><li style="" class="li1">                    oPrn   := PrintBegin("DRUCKER", .f., .f.,cPrnName )</li><li style="" class="li2">                    PAGE</li><li style="" class="li1">                    DEFINE FONT oFntNormal NAME "ARIAL" SIZE 16,40</li><li style="" class="li2">                    oPrn:Say( 0,5 ,   (chr(27)+chr(112)+chr(0)+chr(10)+chr(100))           , oFntNormal  )</li><li style="" class="li1">                    ENDPAGE</li><li style="" class="li2">                    ENDPRINT</li><li style="" class="li1">                    RELEASE FONT oFntNormal</li><li style="" class="li2"> </li><li style="" class="li1">                ENDIF</li><li style="" class="li2"> </li></ol>
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How Open Cash Drawer via printer?
Posted: Sat Feb 14, 2009 03:56 PM

Thanks Otto, I will try.

Regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: How Open Cash Drawer via printer?
Posted: Sun Feb 15, 2009 06:28 AM
Dutch

This is my code, note i do not use tdosprn because of usb limitations

HTH

Richard
Code (fw): Select all Collapse
<ol><li style="" class="li1"> </li><li style="" class="li2">ICAISSE := GetPvProfString("PRINTER","TICKET",,CINIFile )   // this is the printer you should change to identify yours</li><li style="" class="li1">OPRN    := TPrinter():New("TEST Impression", .F. , .F. , ICAISSE, .T.)</li><li style="" class="li2"> </li><li style="" class="li1">Ntext   := SPACE(45)</li><li style="" class="li2">NTEXT   := CHR(27) +'p'+ CHR(0)+CHR(10)+CHR(25)</li><li style="" class="li1"> </li><li style="" class="li2">CFILE := "c:\test.TXT"  // could be any name</li><li style="" class="li1">nHandle := fCreate( cFile )</li><li style="" class="li2">FWRITE( nHandle, NTEXT)</li><li style="" class="li1">fClose( nHandle )</li><li style="" class="li2"> </li><li style="" class="li1">PrintFileRaw(ICAISSE,CFILE)  // this line opens the cash draw </li><li style="" class="li2"> </li><li style="" class="li1">FERASE("C:\test.txt")</li><li style="" class="li2"> </li><li style="" class="li1"> </li></ol>
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 845
Joined: Sun Oct 09, 2005 05:36 PM
Re: How Open Cash Drawer via printer?
Posted: Mon Feb 16, 2009 03:55 PM

Richard,

Where is function PrintFileRaw()?
regards
Paco

____________________

Paco
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: How Open Cash Drawer via printer?
Posted: Tue Feb 17, 2009 06:31 AM
Paco

It is a xharbour function

Code (fw): Select all Collapse
PrintFileRaw()
Prints a file to a Windows printer in RAW mode. 
Syntax
PrintFileRaw( <cPrinterName>, ;
              <cFileName>   , ;
             [<cJobTitle>]    ) --> nErrorCode

Arguments
<cPrinter> 
This is a character string holding the name of the printer to use for printing. 
<cFileName> 
The file to print must be specified as a character string, including path and extension. If the path is omitted, the file is searched in the current directory. 
<cJobTitle> 
This is an optional character string which appears as print job description in the spooler. It defaults to <cFileName>. Return
The function returns 1 on success or a value less than zero on error. See the example for error codes. 
Description
Function PrintFileRaw() prints a file to a Windows printer in RAW mode. This restricts file types for printing to enhanced metafiles (EMF), ASCII text, and raw data, which includes all printer specific file types such as PostScript and PCL. The file is sent to the Windows spooler which processes the print job. The function returns zero when the file is successfully transferred to the spooler. Note that this is no guarantee for a printout. If the physical printer is out of paper, for example, the spooler reports an error to the user. This type of failure cannot be detected by PrintFileRaw(). 
Info
See also: GetPrinters(), GetDefaultPrinter(), PrinterExists(), PrinterPortToName() 
Category: Printer functions , xHarbour extensions 
Source: rtl\tprinter.c 
LIB: xhb.lib 
DLL: xhbdll.dll 

Example
// The example prints a file in RAW mode and demonstrates
// the possible return values of PrintFileRaw().

   PROCEDURE Main()
      LOCAL cPrinter := GetDefaultPrinter()
      LOCAL cFile    := "MyFile.Txt"
      LOCAL nResult  := -1
      LOCAL cMsg     := "PrintFileRaw(): "

      CLS
      IF Empty( cPrinter )
         ? "No default printer found"
         QUIT
      ENDIF

      nResult := PrintFileRaw( cPrinter, cFile, "Test for PrintFileRaw()" )

      SWITCH nResult
      CASE -1
         cMsg += "Invalid parameters passed to function" ; EXIT
      CASE -2
         cMsg += "WinAPI OpenPrinter() call failed"      ; EXIT
      CASE -3
         cMsg += "WinAPI StartDocPrinter() call failed"  ; EXIT
      CASE -4
         cMsg += "WinAPI StartPagePrinter() call failed" ; EXIT
      CASE -5
         cMsg += "WinAPI malloc() of memory failed"      ; EXIT
      CASE -6
         cMsg += "File " + cFile + " not found"          ; EXIT
      DEFAULT
         cMsg += cFile + " PRINTED OK!!!"
      END

      ? cMsg
   RETURN
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: How Open Cash Drawer via printer?
Posted: Tue Mar 03, 2009 07:57 AM

Dear Otto & Richard,

Otto's samples is working well with 16bits and 32bits
Richard's sample is working weel with 32bits.

Thanks for all of you and kindness,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 845
Joined: Sun Oct 09, 2005 05:36 PM
Re: How Open Cash Drawer via printer? *working great*
Posted: Tue Mar 03, 2009 09:56 PM

thanks richard,
don´t found cause i use harbour
regards
paco

____________________

Paco

Continue the discussion