Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing directly to parallel port on Win NT

52 views
Skip to first unread message

Stewart Robinson

unread,
Mar 20, 2000, 3:00:00 AM3/20/00
to
I need to print directly to a parallel port under Windows NT to communicate
with a point of sale pole display connected to LPT1. I've tried using
FileCreate and FileWrite as well as std Delphi Text files using Rewrite and
Write. In both cases the text sometimes reaches the display, but not
always. I've connected a printer to LPT1 to capture my commands using its
debug (hex display) mode and find that sometimes my commands don't reach the
printer and other times the order seems to be different than the order I
sent the commands in. Each command is sent as follows:
1. FileCreate('LPT1')
2. FileWrite
3. FileClose
None of above statements return an error condition, and when running in
debug mode stepping thru the statements everything works fine. So I'm
thinking it must be some sort of timing issue, but can't find any method of
checking if the last command was sent. Or maybe I need a different parallel
port driver. Any suggestions?

Peter Below

unread,
Mar 21, 2000, 3:00:00 AM3/21/00
to
In article <38d66968@dnews>, Stewart Robinson wrote:
> I need to print directly to a parallel port under Windows NT to communicate
> with a point of sale pole display connected to LPT1. I've tried using
> FileCreate and FileWrite as well as std Delphi Text files using Rewrite and
> Write.

Not the correct method if the device acts like a printer. Install a printer,
e.g. the Generic/Text only driver, attach it to LPT1 and the use
WinSpool.WritePrinter to send stuff to it.

Print a line to the generic/text printer without formfeed

Uses WinSpool;

Const
GenericPrinter: Pchar = 'Universal/Nur Text';
// Change to systems generic drivers name

Procedure PrintLineToGeneric(Const line: string );
Var
BytesWritten: DWORD;
hPrinter: THandle;
DocInfo: TDocInfo1;
Begin
If not WinSpool.OpenPrinter(GenericPrinter, hPrinter, nil) Then
raise exception.create('Printer not found');

Try
DocInfo.pDocName := 'MyDocument';
DocInfo.pOutputFile := Nil;
DocInfo.pDatatype := 'RAW';
If StartDocPrinter(hPrinter, 1, @DocInfo) = 0 Then
Abort;

Try
If not StartPagePrinter(hPrinter) Then
Abort;
try
If not WritePrinter(hPrinter, @line[1], Length(line), BytesWritten)
Then
Abort;
Finally
EndPagePrinter(hPrinter);
End;
Finally
EndDocPrinter(hPrinter);
End;
Finally
WinSpool.ClosePrinter(hPrinter);
End;
End;


Peter Below (TeamB) 10011...@compuserve.com)
No replies in private e-mail, please, unless explicitly requested!

0 new messages