Skip to content
Advertisement

How to get the status of parallel port printer under Linux?

How to get the status of parallel port printer under Linux, such as paper missing, the device is not installed. Or How to get through the CUPS printer status etc.

Advertisement

Answer

int fd = open("/dev/lp0", O_RDWR);
if (fd < 0)
{
    printf("can't open lp0n");
}
else
{
    int status = 0;
    if (ioctl(fd, LPGETSTATUS, &status) == 0)
    {

        fprintf(stderr, "DEBUG: LPGETSTATUS returned a port status of %02X...n", status);
          if (status & LP_NOPA)
        {
            RET = T;
            fputs("WARNING: Media tray empty!n", stderr);
        }
        else if (status & LP_ERR)
        {
            RET = F;
            fputs("WARNING: Printer fault!n", stderr);

        }
        else if (status & LP_OFFL)
        {
            RET = F;
            fputs("WARNING: Printer off-line.n", stderr);
        }
    close(fd);

} }

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement