|
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>
#include <linux/lp.h>
int CheckParPortState(int fd, int m_bits)
{
int status;
/* Get Par Port State */
if (ioctl(fd, LPGETSTATUS, (char*)&status) < 0) {
return (0);
}
if (m_bits != 0x20) return ( status & m_bits );
else return( !(status & m_bits) );
}
main()
{
int fd;
if ( (fd = open("/dev/lp0", O_WRONLY , 0)) < 0) {
perror("/dev/lp0 error");
exit(-1);
};
if (!CheckParPortState(fd, LP_PBUSY))
printf("printer is busy \n");
if (!CheckParPortState(fd, LP_PACK))
printf("printer answer \n");
if (!CheckParPortState(fd, LP_POUTPA))
printf("printer paper out \n");
if (!CheckParPortState(fd, LP_PERRORP))
printf("printer error \n");
close(fd);
} |
|