delphi的ESC/POS指令代码片断

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, SPComm, VCL.printers;

type
  TForm1 = class(TForm)
    Comm1: TComm;
    Comm2: TComm;
    Comm3: TComm;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label2: TLabel;
    Edit2: TEdit;
    Button3: TButton;
    Label3: TLabel;
    Edit3: TEdit;
    Button4: TButton;
    Label4: TLabel;
    Edit4: TEdit;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    ListBox1: TListBox;
    Button10: TButton;
    Button11: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure openport(PrinterName:PAnsiChar);stdcall;far; external 'tsclib.dll';
procedure closeport; external 'tsclib.dll';
procedure sendcommand(Command:PAnsiChar);stdcall;far;external 'tsclib.dll';
procedure setup(LabelWidth, LabelHeight, Speed, Density, Sensor, Vertical, Offset:PAnsiChar);stdcall; far; external 'tsclib.dll';
procedure downloadpcx(Filename,ImageName:PAnsiChar);stdcall;far;external 'tsclib.dll';
procedure barcode(X, Y, CodeType, Height, Readable, Rotation, Narrow, Wide, Code :PAnsiChar); stdcall; far; external 'tsclib.dll';
procedure printerfont(X, Y, FontName, Rotation, Xmul, Ymul, Content:PAnsiChar);stdcall;far; external 'tsclib.dll';
procedure clearbuffer; external 'tsclib.dll';
procedure printlabel(NumberOfSet, NumberOfCopoy:PAnsiChar);stdcall; far;external 'tsclib.dll';
procedure formfeed;external 'tsclib.dll';
procedure nobackfeed; external 'tsclib.dll';
procedure windowsfont (X, Y, FontHeight, Rotation, FontStyle, FontUnderline : integer; FaceName, TextContect:PAnsiChar);stdcall;far;external 'tsclib.dll';

procedure TForm1.Button10Click(Sender: TObject);
begin
  listbox1.clear;
  listbox1.items.assign(Printer.printers );
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Enabled := True;
  Comm1.CommName := Edit1.Text;
  Try
    Comm1.StartComm;
    Button1.Enabled := False;
  Except
    ShowMessage('開啟ComPort錯誤');
  End;
end;

procedure TForm1.Button2Click(Sender: TObject);
var s:Ansistring;
begin
    if Button1.Enabled then
       Button1.Click;
    s := Chr(27) + Chr(99) + Chr(48) + Chr(2);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := 'QA00000001' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '2013-04-08 11:30' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '店名:壽比南山健康餐飲 站號:01' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '單A2013040800001 頁1' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '桌號:01' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '健康蔬食鍋x1         300' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '小計:               300' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '服務費:                0' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '合計:                300' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '現金:1000' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '找零: 700' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '收銀員:林壽山' + Chr(10);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := Chr(12);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := Chr(27) + Chr(99) + Chr(48) + Chr(3);
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := Chr(27) + Chr(64) ;
    Comm1.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Button3.Enabled := True;
  Comm2.CommName := Edit2.Text;
  Try
    Comm2.StartComm;
    Button3.Enabled := False;
  Except
    ShowMessage('開啟ComPort錯誤');
  End;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  Button4.Enabled := True;
  Comm3.CommName := Edit3.Text;
  Try
    Comm3.StartComm;
    Button4.Enabled := False;
  Except
    ShowMessage('開啟ComPort錯誤');
  End;
end;

procedure TForm1.Button5Click(Sender: TObject);
var s:Ansistring;
begin
    // 彈出錢箱
    {
#1B#40#1B#70#0#32#C8
    }
    if Button3.Enabled then
      Button3.Click;
    s := chr(27) + chr(64)+ chr(27) + chr(112) + chr(0) + chr(50) + chr(200) ;
    Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
end;

procedure TForm1.Button6Click(Sender: TObject);
var s:Ansistring;
begin
  //打印機 啟動成功!
  {
#1B#40
2014/04/08 13:40:35#0A#0d
#1B#64#02
#1D#21#11
印表機:1-啟動成功#0A
#1D#21#00
#1B#64#05
#1D#56#00
  }
      if Button3.Enabled then
      Button3.Click;
  // 初始化 #1B#40
  s:=  chr(27) + chr(64);
  Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
  s:=  '2014/04/08 13:40:35'+ chr(10)+ chr(13) ; //#0A#0d
  Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
  s:=  chr(27) + chr(100) + chr(2);   //#1B#64#02
  Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
  s:=  chr(29) + chr(33) + chr(17) ;  //#1D#21#11
  Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
  s:=  '印表機:1-啟動成功'+ chr(10);  //#0A
  Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s:=  chr(29) + chr(33) + chr(0) ;  //#1D#21#00
  Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
  s:=  chr(27) + chr(100) + chr(5);    //#1B#64#05
  Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    // 切紙  #1D#56#0
        s := Chr(29) + Chr(86) + Chr(0) ;
    Comm2.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
end;

procedure TForm1.Button7Click(Sender: TObject);
var s:Ansistring;
begin
  if Button4.Enabled then
    Button4.Click;
  s:=  chr(27) + chr(64);
  Comm3.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    //   '123456789012345678901234567890'
    s := '壽比南山健康餐飲'+ Chr(10) + Chr(13) ;
    Comm3.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '外帶' + Chr(10) + Chr(13);
    Comm3.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '樹葡萄四物飲x1            300'+ Chr(10) + Chr(13) ;
    Comm3.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
    s := '小計                      500' ;
    Comm3.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
end;

procedure TForm1.Button8Click(Sender: TObject);
var s:Ansistring;
begin
  if Button4.Enabled then
    Button4.Click;
  // 初始化
  s:=  chr(27) + chr(64);
  Comm3.WriteCommData(PAnsiChar(s),Length(s)); //送出指令給遠端
end;

procedure TForm1.Button9Click(Sender: TObject);
var i:integer;
begin
if trim(edit4.Text)='' then exit;

openport(pansichar(ansistring(edit4.Text)));
        for i:=1 to 1 do
         begin
          clearbuffer;
          sendcommand('DIRECTION 1');
          windowsfont(5, 115, 30, 0, 2, 0, '新細明體', pansichar('店家名稱:美又美'));
          windowsfont(5, 150, 30, 0, 2, 0, '新細明體', pansichar('財產歸屬:總務課'));
          windowsfont(5, 190, 30, 0, 2, 0, '新細明體', pansichar('登帳日:103/02'));
          windowsfont(5, 255, 30, 0, 2, 0, '新細明體', pansichar('最低耐用年限:5 年'));
          windowsfont(5, 290, 30, 0, 2, 0, '新細明體', pansichar('財產編號:3140302001-2038'));
          barcode('50', '335', '39', '64', '1', '0', '2', '4', ('3140302001-2038'));
          printlabel('1', '1');
        end;
          closeport;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
  edit4.Text := ListBox1.Items[ListBox1.ItemIndex];
end;

end.

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享