views:

4126

answers:

4

I am struggling to get an Epson "ESC/POS" printer to print barcodes (Using Delphi) and want to test if the printer is not faulty. Do you know where I can find a program to print a barcode in "ESC/POS"? I suppose as a last resort an OPOS program will also be OK.

Also, a demo Delphi Program that works will also be fine. All the Delphi snippets I have so far is not working.

The printer I am using is an Epson TM-L60II

+1  A: 

Get the Microsoft POS For .Net 1.11, it's got an SDK that includes a sample application that performs all the basic operations on POS hardware. I'm using it all the time to test that cash drawers work ok for example.

There's also a source code included (in .Net), so you can see how they do it.

Miki Watts
Hi, thanks for this but I am really looking for a wee-bit easier way than doing all that - just a simple barcode app. already proven to work with.
mm2010
+4  A: 

I Have a full tests program written in Delphi 5 for the TMT88's but the source is abit big for here so here is the barcode bits

Please note that as its snippets from the full object some vars/functions may be missing

To get the barcode chars

{**
*    @param a ean13 barcode numeric value
*    @return the escpos code for the barcode print
*    Description uses escpos code, return code needed to print a ean13 barcode
*}
function TPrintEscPosToPort.getBarcodeEscPosCode(l_ean13:String):String;
    var
        l_return:String;
begin
    l_return :=  CHR(29) + 'k' + CHR(67) + CHR(12);
    l_return := l_return +  l_ean13; // Print bar code
    l_return := l_return +  l_ean13; // Print bar code number under thge barcode

    Result :=  l_return
end;

to print to a printer

{**
*    @param Printer Name, Item be printed, Cut the papers after the cut, #no of copies to print
*    @return boolen, true if it printed
*    Description prints a test page to the tysso printer
*}
function TPrintEscPosToPort.escPosPrint(const l_printer, l_textToPrint :String;l_cutPaper:Boolean=true;l_copies:integer=1): Boolean;
    var
        l_pPort,l_pName,l_tmp:String;
        i,x:integer;
        PrinterFile: TextFile;
begin
    // set result to false so any thing other then a good print will be false
    Result:= FALSE;

    try
        //Find if the printer exists, else set to defult -1
        i := Printer.Printers.IndexOf(l_printer);
        if (i > -1) then
        begin
            Printer.PrinterIndex := i;
            l_pName := Printer.Printers[i]; //Get the printer name (incase its the defult and not the one passed)
            l_pPort :=   Self.getPrinterPort(l_pName) ; // get the port name from the reg
        end;

        // If true add headers and footers to the passed text
        if (Self.aPrintHeadersFooters) then
        begin
            l_tmp := Self.getHeader()
                 +  l_textToPrint + Self.GetFooter();
        end
        else
        begin
            l_tmp := l_textToPrint;
        end;

      //Send the Document To the printer
      try
          for x:= 1 to l_copies do //Print multi-copies
          Begin              
              //Assign the file to a tmp file in the printer port
              if (length(trim(l_pPort)) > 0) then AssignFile(PrinterFile,l_pPort)
              else
              begin                         
                   //only use if we cant get the port 
                   //(may look bad as ctrl codes are still in place)
                   AssignPrn(PrinterFile);
                   l_tmp := Self.stripEscPos(l_tmp);
              end;

              Rewrite(PrinterFile);

              try
                  //Send the passed Text to the printer 
                  WriteLn(PrinterFile,l_tmp);

                  if (Self.aPrinterReset) then 
                       WriteLn(PrinterFile,escReset);  // Reset the printer alignment

                  if (l_cutPaper) then         
                       WriteLn(PrinterFile,escFeedAndCut); //Cut the paper if needed
              finally
                  CloseFile(PrinterFile);
                  Result:= true;
              end;
          end;
      except
      end;
    except
    end;

end;

Update

Here is a lost of control code constants from the code above, hopefully the names are descriptive enough.

const
     escNewLine   = chr(10);  // New line (LF line feed)
     escUnerlineOn   = chr(27) + chr(45) + chr(1);  // Unerline On
     escUnerlineOnx2 = chr(27) + chr(45) + chr(2);  // Unerline On x 2
     escUnerlineOff  = chr(27) + chr(45) + chr(0);  // Unerline Off
     escBoldOn       = chr(27) + chr(69) + chr(1);  // Bold On
     escBoldOff      = chr(27) + chr(69) + chr(0);  // Bold Off
     escNegativeOn   = chr(29) + chr(66) + chr(1);  // White On Black On'
     escNegativeOff  = chr(29) + chr(66) + chr(0);  // White On Black Off
     esc8CpiOn       = chr(29) + chr(33) + chr(16); // Font Size x2 On
     esc8CpiOff      = chr(29) + chr(33) + chr(0);  // Font Size x2 Off
     esc16Cpi        = chr(27) + chr(77) + chr(48); // Font A  -  Normal Font
     esc20Cpi        = chr(27) + chr(77) + chr(49); // Font B - Small Font
     escReset        = chr(27) + chr(64); //chr(27) + chr(77) + chr(48); // Reset Printer
     escFeedAndCut   = chr(29) + chr(86) + chr(65); // Partial Cut and feed

     escAlignLeft    = chr(27) + chr(97) + chr(48); // Align Text to the Left
     escAlignCenter  = chr(27) + chr(97) + chr(49); // Align Text to the Center
     escAlignRight   = chr(27) + chr(97) + chr(50); // Align Text to the Right
Re0sless
Thanks a Stack for this, I will test and advise/markup
mm2010
I've just spent a little while building something on top of this, there are a few things that could do with being documented in the codes above (the barcode routine doesn't seem to work, as it stands there). I'll format this up nicely and post it as a separate answer once I've finished testing it.
robsoft
Did you get it to work? if not I can post the full code (rather than just snippets).
Re0sless
I got it to work, thanks - the key is that (I think) the chr(12) in your barcode routine is setting the length of the barcode to be printed (ie, 12 chars). I'll tidy-up and add my routine to this question asap.
robsoft
A: 

plz i need thetysso cut code number like that 125,08 in that way

Hi do you mean the escFeedAndCut in my code? if So I'll post it when i get into work tomorrow.
Re0sless
A: 

"I'll tidy-up and add my routine to this question asap." I don't see it. Can you post it ? Thanks.

Marc