Senin, Maret 24, 2008

Pustaka Fungsi Delphi untuk Printer Label SATO seri CL-408

SATO menggunakan SATO command dalam mengirimkan perintah pencetakan ke Printer/LPT1. Alternatif lain bisa menggunakan printer driver SATO, hanya untuk Ms. Windows. Dengan printer driver ini, dimungkinkan mencetak label ke printer SATO dari aplikasi Windows ke printer melalui mekanisme pencetakan standar Windows.

SATO Command ini hanya digunakan untuk pencetakan langsung dari aplikasi ke printer melalui port LPT.

Berikut cuplikan pustaka Object Pascal / Delphi untuk SATO:

unit SATOLabelPrinterLib;

const
/// Line Options
loVertikal = 1;
loHorizontal = 2;
/// Barcode symbol
bsCodabar = 0;
bsCode39 = 1;
bsInterleaved2of5 = 2;
bsUPC_A_EAN13 = 3;
bsEAN8 = 4;
/// Text Rotation Direction
rdNormal = 0;
rd90d = 1;
rd180d = 2;
rd270d = 3;
/// Vector Type Font
vtHelveticaBoldProportional = 'A';
vtHelveticaBoldFixed = 'B';

// print length
pl7i = 'AR';
pl14i = 'AX';

/// QR Code Model
qrModel2 = 0;
qrModel1 = 1;
qrCodeMicro = 2;
//// QR Error Correction Level
qrECL7p = 'L';
qrECL15p = 'M';
qrECL25p = 'Q';
qrECL30p = 'H';
/// QR Connection Mode
qrconnNormal = 0;
qrconnConnection = 1;
/// QR Input Data Type
qrInputTypeNumeric = 1;
qrInputTypeAlphaNumeric = 2;
qrInputTypeKanji = 3;

type
TSATOLineDotRange = 1..99;
TBufferPCX = array[1..2000] of Char; //size of pcx file
/// QR Cell Size
TqrCellSize = 1..32;
/// QR Total Connection Number
TqrTotalConnectionNumber = 1..16;
TCharSpacing = (csProportional, csFixed);
/// SATO Hardware Command
function SATOCommandStart:String;
function ClearInternalMemory:String;
function SetPrintLength(const SATOPrintLength : String): String; //updated by Dyah
function SetAdditionalPrintLength:String;
// function SetPrintDarkness:String;
function SetPrintDarkness(const Grayscale : Integer):String;
function SATOSendJob:String;
function SATOCopyPrint(const CopyofPrint : Integer) : String; //copy of print
function SATOCommandClose:String;
function SetPrintSpeed(const SATOPrintSpeed: Integer): String;
/// SATO Graphical Command
function WriteText(const Rotation, PosHoriz, PosVert, CharPitch : integer;
const CharacterSpacing : TCharSpacing;
const FontType : String; const FontSizeX, FontSizeY : Integer;
const Teks: String):String;
function WriteTextVector(const PosHoriz, PosVert: Integer; const FontType: char;
const FontWidth, FontHeight,FontVariation : integer;
const Teks: String):String;
function DrawBox(const Rotation, PosHoriz, PosVert, BoxWidthX, BoxWidthY, LengthX,
LengthY: Integer): String;
function DrawLine(const Rotation, PosHoriz, PosVert : integer;
const LineOrientation, LineWidth, LineLength : Integer):String;
function DrawLineBarcodeBD25(const PosHoriz, PosVert : integer;
const BarcodeSymbol, NarrowBarDot, BarHeightDot: Integer;
const FullBarcodeData: String): String;
function DrawLineBarcodeB(const PosHoriz, PosVert : integer;
const BarcodeSymbol, NarrowBarDot, BarHeightDot: Integer;
const FullBarcodeData: String): String;
function DrawPCXImage(const PosHoriz, PosVert: Integer; PCXFileName: String):String;
function SATOPrintReverse(const Rotation, PosHoriz, PosVert, LengthHoriz, LengthVert, CharPitch: Integer):String;
function Draw2DBarcodeQRCode(const PosHoriz, PosVert, QRModel, InputType : Integer;
const ErrCorrectionLevel : Char; CellSize : TqrCellSize;
const qrData : String; const qrDataSize : Integer):String;

const
sESC = CHR(27);

var
SATOLineOrientation : array[1..2] of char= ('V', 'H');
LabelPrinterType : (lpSATO, lpZEBRA);

implementation

