[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
Part1 - Part2 - Part3 - Part4 - Part5 - Single Page
Top Document: comp.os.msdos.programmer FAQ part 4/5
Previous Document: - Which 80x86 CPU is running my program?
Next Document: - How can I redirect printer output?
-
Search the FAQ Archives
Part1 - Part2 - Part3 - Part4 - Part5 - Single Page
Top Document: comp.os.msdos.programmer FAQ part 4/5
Previous Document:
Next Document:
- How can a C program send control codes to my printer?
Date: 5 Feb 2002 22:03:03 -0400
If you just fprintf(stdprn, ...), C will translate some of your control
codes. The way around this is to reopen the printer in binary mode: prn
= fopen("PRN", "wb");
You must use a different file handle because stdprn isn't an lvalue. By
the way, in DOS 5.0 a colon must not follow PRN or LPT1.
There's one special case, Ctrl-Z (ASCII 26), the DOS end-of- file
character. If you try to send an ASCII 26 to your printer, DOS simply
ignores it. To get around this, you need to reset the printer from
"cooked" to "raw" mode. Microsoft C users must use INT 21 AH=44,
"get/set device information". Turbo C and Borland C++ users can use
ioctl to accomplish the same thing: ioctl(fileno(prn), 1,
ioctl(fileno(prn),0) & 0xFF | 0x20, 0);
An alternative approach is simply to write the printer output into a
disk file, then copy the file to the printer with the /B switch.
A third approach is to bypass DOS functions entirely and use the BIOS
printer functions at INT 17. If you also fprintf(stdprn,...) in the same
program, you'll need to use fflush() to synchronize fprintf()'s buffered
output with the BIOS's unbuffered.
By the way, if you've opened the printer in binary mode from a C
program, remember that outgoing \n won't be translated to carriage
return/line feed. Depending on your printer, you may need to send
explicit \n\r sequences.
Top Document: comp.os.msdos.programmer FAQ part 4/5
Previous Document:
Next Document:
Part1 - Part2 - Part3 - Part4 - Part5 - Single Page
[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
Send corrections/additions to the FAQ Maintainer:
jeffrey@carlyle.org (Jeffrey Carlyle)
Last Update November 23 2008 @ 00:11 AM