HP OpenVMS Systems

ask the wizard
Content starts here

Terminals and Attached Printers?

» close window

The Question is:

 
Is there a way to send escape codes to a serial printer connected to my PC,
 that will allow the cash drawer connected to the printer to open?
 
Please find below a copy of the technical bulletin from Epson that describes
 the escape codes necessary to open the cash till. I have also attached a copy
 of the file that has been programmed for opening the cash till.
 
 
Thanks,
 
_____________________________________________________________________
This is the technical information bulletin from Epson:
 
The purpose for this Technical Information Bulletin is to provide a generally
 available way to send ESC/POS commands (in Hex) to the TM-series printers.
 
The first step is to create a binary file containing the desired byte
 sequence(s) that corresponds to the ESC/POS command(s). This can be done using
 DEBUG. Next the COM port where the printer is connected, has to be initialized
 with the MODE COMx command.
 Finally the DOS standard output redirection mechanism is used in combination
 with the TYPE command to send the file to the COM port.
 
 
Example:
 
ESC p n t1 t2           (send pulse for Cash Drawer open)
 
Where:
	ESC = 1B (hex)
	P     = 70 (hex)
	N     = 00 (hex) for drawer 1 or 01 (hex) for drawer 2
	T1    = 00 ~ FF (hex) for ON time
	T2    = 00 ~ FF (hex) for OFF time
 
If a cash drawer coil requires 20ms of energizing time then the OFF time has to
 be calculated by the formula T2 > 4 x T1. In this case we will make the OFF
 time 100ms which is greater than 20ms x 4. The byte sequence we need to send
 to the printer will be
 
 
 
		1B	70	00	40	F0 to send pulse to pin 2
 (drawer1)
	or
		1B	70	01	40	F0 to send pulse to pin 5
 (drawer2)
 
_____________________________________________________________________
This is the file to open the cash till:
 
$!********************************************************************
$!  B552A_DP_OPENTILL_COM.COM
$!  DCL procedure to open a cashdrawer on the DECpos type cashtill machine
$!  Written by : Andrew Hartery
$!  Date       : 20-Mar-1995
$!  Amendments:
$!********************************************************************
$!
$ WS            == "WRITE SYS$OUTPUT"
$ NUL[0,8]      == 0
$ ESC[0,8]      == 27
$ CTRL_G[0,8]   == 7
 
$ WS "''ESC'[5i''CTRL_G'''ESC'[4i"      ! opens cash drawer
$!
$ set mess/nof/noi/nos/not
$ set mess/f/i/s/t
$ EXIT
[End of file]
 
 
 


The Answer is :

 
  The attached example demonstrates writing a control sequence that
  checks the terminal's printer status, and processes the returning
  control sequence.
 
  Most terminals with support for an attached printer (or terminal
  emulators that themselves have an emulation of an attached printer)
  will support control sequences that will switch the output sent to
  the terminal from the terminal through to the printer -- with VT
  series terminals, this mode is known as printer controller mode,
  and is enabled via the eight- or seven-bit control sequence:
 
    CSI 5 i
    ESC [ 5 i
 
  and disabled via the eight- or seven-bit sequence:
 
    CSI 4 i
    ESC [ 4 i
 
  You can thus enable printer controller mode, send along the particular
  control sequence(s) required for the attached device, then revert back
  to the normal operations.
 
  The previous DCL example uses these sequences, as well as apparently
  using the bell (ASCII 7) character as the trigger.  You would need to
  substitute the control sequence needed for your particular device for
  the bell character.
 
  The OpenVMS Wizard would encourage examination of any programming
  information for the particular terminal (or terminal emulator), as
  support and requirements can vary.
 
 
	--
 
#module	EXAMPLE "SRH X1.0-000"
#pragma builtins
 
/*
** COPYRIGHT (c) 1992 BY
** DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS.
** ALL RIGHTS RESERVED.
**
** THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
** ONLY  IN  ACCORDANCE  OF  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
** INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR  ANY  OTHER
** COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
** OTHER PERSON.  NO TITLE TO AND  OWNERSHIP OF THE  SOFTWARE IS  HEREBY
** TRANSFERRED.
**
** THE INFORMATION IN THIS SOFTWARE IS  SUBJECT TO CHANGE WITHOUT NOTICE
** AND  SHOULD  NOT  BE  CONSTRUED  AS A COMMITMENT BY DIGITAL EQUIPMENT
** CORPORATION.
**
** DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE  OR  RELIABILITY OF ITS
** SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
*/
 
/*
**++
**  Facility:
**
**	Examples
**
**  Version: V1.0
**
**  Abstract:
**
**	Example of working with the $QIO Extended Read
**
**  Author:
**	Steve Hoffman
**
**  Creation Date:  1-Jan-1990
**
**  Modification History:
**--
*/
#include <descrip.h>
#include <iodef.h>
#include <ssdef.h>
#include <stsdef.h>
#include <trmdef.h>
 
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 = &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;
    }
 
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;
	unsigned char *itmbuf;
	unsigned short int *itmrla;
	} itmlst[]=
	{
	    {
	    0, TRM$_ESCTRMOVR, 64, 0
	    },
	    {
	    0, TRM$_MODIFIERS,
	    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;
    }
 
 

answer written or last revised on ( 24-AUG-2000 )

» close window