0

We have some windows box on the network, and shared printers on them.

I've added them through the CUPS web interface, and all of them works like a charm, we can print to them by php:

exec('lp -d vasosamsung file.pdf');

Cool. I worte a Printer class, what makes some validation before the print job ccould start.

The first thing what I check is the printer is exists:

lpstat -p vasosamsung

If it is not says, the destination is invalid, then yes, move on. And here comes the tricky part.

If the answer is idle, or printing, the everything is fine, let's send the job.

BUT!

The problem is it says, the printer is idle, because on my machine the printer has added to the list of printers, but sadly it is offline. This is what I want to catch. More problems come.

Ok, I can deal with it, the jobs are in the queue even if the printer itself is offline (pulled out from the machine).

The real problem is, that when I removed the whole printer thing from my "Printers and Devices" with right click and remove device, CUPS says, it is idle. I've restarted the CUPS by service cups restart, and get a stat:

printer vasosamsung is idle.  enabled since Thu 06 Apr 2017 03:34:26 PM CEST

It is not true. Now on my machine there is now printer like this. The worst thing, if I am send a document to it, it says:

string(40) "request id is vasosamsung-71 (1 file(s))"

and the job is on the web interface:

vasosamsung-71  Unknown     Withheld    1933k   1   held since

Thu Apr 6 15:59:43 2017

My question is: is there a way ti get the phisicaly printer status? Offline, printing etc... not from CUPS?

If it is not possible, can I get somehow, is the printer is in the device list on the target machine at least?

EDIT

Hehe, when I turned off my machine, the printer is idle also :)

I guess, this is because vasosamsung printer is in the CUPS, and that is not the phiscal device, now I see, but my questions are still alives.

  • Cant stop laughing. It is lying :-) – A Umar Mukthar Apr 6 '17 at 14:18
  • @AUmarMukthar First I thought that. I changed the name of question, but you were right. – vaso123 Apr 6 '17 at 14:22
  • If the driver does not support it you won't be able to. – Rinzwind Apr 6 '17 at 14:38
  • How the diver comes to the picture? CUPS will always say idle, or printing if the priner has added to CUPS. CUPS does not care about is the target machine turned on / off, or printer is turned on / off. Cups put the job into their on queue, and send to the target queue it when the machine will be online, target machine send to the target printer when target printer will be online. – vaso123 Apr 6 '17 at 14:42
0

my solution: in my programs written in C I include the function (or procedure in ALGOL, my first language, in 1964 ...)

#define BUFFERLEN 1024
int isprtready( void )
{ char cmd[BUFFERLEN], buffer[BUFFERLEN], usbstat[]="lsusb > ",
       enabled[]="Hewlett-Packard LaserJet 2420", filename[]="prtreadyXXXXXX";
  int handle, len;

  handle = mkstemp( filename );

  strcpy( cmd, usbstat );
  strcat( cmd, filename );
  system( cmd );
  len = read( handle, buffer, BUFFERLEN );
  buffer[len] = '\0';
  close( handle ); 
  unlink( filename );

  return ( strstr( buffer, enabled ) != (char*)NULL );
}

With the necessary includes
disadvantage: The explicit printer name is in my program. (I have only one computer and one printer, no network and such things.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.