Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Sending hex values to the printer

edited July 2005 in General
I have receipt printer with an auto cut feature. In the past we've
commuicated with the printer directly. I'm now using Report Builder to print
the receipts. My question is how do I send the hex command that cuts the
receipt? Is it possible to do it from the report iself or do I need to do it
in code. If it's in code what method would I call.
tppReport.???(hexcommand).

Preston

Comments

  • edited July 2005
    Hi Preston

    ReportBuilder renders to the printer using the Delphi TCanvas class and via
    calls to Windows GDI functions.

    We do not have any direct experience with sending escape or hex codes
    directly to the printer driver. According to the Windows API documentation,
    the ExtEscape function allows applications to access capabilities of a
    particular device that are not available through GDI. Try searching the
    Windows API docs and Google for more information.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2005
    Hi Nick,

    If I use the printer object, from the printers unit, using the escape works
    fine. However, I can not get it work work using the device context provided
    by the TPPReport.Printer.DC. The difference is that when I use the printer
    (Delphi) object I have do to a beginDoc and a EndDoc. My understanding is
    that this is creating a seperate print job. I want to embed my esc commands
    into the middle of the TppReport's print job rather than creating a seperate
    print job. I've tried running the code after different events but I haven't
    found one that works yet.

    Can you offer any other suggestions?

    {Thanks to Peter Below for posting 90% of this code}
    procedure cut;
    type
    escdata = packed record
    datalen: Word;
    databuf: Array [0..128] of Char;
    end;
    var
    escdata2 : escData;
    data : string;
    begin
    //data := EncodeLogoStr(gResumeRecTbl.FieldByName('CutCmd').AsString);
    data := #27#100#51;

    with escdata2 do begin
    datalen := Length( data );
    StrLCopy( databuf, Pchar( data ), 128);
    end;

    // works
    {Printer.BeginDoc;
    if Escape( Printer.canvas.handle, PASSTHROUGH, 0, @escdata2, Nil )= 0 then
    ShowMessage('Escape Failed');
    Printer.EndDoc;}

    // doesn't work
    if Escape( repCustomPrePrinted.Printer.DC, PASSTHROUGH, 0, @escdata2,
    Nil )= 0 then
    ShowMessage('Escape Failed');
  • edited July 2005
    it IS doable, been there done that
    so, you are on the right track here, the only thing you need to do is to
    call the Escape function through a RapFunction (in Rap)
    i suppose you have the Enterprise version, if so drop me an email and i'll
    provide the function to you

    alternative : normally if you look at the fonts for this printer (every pos
    printer driver surfaces 'own printer specific' fonts, you'll probably notice
    a 'control' font which let you do just that
    furthermore, look at the printer preferences, normally you'll have an option
    that the printer uses 'forms' or 'receipts', i'de go for forms so that every
    'form' you print will be cut

    maybe you should post the type of pos printer you are using
    cu
    marc


  • edited July 2005
    Hi Marc

    It's good to hear someone has been down this road before. I don't have the
    enterprise version. I'm using a Star TSP600, however our customer's could be
    using almost anything, I suppose. I'll start looking for this control font
    and let you know what I find.

    Is there not a event that will allow to send the cut command to the printer
    inside of the RB print job?

    Preston

  • edited July 2005
    I'm not having any luck finding a control font.

    The driver does allow me to tell it to cut after every job. My current
    report prints a receipt and then a credit card signature section. This all
    started because I need to cut in the middle of the two. I could break it out
    into two seperate print jobs and then let the driver handle it, but it's not
    preferable.

    I'd still like to figure it out, we do stuff with logos (coupons) and need
    to make sure the right bitmap prints at the bottom or top. Like the cut
    command these are handled using escape codes.

    Thanks for the help,
    Preston


  • edited July 2005
    Preston,
    ok don't panic
    if you do not have RAP then you still have the events on the components to
    handle this
    i do suppose that you have the reports done in code (flexible for you)
    otherwise you'll need to always have the same component somewhere
    just place a TppVariable and in the onprint event send your escape codes to
    the printer using the Escape() function using the report.printer.handle
    (look for the right syntax)
    it should work just fine (as it does for me)
    still some kind of special font should be surfaced by the printer to do
    these kind of things (cutting and openining a drawer etc)
    cu
    marc


  • edited July 2005
    Preston,
    i have a SP298 installed (so an old one)
    and my driver does have the control font mentioned
    maybe you should open wordpad, go to page settings, select the driver for
    the tsp600, accept the settings and look in the font box for the 'Control'
    font
    if you do not see it, do you see other printer specific fonts (they have no
    truetype indication on the left of them)
    cu
    marc


  • edited July 2005
    FYI.... I contacted Star and the control font is not available is using the
    USB driver it's only available if you're using the line driver.

    I tried your suggestion of putting a TppVariable on my report and the
    appropriate code in the on print event. The problem with this is that the
    cut command does not work if I use the TppReport.Printer.DC. All the code
    gets ran, but nothing happens.

    It does work if I use the Printer object from the Printers unit, so I know
    the esc code is correct.

    You mentioned using TppReport.Printer.Handle. I'm assuming you mean
    TppReport.Printer.PrinterHandle. The problem with that is that the Escape
    function wants a HDC not a handle. Can you post a small snippet of what
    you're doing so I can compare the two?

    Basically I have the following

    // works but as a seperate print document
    {Printer.BeginDoc;
    if Escape( Printer.canvas.handle, PASSTHROUGH, 0, @escdata2, Nil )= 0 then
    ShowMessage('Escape Failed');
    Printer.EndDoc;}

    // doesn't work
    if Escape( repCustomPrePrinted.Printer.DC, PASSTHROUGH, 0, @escdata2,
    Nil )= 0 then
    ShowMessage('Escape Failed');


  • edited July 2005
    Preston,
    can you mail me your email address at
    marc_at_xls_dot_be
    i'll email you the code then that should work
    cu
    marc

  • edited July 2005
    Hi Marc I sent you an email but I'm not certain you got it.

    My email address is mcfarlandp @ posim.net (drop the spaces)

    Thanks for your help.


  • edited July 2005
    no i didn't
    sending the mail

This discussion has been closed.