I'm experimenting with a Zebra TTP8200 thermal printer. For my application I need to print plotter type traces continuously until the user hits a stop button. I've had a play with the ZPL language and I can successfully generate bitmap data and dump out my bitmap a line (or few lines) at a time by outputting the ZPL as raw data.
I'm using some Microsoft demo code to output the raw data to the printer and this works great, bar one issue: the spooler. It turns out that every time I output some data using the MS rawprn.exe code it is actually spooled as a print job and then transmitted to the printer. This takes up to 10 seconds to get through the spooler, obviously too slow. Disabling spooling in the driver doesn't help, it just means that the program hangs while the job is passed through the spooler and printing completes.
Is there a way to bypass the spooler and output data straight to this USB printer? My research so far hasn't turned up anything likely looking in the Windows API. Ideally, I'd like to be able to use the printer like it was a serial printer - open the port and shove data in.
Many thanks in advance for any hints!
If the USB printer is available as a COM port, you can just write to the COM port. Like this, from the DOS prompt:
The former example will output the results of the
dir
command to the printer.Or, here is another example:
The former example will output the contents of
file.txt
to the printer.Outputting properly formatted ZPL data will be harder than just plain text. I have gotten this to work from Linux using Ruby (and Epson/ESC commands), however.
The below class in C# is something I've adapted from a Microsoft Knowledgebase article. There are methods in this class to send the print job as a
string
andbyte[]
. Please note there are some references to log4net in there that can be removed/replaced with the logging framework of your choice. :Yes, absolutely. It's built into most OSs, printing raw via USB is just a bit less obvious than Ethernet and COM/LPT. Note, many applications, such as notepad are incapable of printing raw, so your application needs to support this as well.
Now with your raw printing application, use the newly created printer.
P.S. These instructions are also available here, with screenshots, as part of a Java open source raw printing tutorial. The project provides tutorials for other platforms (Ubuntu, OS X) as well.
http://qzindustries.com/TutorialRawWin
-Tres
Thanks for the comments.
After some more digging around, I found this interesting article on using Windows printer functions provided by usbprint.sys. With a bit of hacking the sample code there seemed to work. I think I'll take this route.
There is the final code given in the article:
Thanks again for the suggestions.