[comp.sys.ibm.pc] TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

a_rubin@dsg4.dse.beckman.com (Arthur Rubin) (06/21/91)

In <1991Jun21.040657.3195@ux1.cso.uiuc.edu> mdcg7180@uxa.cso.uiuc.edu (Michael David Carr) writes:

>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.
--
2165888@mcimail.com 70707.453@compuserve.com arthur@pnet01.cts.com (personal)
a_rubin@dsg4.dse.beckman.com (work)
My opinions are my own, and do not represent those of my employer.

mikec@mullauna.cs.mu.OZ.AU (Michael CIAVARELLA) (06/22/91)

a_rubin@dsg4.dse.beckman.com (Arthur Rubin) writes:

>In <1991Jun21.040657.3195@ux1.cso.uiuc.edu> mdcg7180@uxa.cso.uiuc.edu (Michael David Carr) writes:

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

>>     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
      (D  / \   C)            email : mikec@mullauna.cs.mu.oz.AU
      r>_%   =--{]            snail : PO Box 542, Kyabram, Victoria, 3620.
     /&          z\                              Australia
    ///\        /\\\          voice : +61 3 3421692 
   /   ^        \  \\                 "The way of the katana"       

frank@cavebbs.gen.nz (Frank van der Hulst) (06/22/91)

In article <1991Jun21.040657.3195@ux1.cso.uiuc.edu> mdcg7180@uxa.cso.uiuc.edu (Michael David Carr) writes:
>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.

frank@cavebbs.gen.nz (Frank van der Hulst) (06/23/91)

>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.

>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.

rob@pact.nl (Rob Kurver) (06/23/91)

In <1991Jun22.080947.504@cavebbs.gen.nz> frank@cavebbs.gen.nz (Frank van der Hulst) writes:

>In article <1991Jun21.040657.3195@ux1.cso.uiuc.edu> mdcg7180@uxa.cso.uiuc.edu (Michael David Carr) writes:
}>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
    Foulkeslaan 87         rob@pact.nl
   2625 RB Delft    tel: +31 15 616864 
  The Netherlands   fax: +31 15 610032