Topic: Setting up the printer in C++
Author: lrogers@cs.uct.ac.za (L J Rogers)
Date: 26 Dec 1994 16:42:46 +0200 Raw View
Hi all,
Below is a copy of the printer class that I am using to send output to the
printer. I have have one major problem with this code, if the printer is not
on-line then the program bombs and MS-Dos responds by saying that the printer
is not ready.
So I am looking for some c/c++ code to add to this code below that will help
me determine if the printer is on-line or not. Please tell me is there a
header file and function that I can use to check for the i/o status of the
printer.
This program has been designed to run on an Ms-Dos machine but I want to be
able to port it to Unix or any other platform, so I would like to take out
the machine specific code below.
The printer used is an Epson LX-400
The compiler is borland C++ 3.1
Any help in sorting out this problem would be greatly appreciated.
Thank you.
>------------<
#include <iostream.h>
#include <fstream.h>
#define TRUE 1
#define FALSE 0
class Printer {
int counter;
fstream prnts;
public:
Printer ();
virtual ~Printer();
virtual char Ok();
virtual char Print( char *);
virtual char Print( char );
};
Printer::Printer()
{
counter = 0;
prnts.open("prns",ios::binary|ios::out);
}
Printer::~Printer()
{
prnts.close();
}
char Printer::Ok ()
{
unsigned char retval = 0;
// The code below is specific for the ms-dos machine.
asm {
mov ah,02;
mov dx,0000;
int 0x17;
mov retval, ah;
}
retval = retval << 4;
retval = retval >> 7;
return !retval;
}
char Printer::Print(char *temp)
{
char retval = TRUE;
if (!Ok())
retval = FALSE;
else {
char tmp = strlen(temp);
prnts << temp;
prnts.flush();
counter += tmp;
}
return retval;
}
char Printer::Print(char test)
{
char retval = TRUE;
if (!Ok())
retval = FALSE;
else {
prnts.put (test);
if (Ok() )
prnts.flush();
counter++;
}
return retval;
}
>---
--
<--------------------------------------------------------------------->
| Louis Rogers Internet: lrogers@cs.uct.ac.za |
| Fidonet: 5:7102/116.13 rgrlou02@uctvax.uct.ac.za |
<--------------------------------------------------------------------->