通用的SATO条码打印软件
SATO条码打印机,是一款比较好用的打印机。很多工矿企业,机场等对稳定性和性能要求比较高的场所,都会选用。偷下懒,目前还没有把它做成一个通用的条码打印软件。SATO条码打印机本身不提供类似于驱动程序接口的打印方式,只能使用底层的打印机指令集来打印,刚开始摸索了一段,最后还是解决了问题。
我把最关键的源代码贴出来,Delphi的:
1 打印部分
procedure TPkFrm.WriteToPrinter(psPrinterName,psStr:
string
; piPrintQty: integer);
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
lsPrintESC: string ;
begin
// PrinterName: 打印机名字(如:EPSON LQ-1600K等),S为打印机的ESC指令集等。
// ShowMessage(IntToStr(iPrintBarcode )+' = '+Printer.Printers[iPrintBarcode] + ' iPrintLabel = '+IntToStr(iPrintLabel ));
if not OpenPrinter(PChar(psPrinterName), Handle, nil) then
CreateError( ' 打印条码时出错!无法得到条码打印机 ' + IntToStr(GetLastError),nil, 1 );
with DocInfo1 do begin
pDocName : = PChar( ' SATO条码正在打印: ' + psStr);
pOutputFile : = nil;
pDataType : = ' RAW ' ;
end;
StartDocPrinter(Handle, 1 , @DocInfo1);
StartPagePrinter(Handle);
// 打印指令:开始
lsPrintESC : = Chr( 27 ) + ' A ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// page size
lsPrintESC : = Chr( 27 ) + ' A1 ' + ' 1216 ' + ' 3776 ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 1,2,3
lsPrintESC : = Chr( 27 ) + ' #E3 ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// aduject start point
// S := Chr(27)+'A3V'+edt9.Text +'H'+edt10.Text;
// WritePrinter(Handle, PChar(S), Length(S), N);
// 打印指令:条码 {BG Code128
// S := Chr(27)+'V0020' + #27 + 'H0001' + #27 + 'BG04260' + '2ZC100126614134523507';
lsPrintESC : = Chr( 27 ) + ' V0040 ' + Chr( 27 ) + ' H0001 ' + Chr( 27 ) + ' BG04256 ' + psStr;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 打印指令:条码字符
lsPrintESC : = Chr( 27 ) + ' V0320 ' + Chr( 27 ) + ' H0320 ' + Chr( 27 ) + ' L0101 ' + Chr( 27 ) + ' P03 ' + Chr( 27 ) + ' WB1 ' + psStr;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 打印指令:份数
lsPrintESC : = Chr( 27 ) + ' Q ' + IntToStr(piPrintQty);
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 打印指令:结束
lsPrintESC : = Chr( 27 ) + ' Z ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
lsPrintESC: string ;
begin
// PrinterName: 打印机名字(如:EPSON LQ-1600K等),S为打印机的ESC指令集等。
// ShowMessage(IntToStr(iPrintBarcode )+' = '+Printer.Printers[iPrintBarcode] + ' iPrintLabel = '+IntToStr(iPrintLabel ));
if not OpenPrinter(PChar(psPrinterName), Handle, nil) then
CreateError( ' 打印条码时出错!无法得到条码打印机 ' + IntToStr(GetLastError),nil, 1 );
with DocInfo1 do begin
pDocName : = PChar( ' SATO条码正在打印: ' + psStr);
pOutputFile : = nil;
pDataType : = ' RAW ' ;
end;
StartDocPrinter(Handle, 1 , @DocInfo1);
StartPagePrinter(Handle);
// 打印指令:开始
lsPrintESC : = Chr( 27 ) + ' A ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// page size
lsPrintESC : = Chr( 27 ) + ' A1 ' + ' 1216 ' + ' 3776 ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 1,2,3
lsPrintESC : = Chr( 27 ) + ' #E3 ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// aduject start point
// S := Chr(27)+'A3V'+edt9.Text +'H'+edt10.Text;
// WritePrinter(Handle, PChar(S), Length(S), N);
// 打印指令:条码 {BG Code128
// S := Chr(27)+'V0020' + #27 + 'H0001' + #27 + 'BG04260' + '2ZC100126614134523507';
lsPrintESC : = Chr( 27 ) + ' V0040 ' + Chr( 27 ) + ' H0001 ' + Chr( 27 ) + ' BG04256 ' + psStr;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 打印指令:条码字符
lsPrintESC : = Chr( 27 ) + ' V0320 ' + Chr( 27 ) + ' H0320 ' + Chr( 27 ) + ' L0101 ' + Chr( 27 ) + ' P03 ' + Chr( 27 ) + ' WB1 ' + psStr;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 打印指令:份数
lsPrintESC : = Chr( 27 ) + ' Q ' + IntToStr(piPrintQty);
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
// 打印指令:结束
lsPrintESC : = Chr( 27 ) + ' Z ' ;
WritePrinter(Handle, PChar(lsPrintESC), Length(lsPrintESC), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;
2 调用打印部分
procedure TPkFrm.PrintMode2(psPrintFile:
string
; piPrintLabelQty,piPrintBarcodeQty: integer);
var
liOriPrinterIndex: integer;
begin
liOriPrinterIndex : = Printer.PrinterIndex; // 把原来的默认打印机号保存起来,以便恢复
// 注意,这种方式打印,是通过打印机顺序号来自动分配要打的内容,所以不必指定一个默认打印机
// 每打一个内容,动态指定一个默认打印机
// 1 先打标签
// 打标签前,先把打标签的打印机设置为默认值,注意这一点很重要,要指导用户正确设置哪台是标签用的打印机
try
Printer.PrinterIndex: = GetPrintIndexFromName(sPrintLabel);
BarCodePrint.LoadFromFile(psPrintFile);
SetLabelColor(CDSMaster.FieldByName( ' OldDescr ' ).AsString);
BarCodePrint.PrepareReport;
// 打印份数,根据用户要求来定。一般单排打印两份,双排打印一份
BarCodePrint.PrintPreparedReport( '' ,piPrintLabelQty,True,frall)
except
CreateError( ' 打印标签时出错!可能是标签打印机编号设置不正确等原因 ' ,nil, 1 );
end;
// 2 再打条码
// 打标签前,先把打条码的打印机设置为默认值,注意这一点很重要,要指导用户正确设置哪台是条码用的打印机
try
// Printer.PrinterIndex:=iPrintBarcode;
// 打印份数,根据标签来定。一个标签要打两个条码
WriteToPrinter(sPrintBarcode,CDSMaster.FieldbyName( ' NewPkCode ' ).AsString,piPrintBarcodeQty); // 条码打印机顺序号,条码内容,份数
except
CreateError( ' 打印条码时出错!可能是条码打印机编号设置不正确等原因 ' ,nil, 1 );
end;
// 恢复到原先设置的默认打印机
try
Printer.PrinterIndex : = liOriPrinterIndex;
except
end;
end;
var
liOriPrinterIndex: integer;
begin
liOriPrinterIndex : = Printer.PrinterIndex; // 把原来的默认打印机号保存起来,以便恢复
// 注意,这种方式打印,是通过打印机顺序号来自动分配要打的内容,所以不必指定一个默认打印机
// 每打一个内容,动态指定一个默认打印机
// 1 先打标签
// 打标签前,先把打标签的打印机设置为默认值,注意这一点很重要,要指导用户正确设置哪台是标签用的打印机
try
Printer.PrinterIndex: = GetPrintIndexFromName(sPrintLabel);
BarCodePrint.LoadFromFile(psPrintFile);
SetLabelColor(CDSMaster.FieldByName( ' OldDescr ' ).AsString);
BarCodePrint.PrepareReport;
// 打印份数,根据用户要求来定。一般单排打印两份,双排打印一份
BarCodePrint.PrintPreparedReport( '' ,piPrintLabelQty,True,frall)
except
CreateError( ' 打印标签时出错!可能是标签打印机编号设置不正确等原因 ' ,nil, 1 );
end;
// 2 再打条码
// 打标签前,先把打条码的打印机设置为默认值,注意这一点很重要,要指导用户正确设置哪台是条码用的打印机
try
// Printer.PrinterIndex:=iPrintBarcode;
// 打印份数,根据标签来定。一个标签要打两个条码
WriteToPrinter(sPrintBarcode,CDSMaster.FieldbyName( ' NewPkCode ' ).AsString,piPrintBarcodeQty); // 条码打印机顺序号,条码内容,份数
except
CreateError( ' 打印条码时出错!可能是条码打印机编号设置不正确等原因 ' ,nil, 1 );
end;
// 恢复到原先设置的默认打印机
try
Printer.PrinterIndex : = liOriPrinterIndex;
except
end;
end;
主要支持SATO CL系列的,如SATO CL612e条码打印机,SATO CL408e/412e 条码打印机,SATO CL608e/612e 条码打印机。
SATO CL608e/612e 条码打印机
宽幅工业级条码打印机,热转印/热敏方式,打印速度可达 4英寸-8英寸/秒,
列印各式标签、服饰吊牌、洗涤布标、或特殊用,途贴纸等工商业运用