我该在哪里找到“ESC/POS”爱普生条形码测试程序?

9
我正在努力让一个爱普生“ESC/POS”打印机(使用Delphi)打印条形码,并希望测试打印机是否有故障。您知道我在哪里可以找到一个打印“ESC/POS”条形码的程序吗?如果万不得已,一个OPOS程序也可以。此外,一个可行的演示Delphi程序也可以。到目前为止,我拥有的所有Delphi片段都不能正常工作。我使用的打印机是爱普生TM-L60II。

我已经有了参考程序 - 但它在我的打印机上无法正常工作,这就是为什么我想要一个已经测试过可以正常工作的程序。 - Johan Bresler
是的,我的打印机是串口的 - 你能帮忙吗? - Johan Bresler
试试这个程序,我写了一段时间了,但它应该仍然可以工作。http://support.relogic.co.uk/sk/TillTest.zip - stukelly
2个回答

8

我有一个完整的测试程序,用Delphi 5编写了TMT88的程序,但源代码太大了,所以这里只提供条形码位。

请注意,由于它是从完整对象中提取的片段,因此可能缺少一些变量/函数。

获取条形码字符的方法:

{**
*    @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;

打印到打印机

{**
*    @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;

更新

以下是上述代码中的控制代码常量列表,希望名称足够描述。

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

1
我已经让它工作了,谢谢 - 关键是你条形码例程中的chr(12)设置了要打印的条形码的长度(即12个字符)。我会尽快整理并将我的例程添加到这个问题中。 - robsoft

1
获取 Microsoft POS For .Net 1.11,它有一个包含样例应用程序的 SDK,可以执行 POS 硬件的所有基本操作。例如,我经常使用它来测试钱箱是否正常工作。
此外,还包括源代码(使用 .Net 编写),因此您可以了解它们是如何实现的。

嗨,谢谢您的回复,但我真的正在寻找一种比做所有这些更简单的方法 - 只是一个已经被证明可以使用的简单条形码应用程序。 - Johan Bresler
首先,OP正在寻找一个Delphi应用程序而不是.NET,您能否指定您答案中提到的示例代码的名称? - AaA

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接