TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

Post by Michael David Ca » Sat, 22 Jun 1991 13:06:57



I'm new to C, so if I'm overlooking the obvious, please bear with me.

I'm trying to print graphics on a DeskJet+, and am having no problems
except that I can't send ASCII 26 in a string of graphics bytes.

For those not familiar with the Deskjet (but C pros), to print a
row of graphics pixels, you must first put the printer in graphics
mode (I did that).  Then send it an Escape, and the following string:
     *b###W (... data bytes)

   where ### is the number of data bytes that follow.

     The data bytes represent 8 pixels, and can take on values from
0 to 255.  I can print any byte except ASCII 26!

     It isn't the printer, because I can send a 26 in BASIC and
FORTRAN.

Any help would be greatly appreciated (HP and Borland have no clue).

Michael Carr

Graduate Engineering, U. of I. at Urbana-Champaign

 
 
 

TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

Post by Michael CIAVAREL » Sun, 23 Jun 1991 10:23:34


[stuff about printing graphics sent to /dev/null ]

Quote:>>     It isn't the printer, because I can send a 26 in BASIC and
>>FORTRAN.
>I've noticed this also.  You might try (re)opening the printer in "b"inary mode
>rather than in "t"ext mode.  Sometimes that works.

Yep - opening in binary *should* work.  The problem isn't with Turbo C++ or
with the printer, but is to do with the way in which DOS handles files.
It assumes that the PRN file is a text-device, and, surprise surprise, the
ascii value 26 just corresponds to DOS's EOF (end-of-file) marker.  So,
you send a \0x1a and DOS thinks "Whoopee! end of file - lets ignore everything
after it!.  Voila!  Instant problems.

If that doesn't work, try writing directly to the printer port (the number
WAS here somewhere.....damned paperless office ;-)

Oh, and to the original poster (Mike Carr) and probably most people on the net:
        If you're new to a language/system/whatever and you have a problem
        which you can't figure, then by all means, ASK WHOEVER YOU CAN!
        At least you'll be learning something, and it gives knowledegeable
        people a chance to show off :-)  Besides, the net _IS_ for the
        worthfile exchange of information.  Just my $0.02 worth.  actually, I
        probably owe someone that, given inflation these days......

Mike

-----------------------------------------------------------------------------
           X

      r>_%   =--{]            snail : PO Box 542, Kyabram, Victoria, 3620.
     /&          z\                              Australia
    ///\        /\\\          voice : +61 3 3421692
   /   ^        \  \\                 "The way of the katana"      

 
 
 

TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

Post by Arthur Rub » Sun, 23 Jun 1991 00:47:01



Quote:>I'm new to C, so if I'm overlooking the obvious, please bear with me.
>I'm trying to print graphics on a DeskJet+, and am having no problems
>except that I can't send ASCII 26 in a string of graphics bytes.
>For those not familiar with the Deskjet (but C pros), to print a
>row of graphics pixels, you must first put the printer in graphics
>mode (I did that).  Then send it an Escape, and the following string:
>     *b###W (... data bytes)
>   where ### is the number of data bytes that follow.
>     The data bytes represent 8 pixels, and can take on values from
>0 to 255.  I can print any byte except ASCII 26!
>     It isn't the printer, because I can send a 26 in BASIC and
>FORTRAN.

I've noticed this also.  You might try (re)opening the printer in "b"inary mode
rather than in "t"ext mode.  Sometimes that works.
--


My opinions are my own, and do not represent those of my employer.
 
 
 

TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

Post by Phil Hold » Sun, 23 Jun 1991 01:21:13


ASCII 26 (0x1A) is the end of file character in DOS text files.  If you want
to write this character from a 'C' program, you must open the file in binary
mode
         OutFile = fopen( "filename", "wb");
The b puts it in binary mode.  
 
 
 

TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

Post by Frank van der Hul » Sun, 23 Jun 1991 17:09:47



Quote:>I'm trying to print graphics on a DeskJet+, and am having no problems
>except that I can't send ASCII 26 in a string of graphics bytes.

>Any help would be greatly appreciated (HP and Borland have no clue).

The problem lies with TC++ (and TC and Turbo-Pascal going back at least 5
years). The stdprn stream is opened as text mode, not binary, so a \x1A acts
as an EOF character (just like a disk text file). You need to re-open stdprn
in binary mode. I have code (elsewhere) which does this by doing a DOS call
via int 21h (from vague memory) because TC won't allow you to change the
device's mode.

I can post the code (its only about 10 lines) if you need it.

Frank.

--

Take a walk on the wild side, and I don't mean the Milford Track.
Kayaking: The art of appearing to want to go where your boat is taking you.

 
 
 

TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

Post by Frank van der Hul » Mon, 24 Jun 1991 10:56:48


Quote:>The problem lies with TC++ (and TC and Turbo-Pascal going back at least 5

Oops -- minor mistake. The problem relates to MS-DOS, going back several years.

Quote:>years). The stdprn stream is opened as text mode, not binary, so a \x1A acts
>as an EOF character (just like a disk text file). You need to re-open stdprn
>in binary mode. I have code (elsewhere) which does this by doing a DOS call

Doing open() or whatever from C won't work -- here's the code (in assembler),
although doing the same in C via intdos() should work fine.:

; bin_mode:
;        int far bin_mode(int handle);
;        Change device into binary mode.

; Assemble via TASM /mx BIN_MODE

; DOS always ignores the binary parameter ("b") on device opens - LPT1,
; etc.  You have to follow the open with an IOCTL call to get the output
; device operating in binary mode. Note that it needs the result of an
; sopen(), open() or fdopen() call.

_bin_mode  proc far handle: word
        push    bp
        mov     bp, sp
        mov     ax, 4400h              ; Read device info
        mov     bx, handle             ; file handle from open
        int     21h                    ; Get device data into DX
        jc      exit                   ; Check whether valid
        and     dl, 80h                ; Is this a file or device ?
        jz      exit_OK                ; If file, do nothing
        mov     ax, 4401h              ; Set device parms
        mov     bx, handle
        xor     dh, dh                 ; Clear high byte
        or      dl, 20h                ; Ignore control characters, incl. ^Z
        int     21h
        jc      exit
exit_OK:xor     ax, ax
exit:   pop     bp
        ret

--

Take a walk on the wild side, and I don't mean the Milford Track.
Kayaking: The art of appearing to want to go where your boat is taking you.

 
 
 

TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

Post by Rob Kurv » Mon, 24 Jun 1991 21:28:02




}>I'm trying to print graphics on a DeskJet+, and am having no problems
}>except that I can't send ASCII 26 in a string of graphics bytes.
}>
}>Any help would be greatly appreciated (HP and Borland have no clue).
}The problem lies with TC++ (and TC and Turbo-Pascal going back at least 5
}years). The stdprn stream is opened as text mode, not binary, so a \x1A acts
}as an EOF character (just like a disk text file). You need to re-open stdprn
}in binary mode. I have code (elsewhere) which does this by doing a DOS call
}via int 21h (from vague memory) because TC won't allow you to change the
}device's mode.

Can't you just ignore stdprn and simply open a new stream to the printer in
binary mode?

Cheers. - Rob
--
     PACT                   Rob Kurver

   2625 RB Delft    tel: +31 15 616864
  The Netherlands   fax: +31 15 610032