Page 1 of 1

How Open Cash Drawer via printer? *working great*

PostPosted: Sat Feb 14, 2009 2:37 pm
by dutch
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: Select all  Expand view
 
*------------------*
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

Re: How Open Cash Drawer via printer?

PostPosted: Sat Feb 14, 2009 2:53 pm
by Otto
Hello Dutch,
this is my code. Maybe it is of some use for you.
Best regards,
Otto
Code: Select all  Expand view
  1.     if GetPvProfString( "Kassenlade", "UEBERDRUCKER" , "N", ".\INI\TOUCH.INI" ) ="J"
  2.                     oPrnDOS := TDosPrn():New("LPT1")
  3.                     *oPrnDOS:write(chr(27)+chr(112)+chr(15)+chr(15))
  4.                     oPrnDOS:write(chr(27)+chr(112)+chr(0)+chr(10)+chr(100))
  5.                     oPrnDOS:cFormFeed:="0"
  6.                     oPrnDOS:EndPage()           // optional
  7.                     oPrnDOS:End()
  8.  
  9.                 else
  10.  
  11.                     oPrn   := PrintBegin("DRUCKER", .f., .f.,cPrnName )
  12.                     PAGE
  13.                     DEFINE FONT oFntNormal NAME "ARIAL" SIZE 16,40
  14.                     oPrn:Say( 0,5 ,   (chr(27)+chr(112)+chr(0)+chr(10)+chr(100))           , oFntNormal  )
  15.                     ENDPAGE
  16.                     ENDPRINT
  17.                     RELEASE FONT oFntNormal
  18.  
  19.                 ENDIF
  20.  

Re: How Open Cash Drawer via printer?

PostPosted: Sat Feb 14, 2009 3:56 pm
by dutch
Thanks Otto, I will try.

Regards,
Dutch

Re: How Open Cash Drawer via printer?

PostPosted: Sun Feb 15, 2009 6:28 am
by Richard Chidiak
Dutch

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

HTH

Richard
Code: Select all  Expand view
  1.  
  2. ICAISSE := GetPvProfString("PRINTER","TICKET",,CINIFile )   // this is the printer you should change to identify yours
  3. OPRN    := TPrinter():New("TEST Impression", .F. , .F. , ICAISSE, .T.)
  4.  
  5. Ntext   := SPACE(45)
  6. NTEXT   := CHR(27) +'p'+ CHR(0)+CHR(10)+CHR(25)
  7.  
  8. CFILE := "c:\test.TXT"  // could be any name
  9. nHandle := fCreate( cFile )
  10. FWRITE( nHandle, NTEXT)
  11. fClose( nHandle )
  12.  
  13. PrintFileRaw(ICAISSE,CFILE)  // this line opens the cash draw
  14.  
  15. FERASE("C:\test.txt")
  16.  
  17.  

Re: How Open Cash Drawer via printer?

PostPosted: Mon Feb 16, 2009 3:55 pm
by Francisco Horta
Richard,

Where is function PrintFileRaw()?
regards
Paco

Re: How Open Cash Drawer via printer?

PostPosted: Tue Feb 17, 2009 6:31 am
by Richard Chidiak
Paco

It is a xharbour function

Code: Select all  Expand view

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


 

Re: How Open Cash Drawer via printer?

PostPosted: Tue Mar 03, 2009 7:57 am
by dutch
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

Re: How Open Cash Drawer via printer? *working great*

PostPosted: Tue Mar 03, 2009 9:56 pm
by Francisco Horta
thanks richard,
don´t found cause i use harbour
regards
paco