-------------------
function SATOCommandStart:String;
begin // Tell LPT1 parallel port {tell the printer(SATO) to starting command}
Result := sESC + 'A';
end;

function SATOSendJob:String;
begin
Result := sESC + 'Q1';
end;

function WriteText(const Rotation, PosHoriz, PosVert, CharPitch : integer;
const CharacterSpacing : TCharSpacing;
const FontType : String; const FontSizeX, FontSizeY : Integer;
const Teks: String):String;
var str : string;
begin ////
case CharacterSpacing of
csProportional : str := 'PS';
csFixed : str := 'PR';
end;
Result := sESC+ '%'+IntToStr(Rotation) + sESC + Format('P%.2d',[CharPitch]) + sESC+
str + sESC +
Format('H%.3d',[PosHoriz]) + sESC + Format('V%.4d',[PosVert]) + sESC +
Format('L%.2d%.2d',[FontSizeX,FontSizeY]) + sESC +
FontType + Teks;
end;

function DrawLineBarcodeB(const PosHoriz, PosVert : integer;
const BarcodeSymbol, NarrowBarDot, BarHeightDot: Integer;
const FullBarcodeData: String): String;
begin //// write(f,sESC+'%0'+sESC+'H0210'+sESC+'V0120'+sESC+'B101090*' + FBarCode + '*');
Result := sESC + '%0' + sESC +
Format('H%.3d',[PosHoriz]) + sESC +
Format('V%.4d',[PosVert]) + sESC +
Format('B%d%.2d%.3d*',[BarcodeSymbol, NarrowBarDot, BarHeightDot])+
FullBarcodeData +'*';
end;

function DrawLine(const Rotation, PosHoriz, PosVert : integer;
const LineOrientation, LineWidth, LineLength : Integer):String;
begin ////
Result := sESC+'%' + IntToStr(Rotation) + sESC +
Format('H%.3d',[PosHoriz]) + sESC +
Format('V%.3d',[PosVert]) + sESC +
Format('FW%.2d%s%.4d',[LineWidth, SATOLineOrientation[LineOrientation], LineLength]);
end;

-------------

Fungsi-fungsi diatas adalah pembungkus SATO Command, sehingga programmer berikutnya tidak perlu lagi belajar SATO Command, tapi cukup menggunakan pustaka fungsi diatas dari aplikasinya secara langsung ataupun membungkusnya lagi dalam bentuk komponen/ VCL.

2 komentar:

Teguh Ramanal mengatakan...

Contoh penggunaan pustaka fungsi diatas:



procedure TRLabel.Print;
var JF : TextFile;
CommandList : TStrings;
n : Integer;
begin
/// Isi dulu stringlist CommandList dengan isi dan layout label yang diinginkan

try
CommandList := TStringList.Create;
CommandList.Add(SATOCommandStart);
CommandList.Add(WriteText(rdNormal, 64, 296, 2, csProportional, 'U', 1, 1, 'QUANTITY'));

/// line horizon CommandList.Add(DrawLine(rdNormal, 707, 320, loHorizontal, 3, 115));
/// rectangle CommandList.Add(DrawBox(rdNormal, 705, 300, 3, 3, 119, 65));

CommandList.Add(SATOSendJob);
CommandList.Add(SATOCommandClose);

AssignFile(JF,'LPT1');
Rewrite(JF);
for n := 0 to CommandList.Count-1 do
begin
Write(JF,CommandList.Strings[n]);
end;
CloseFile(JF);

Teguh Ramanal mengatakan...

Contoh jika dilakukan langsung secara manual:

Perintah SATOnya:

[ESC]A
[ESC]H0050[ESC]V0100[ESC]L0303[ESC]XMSATO
[ESC]H0050[ESC]V0200[ESC]B103100*SATO*
[ESC]H0070[ESC]V0310[ESC]L0101[ESC]XUSATO
[ESC]Q1[ESC]Z

Kode Delphinya (tidak semuanya saya masukkan, cape.. ^-^):

procedure TRLabel.Print;
const kodeESC = Chr(27);
var JF : TextFile;
n : Integer;
begin

AssignFile(JF,'LPT1');
Rewrite(JF);

Write(JF,kodeESC+'A');
Write(JF,kodeESC+'H0050'+kodeESC+'V0200'+'B103100*SATO*');
Write(JF,kodeESC+'Q1');
Write(JF,kodeESC+'Z');

CloseFile(JF);

END;