真的不是很难:这个是我写的一个例子,只要搞懂了sendcommand指令就行了。
我现在没有在那个项目组。老板让我帮他找一个人。
const
TestLib = 'Trace.dll';//trace.dll就是厂家提供的。
procedure openport(port
Char);
stdcall;
external TestLib ;
procedure setup(a, b, c, d, e, f:Integer);
stdcall;
external TestLib;
procedure sendcommand(command
Char);
stdcall;
external TestLib;
procedure intloadimage(filename, image_name, image_type
Char);
stdcall;
external TestLib;
procedure extloadimage(filename, image_name, image_type
Char);
stdcall;
external TestLib;
procedure putimage(x:Integer;
y:Integer;
filemane
Char;
degree
Char);
stdcall;
external TestLib;
proceduredo
wnloadimage(filename
Char;
degree:Integer;
name
Char);
stdcall;
external TestLib;
procedure ecTextOut(x:Integer;
y:Integer;
b:Integer;
c
Char;
d
Char;
e:Integer;
f:Integer);
stdcall;
external TestLib;
procedure ecTextOutR(x:Integer;
y:Integer;
b:Integer;
c
Char;
d
Char;
e:Integer;
f:Integer;
g:Integer);
stdcall;
external TestLib;
procedure ecTextDownLoad(b:Integer;
c
Char;
d
Char;
e:Integer;
f:Integer;
g:Integer;
name
Char);
stdcall;
external TestLib;
procedure closeport;
stdcall;
external TestLib;
function isready(): boolean;
stdcall;
external TestLib;
function TFrmPrint.OpenPrint: boolean;
begin
openport('0');
// 0-> LPT1;
1-> COM1;
2->COM2
Result := True;
end;
procedure TFrmPrint.ClosePrint;
begin
closeport();
end;
procedure TFrmPrint.SetPrint(CopyCount: integer);
var
CopyStr: string;
begin
sendcommand('^Q35,2');
//标签长度35,间隔2
sendcommand('^W70');
//标签宽度70
sendcommand('^H10');
//明暗度10
sendcommand('^S2');
//打印速度2inch/s
sendcommand('^AD');
//打印模式 d-热感模式
CopyStr := '^C'+ IntToStr(CopyCount);
sendcommand(PAnsiChar(CopyStr));
//每张标签打印份数
sendcommand('^R0');
//左起印点
sendcommand('~Q0');
//上起印点
sendcommand('^O0');
//剥离感应器设定 0
sendcommand('^D0');
//每张标签裁切一次之设定?
sendcommand('^E12');
//停歇点设定 有间隔的标签为12
sendcommand('^P1');
//最后一标签打印分数
end;
procedure TFrmPrint.DoPrint(PrintList: TStrings);
var
Text: string;
i: integer;
PrintText, LeftStr, TopStr, TopStrEx: string;
CopyCount: integer;
LeftPos: integer;
TopPos: integer;
begin
GetLabelPos(LeftPos, TopPos);
LeftStr := IntToStr(LeftPos);
TopStr := IntToStr(TopPos);
TopStrEx := IntToStr(TopPos + 40);
for i := 0 to PrintList.Count - 1do
begin
if CheckCancel() then
Break;
CopyCount := TString.ObjPtrToInt(PrintList.Objects
);
SetPrint(CopyCount);
PrintText := PrintList.Strings;
SetInfo('正在打印标签 - ' + PrintText + '...');
Application.ProcessMessages();
sendcommand('^L');
//开始新标签
Text := 'BQ,' + LeftStr + ',' + TopStr + ',2,5,40,0,0,' + PrintText;
sendcommand(PAnsiChar(Text));
Text := 'AB,' + LeftStr + ',' + TopStrEx + ',1,1,0,0,' + PrintText;
sendcommand(PAnsiChar(Text));
sendcommand('E');
//结束标签并开始打印
// sleep(50);
end;
end;