Delphi POS – 通过USB Printer打开钱抽屉


procedure USBOpenCashDrawer(PrinterName: String);
var
 // use winspool
 Handle, hDeviceMode: THandle;
 N: DWORD;
 DocInfo1: TDocInfo1;
 Device, Driver, Port: array [0 .. 255] of char;
 ThePrinter: string;
 <a title="code" href="http://superlevin.ifengyuan.tw/tag/code/">code</a>:ansistring;
begin
 ThePrinter := PrinterName;
 Code := chr(27) + chr(64)+ chr(27) + chr(112) + chr(0) + chr(50) + chr(200);
 <a title="Printer" href="http://superlevin.ifengyuan.tw/tag/printer/">Printer</a>.PrinterIndex := Printer.Printers.Indexof(ThePrinter);
 Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
 PrinterName := Format('%s', [Device]);
 if not WinSpool.OpenPrinter(PChar(PrinterName), Handle, nil) then
 begin
 // ShowMessage('Error : ' + IntToStr(GetLastError));
 Exit;
 end;
 with DocInfo1 do
 begin
 pDocName := 'Test';
 pOutputFile := nil;
 pDataType := 'RAW';
 end;
 WinSpool.StartDocPrinter(Handle, 1, @DocInfo1);
 WinSpool.StartPagePrinter(Handle);
 WinSpool.WritePrinter(Handle, PAnsiChar(Code), Length(Code), N);
 WinSpool.EndPagePrinter(Handle);
 WinSpool.EndDocPrinter(Handle);
 WinSpool.ClosePrinter(Handle);
end;

联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678