Automatically starting printer when turned on

Anonymous anonymous at easysw.com
Fri Jun 24 18:13:17 PDT 2005


>
> No, it can't detect this.
>

Here's what I did. I'm in a similar situation that the printer is often turned off to save energy and then I have to log in and start it again.

So I went ahead and modified usb-unix.c as follows:

#define WORKAROUND

[...]

int					/* O - Exit status */
print_device(const char *uri,		/* I - Device URI */
             const char *hostname,	/* I - Hostname/manufacturer */
             const char *resource,	/* I - Resource/modelname */
	     const char *options,	/* I - Device options/serial number */
	     int        fp,		/* I - File descriptor to print */
	     int        copies)		/* I - Copies to print */
{
  int		fd;			/* USB device */
  int		wbytes;			/* Number of bytes written */
  size_t	nbytes,			/* Number of bytes read */
		tbytes;			/* Total number of bytes written */
  char		buffer[8192],		/* Output buffer */
		*bufptr;		/* Pointer into buffer */
  struct termios opts;			/* Parallel port options */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
  struct sigaction action;		/* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
#ifdef __linux
  unsigned int	status;			/* Port status (off-line, out-of-paper, etc.) */
#endif /* __linux */


 /*
  * Open the USB port device...
  */
#ifdef WORKAROUND
  int timer=1; // we will loop for as long as the printer needs to come back online!
#endif // WORKAROUND

  do
  {
    if ((fd = open_device(uri)) == -1)
    {
      if (errno == EBUSY)
      {
        fputs("INFO: USB port busy; will retry in 20 seconds...\n", stderr);
	sleep(20);
      }
#ifdef WORKAROUND
      else /* if (errno == ENXIO || errno == EIO || errno == ENOENT) */
      {
        fputs("INFO: WORKAROUND defined ..waiting for printer to come online!\n",stderr);
        fputs("INFO: Printer not connected; will retry in 10 seconds...\n", stderr);
	sleep(10);
	timer++;
	if(timer >= 20) // after 20 retries, we finally give up
		{
		fprintf(stderr, "ERROR: Unable to open USB device \"%s\": %s\n",
	        uri, strerror(errno));
		return(1);
		}
      }
#else
	else if (errno == ENXIO || errno == EIO || errno == ENOENT)
      {
        fputs("INFO: Printer not connected; will retry in 30 seconds...\n", stderr);
	sleep(30);
      }
    else
      {
	fprintf(stderr, "ERROR: Unable to open USB device \"%s\": %s\n",
	        uri, strerror(errno));
	return (1);
      }
#endif WORKAROUND

it is a VERY dirty hack, but it works for my requirements... I'm sure it messes up something but it works! At least now all I have to do is run upstairs and pop the power button :) (rather than that and logging into the cups web interface)

-Bartek




More information about the cups mailing list