Kevinn3
Posts: 1
Joined: Thu Apr 19, 2018 2:04 pm

Lazarus Printing in Thermal printer, Barcode.pas error

Thu Apr 19, 2018 2:07 pm

hello, i have doing a project and it went well to print a barcode in thermal printer using lazarus for windows 10
then i try in debian stretch raspberry pi and it cant print any barcode, the printer queue is on the list but then after processing it just dissapear

Code: Select all

unit Printertestingg;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Buttons, Printers, StBarC;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    StBarCode1: TStBarCode;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
    procedure PrintString(S:String);
    procedure PrintSample;
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }
procedure TForm1.PrintString(S: String);
var
  Written: Integer;
begin
  Printer.Write(S[1], Length(S), Written);
end;

const
  MaxBufSize = 256;

procedure TForm1.PrintSample; // a kind of procedure
begin
   //Mencetak header dan isi struk
   PrintString('========Selamat Datang========='+LineEnding);
   PrintString('=======Penyewaan  Loker========'+LineEnding);
   PrintString('Tercetak Pada '+DateTimeToStr(Now));//Menampilkan waktu sekarang
   PrintString('Item : 1 Loker    = Rp. 35000,-'+LineEnding);
   PrintString('==============================='+LineEnding);
   PrintString('Total             = Rp. 35000,-'+LineEnding);
   PrintString(LineEnding);
   PrintString('  Simpan Struk pembayaran ini  '+LineEnding);
   PrintString('Struk ini akan digunakan untuk '+LineEnding);
   PrintString('buka loker yang digunakan      '+LineEnding);
   PrintString('Barcode : '+LineEnding);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Printer.SetPrinter('POS-58');  //Deklarasi nama printer
  Printer.Title := Caption;
 // Printer.RawMode := True;
 // Printer.BeginDoc;
 // PrintSample;
 // Printer.EndDoc;
  Printer.RawMode := False;
  Printer.BeginDoc;
  Printer.Canvas();
//  StBarCode1.Code:=IntToStr(Random(999999)); //menghasilkan nilai random untuk barcode
//  StBarCode1.PaintToCanvas(Printer.Canvas,Rect(100,-200,100,200)); //print barcode dalam bentuk canvas
  Printer.EndDoc;
end;


end.

fruitoftheloom
Posts: 23548
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Lazarus Printing in Thermal printer, Barcode.pas error

Thu Apr 19, 2018 3:59 pm

Kevinn3 wrote:
Thu Apr 19, 2018 2:07 pm
hello, i have doing a project and it went well to print a barcode in thermal printer using lazarus for windows 10
then i try in debian stretch raspberry pi and it cant print any barcode, the printer queue is on the list but then after processing it just dissapear

Code: Select all

unit Printertestingg;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Buttons, Printers, StBarC;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    StBarCode1: TStBarCode;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
    procedure PrintString(S:String);
    procedure PrintSample;
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }
procedure TForm1.PrintString(S: String);
var
  Written: Integer;
begin
  Printer.Write(S[1], Length(S), Written);
end;

const
  MaxBufSize = 256;

procedure TForm1.PrintSample; // a kind of procedure
begin
   //Mencetak header dan isi struk
   PrintString('========Selamat Datang========='+LineEnding);
   PrintString('=======Penyewaan  Loker========'+LineEnding);
   PrintString('Tercetak Pada '+DateTimeToStr(Now));//Menampilkan waktu sekarang
   PrintString('Item : 1 Loker    = Rp. 35000,-'+LineEnding);
   PrintString('==============================='+LineEnding);
   PrintString('Total             = Rp. 35000,-'+LineEnding);
   PrintString(LineEnding);
   PrintString('  Simpan Struk pembayaran ini  '+LineEnding);
   PrintString('Struk ini akan digunakan untuk '+LineEnding);
   PrintString('buka loker yang digunakan      '+LineEnding);
   PrintString('Barcode : '+LineEnding);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Printer.SetPrinter('POS-58');  //Deklarasi nama printer
  Printer.Title := Caption;
 // Printer.RawMode := True;
 // Printer.BeginDoc;
 // PrintSample;
 // Printer.EndDoc;
  Printer.RawMode := False;
  Printer.BeginDoc;
  Printer.Canvas();
//  StBarCode1.Code:=IntToStr(Random(999999)); //menghasilkan nilai random untuk barcode
//  StBarCode1.PaintToCanvas(Printer.Canvas,Rect(100,-200,100,200)); //print barcode dalam bentuk canvas
  Printer.EndDoc;
end;


end.

Does Raspbian Stretch via CUPS support the unknown Printer ?
Rather than negativity think outside the box !
RPi 4B 4GB (SSD Boot) RaspiOS64 ARM64
Asus ChromeBox 3 Celeron is my other computer...

Return to “General programming discussion”