LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Accessing a [Ethernet] printer in Linux (https://www.linuxquestions.org/questions/programming-9/accessing-a-%5Bethernet%5D-printer-in-linux-904083/)

DiBosco 09-20-2011 04:08 PM

Accessing a [Ethernet] printer in Linux
 
Folks,

I need to send a file I will create to a [barcode] printer. It's very simple, just a few lines of .xml type ASCII and apparently if the printer receives this it will print out my barcode.

Now, there are cups drivers for these [Zebra] printers and apparently, when installing the printer you just set it up in Linux as a zpl or epl Zebra device and the OS will find it.

Now, what I am unclear about is how to actually get this file to the printer. My gut feeling is I could open a connection to the file which I would expect to see in /dev, but I have an HP Laserjet 5000 that I use and I can't see anything that is obviously it in /dev.

I've developed my app in Qt and just need to write some code to create the .zpl file and then work out how to get it from my app to the printer itself. Would anyone be able to advise on how I can do this please? I don't actually have the printer yet, but would like to have as much code ready as possible for when it arrives.

Many thanks.

Snark1994 09-20-2011 04:12 PM

If you're using C/C++, you'll want to be looking at the CUPS API. I'm afraid I haven't used it personally so I can't provide any personal insight into its use...

Hope this helps,

DiBosco 09-20-2011 05:12 PM

Thanks, that does look like it's what I'll need. Lots of pointers to pointers. There's something new for me to learn! They seem to have some basic examples of how to use the API calls, not entirely sure about how some of it works at first glance, but hopefully that will get me started.

michaelk 09-20-2011 05:19 PM

Although none of the links work there is also a user guide on the page that might provide some help.
https://km.zebra.com/kb/index?page=c...7680&actp=LIST

In general, I would setup the printer with a static IP address. Next add the printer via the cups web interface (i.e. localhost:631). The URL of the printer will be IP_address:9100. There will also be a step to select the printer driver.

To print a file via the command line:
lpr -P zebra filename

Replace zebra with the actual printer name that was used when you added the printer.

You can also view the setup for the HP from the cups web interface.

DiBosco 09-20-2011 05:25 PM

Thanks, Michael, that's also helpful. I'd already seen, and got frustrated by, the broken links on the Zebra site.

There's a lot of useful example programs on the cups site, I'm just having a go at listing the printers on my system from a simple Qt app I'm knocking up.

DiBosco 09-20-2011 06:09 PM

Looks straighforward, this lists my CUPS printers:

Code:

int MainWindow::listPrinters(void)
{
  int i;
  cups_dest_t *dests, *dest;
  int num_dests = cupsGetDests(&dests);

  for (i = num_dests, dest = dests; i > 0; i --, dest ++)
  {

      ui->textEdit->append(QString::QString(dest->name) + "\n");
    if (dest->instance)
      printf("%s/%s\n", dest->name, dest->instance);
    else
      puts(dest->name);
  }

  return (0);
}

That's just slightly modifying some example code in the link Snark gave me.

Also, once I knew what to search for a bit better thanks to Snark, this also helped a lot. It specifically deals with sending text to the Zebra printers which is exactly what I want. It's amazing how all the sales people in the distributors when you first ask them say you can't use Zebra printers from Linux.

Hope this also helps someone in future. :)


All times are GMT -5. The time now is 09:58 AM.