[comp.lang.c] TC++ & DeskJet+ graphics programming: can't print '\x1a' !!??

mdcg7180@uxa.cso.uiuc.edu (Michael David Carr) (06/21/91)

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
mdcg7180@uxa.cso.uiuc.edu
Graduate Engineering, U. of I. at Urbana-Champaign

craigg@hpwrce.HP.COM (06/22/91)

Mike,

I just tried to duplicate your problem using Microsoft QuickC.  The DeskJet
worked fine with the QuickC code.

I don't have Turbo C or C++ installed on my office system.  I will try it
at home this weekend.

BTW... You really don't need to set the printer for graphics mode, unless 
you are changing the default resolution.  However, it is a good practice
to get into.

I will follow up on Monday...

===============================================================================
|Craig Gilmore                     |  "I know GOD is a man, 'cause the first  |
|Hewlett-Packard Response Center   |  thing created was DIRT.  A woman would  |
|craigg@hpwrce.HP.COM              |  have created a DUSTBUSTER..." -Gallager |
|These are MY opinions, HP only pays me to answer questions and solve problems|
===============================================================================

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