[fpc-pascal] raw printing throught USB port / WINDOWS
Chriss Kalogeropoulos
iz.iznogood at gmail.com
Tue Jan 13 15:32:30 CET 2015
Hi,
map the USB Port to a Virtual Serial Port and open the Port as File using
CreateFile using name "\\.\COMxxx"
Then write to the port with the usual API file commands
Even better wrap this to a Stream (or FileStream) descendant and use
Stream.Write commands
Read and Seek should do nothing
I hope this helps
Chriss
On Tue, Jan 13, 2015 at 3:13 PM, Virgo Pärna <virgo.parna at mail.ee> wrote:
> On Tue, 13 Jan 2015 10:41:55 -0200, Philippe <philippe at quarta.com.br>
> wrote:
> >
> > First: could anyone tell me I have the possibility to access USB
> > printer in raw mode with the "basic" FPC package (not using Lazarus
> > packages/components)?
> >
>
> If you have USB printer installed , then winunits-base package has
> winspool unit.
> Following sample is with string beeing ansisstring and Char AnsiChar.
>
> procedure PrintCodesToPrinter(const APrinterName, APrintData: string);
> type
> TDoc_Info_1 = record
> DocName,
> OutputFile,
> Datatype: PChar;
> end;
> var
> Written: DWORD;
> DocInfo: TDoc_Info_1;
> PHandle: THandle;
> begin
> if APrintData = '' then //nothing to print
> exit;
> DocInfo.DocName := 'POS';
> DocInfo.OutputFile := nil;
> DocInfo.Datatype := 'RAW';
> if not OpenPrinter(PChar(APrinterName), PHandle, nil) then
> raise Exception.CreateFmt('Error opening printer "%s"',
> [APrinterName]);
> try
> StartDocPrinter(PHandle, 1, @DocInfo);
> StartPagePrinter(PHandle);
> WritePrinter(PHandle, @APrintData[1], Length(APrintData), Written);
> EndPagePrinter(PHandle);
> EndDocPrinter(PHandle);
> finally
> ClosePrinter(PHandle);
> end;
> end;
>
> --
> Virgo Pärna
> virgo.parna at mail.ee
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150113/83a00a3c/attachment.html>
More information about the fpc-pascal
mailing list