Delphi 我在哪里可以找到一个;电子稳定控制系统/位置“;爱普生条形码测试程序?

Delphi 我在哪里可以找到一个;电子稳定控制系统/位置“;爱普生条形码测试程序?,delphi,barcode,point-of-sale,opos,epson,Delphi,Barcode,Point Of Sale,Opos,Epson,我正在努力让爱普生“ESC/POS”打印机打印条形码(使用Delphi),并想测试打印机是否有故障。你知道我在哪里可以找到一个在“ESC/POS”中打印条形码的程序吗?我想作为最后手段,OPOS计划也可以 另外,一个Delphi的演示程序也可以。到目前为止,我所有的Delphi代码片段都不起作用 我使用的打印机是一台Epson TM-L60II获取Microsoft POS For.Net 1.11,它有一个SDK,其中包含一个示例应用程序,可在POS硬件上执行所有基本操作。例如,我一直在用它来

我正在努力让爱普生“ESC/POS”打印机打印条形码(使用Delphi),并想测试打印机是否有故障。你知道我在哪里可以找到一个在“ESC/POS”中打印条形码的程序吗?我想作为最后手段,OPOS计划也可以

另外,一个Delphi的演示程序也可以。到目前为止,我所有的Delphi代码片段都不起作用


我使用的打印机是一台Epson TM-L60II

获取Microsoft POS For.Net 1.11,它有一个SDK,其中包含一个示例应用程序,可在POS硬件上执行所有基本操作。例如,我一直在用它来测试现金抽屉是否正常工作


还有一个源代码(在.Net中),所以你可以看到他们是如何做到的。

我有一个完整的测试程序,是用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

嗨,谢谢你,但我真的在寻找一种比这更简单的方法——一个简单的条形码应用程序。已经证明可以使用。首先,OP要求的是delphi应用程序而不是.NET,您是否愿意指定您的答案中提到的示例代码名称?我已经有了参考资料-它在我的打印机上不工作,这就是为什么我想要一个已经工作的测试程序。是的,我的打印机是串行的-您可以帮助吗?试试这个程序,我不久前写的,但它应该仍然有效。我让它工作了,谢谢-关键是(我认为)条形码例程中的chr(12)正在设置要打印的条形码的长度(即12个字符)。我会尽快整理一下,把我的例行公事加到这个问题上。