ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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...
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.