From: hoffman@xdelta.zko.dec.nospam Sent: Friday, February 02, 2001 5:02 PM To: Info-VAX@Mvb.Saic.Com Subject: Re: How to detect if VT320 has local printer attached. In article <95ettp$c7l$1@nnrp1.deja.com>, Fatz writes: :If the escape sequence is sent to the terminal when there's no printer, the :app "hangs". : :We need a way of determining if the terminal physically has a printer :attached to it before trying to print to it. Simply ask the terminal if it has a printer attached, and it will tell you. Attached is some (old) C code that should be helpful, albiet somewhat crufty -- I've done a very quick and cursory update to get the code to compile under Compaq C, but have not executed the code or otherwise tested it in a long time... --------------------------- pure personal opinion --------------------------- Hoff (Stephen) Hoffman OpenVMS Engineering hoffman#xdelta.zko.dec.com #pragma module EXAMPLE "SRH X1.0-000" /* ** Copyright 2000 Compaq Computer Corporation */ /* **++ ** Facility: ** ** Examples ** ** Version: V1.0 ** ** Abstract: ** ** Example of working with the $QIO Extended Read ** ** Author: ** Steve Hoffman ** ** Creation Date: 1-Jan-1990 ** ** Modification History: ** 2-Feb-2001 Compaq C updates, Copyright ** **-- */ #include #include #include #include #include #include #include #include open_target( char *trgdev, unsigned short int *chn ) { unsigned long int retstat; struct dsc$descriptor trgdsc; trgdsc.dsc$w_length = strlen( trgdev ); trgdsc.dsc$b_dtype = DSC$K_DTYPE_T; trgdsc.dsc$b_class = DSC$K_CLASS_S; trgdsc.dsc$a_pointer = trgdev; retstat = sys$assign( &trgdsc, chn, 0, 0, 0 ); if (!$VMS_STATUS_SUCCESS( retstat )) return retstat; return retstat; } close_target( unsigned short int chn ) { unsigned long int retstat; retstat = sys$dassgn( chn ); if (!$VMS_STATUS_SUCCESS( retstat )) return retstat; return retstat; } write_target_with_reply( unsigned short int chn, char *wrbuf, char *rdbuf ) { unsigned long int retstat; struct qioiosb { short retstat; short terminator_offset; char terminator_char; char reserved; char terminator_length; char cursor_position; } rdiosb, wriosb; struct itemlist_3 { unsigned short int itmlen; unsigned short int itmcod; void *itmbuf; void *itmrla; } itmlst[]= { { 0, TRM$_ESCTRMOVR, (void *) 64, 0 }, { 0, TRM$_MODIFIERS, (void *) (TRM$M_TM_ESCAPE | TRM$M_TM_TRMNOECHO | TRM$M_TM_NOFILTR | TRM$M_TM_NORECALL), 0 } }; retstat = sys$qio( 0, chn, IO$_READVBLK | IO$M_EXTEND, &rdiosb, 0, 0, rdbuf, 255, 0, 0, itmlst, sizeof(itmlst)); if (!$VMS_STATUS_SUCCESS( retstat )) return retstat; retstat = sys$qiow( 0, chn, IO$_WRITEVBLK, &wriosb, 0, 0, wrbuf, strlen(wrbuf), 0, 0, 0, 0); if (!$VMS_STATUS_SUCCESS( retstat )) return retstat; retstat = sys$synch(0, &wriosb ); retstat = sys$synch(0, &rdiosb ); return retstat; } main() { unsigned long int retstat; unsigned short int target_chan; char *target_device = "SYS$OUTPUT"; char target_reply[255]; unsigned long int *rply; retstat = open_target( target_device, &target_chan ); if (!$VMS_STATUS_SUCCESS( retstat )) return retstat; retstat = write_target_with_reply( target_chan, "\033[?15n", target_reply ); if (!$VMS_STATUS_SUCCESS( retstat )) return retstat; rply = (void *) &target_reply[2]; switch (*rply ) { case '?10n': printf("Printer ready\n"); break; case '?11n': printf("Printer not ready\n"); break; case '?13n': printf("No printer\n"); break; case '?18n': printf("Printer busy\n"); break; default: printf("Unrecognized response\n"); break; } retstat = close_target( target_chan ); if (!$VMS_STATUS_SUCCESS( retstat )) return retstat; return SS$_NORMAL; }