Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1242
  • Last Modified:

How can I send ZPLII commands to Zebra LP2844s printer from a Win32 app

I need to send ZPLII commands directly to a Zebra LP2844 printer from a Win32 (C++) app. Is there any sample code I can access ? My code below didn't produce any error messages, but nothing printed either. If a working Win32 sample cannot be provided, perhaps someone can show me at least how I can print a txt file containing ZPLII commands to the printer from the windows Command prompt, so that the commands are actually executed instead of printed ? If I use notepad's print command, I get the actual command text printed on the printer rather than the intended graphics (bar codes, etc.).
Thanks in advance.

BOOL RawDataToPrinter(LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount)
{
HANDLE hPrinter;
DOC_INFO_1 DocInfo;
DWORD dwJob;
DWORD dwBytesWritten;
if(!OpenPrinter(szPrinterName, &hPrinter, NULL)) // Need a handle to the printer.
	return FALSE;
DocInfo.pDocName="My Document"; // Fill in the structure with info about this "document."
DocInfo.pOutputFile=NULL;
DocInfo.pDatatype="RAW";
if((dwJob=StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo))==0) // Inform the spooler the document is beginning.
	{
	ClosePrinter(hPrinter);
	return FALSE;
	}
if(!StartPagePrinter(hPrinter)) // Start a page.
	{
	EndDocPrinter(hPrinter);
	ClosePrinter(hPrinter);
	return FALSE;
	}
if(!WritePrinter(hPrinter, lpData, dwCount, &dwBytesWritten)) // Send the data to the printer.
	{
	EndPagePrinter(hPrinter);
	EndDocPrinter(hPrinter);
	ClosePrinter(hPrinter);
	return FALSE;
	}
if(!EndPagePrinter(hPrinter)) // End the page.
	{
	EndDocPrinter(hPrinter);
	ClosePrinter(hPrinter);
	return FALSE;
	}
if(!EndDocPrinter(hPrinter)) // Inform the spooler that the document is ending.
	{
	ClosePrinter(hPrinter);
	return FALSE;
	}
ClosePrinter(hPrinter); // Tidy up the printer handle.
if(dwBytesWritten!=dwCount) // Check to see if correct number of bytes were written.
	return FALSE;
return TRUE;
}

Open in new window

0
misterpi
Asked:
misterpi
  • 3
  • 2
2 Solutions
 
DanRollinsCommented:
When you single-step in the debugger, how far does it get?
If any function fails, you might be able to use GetLastError to provide some insight.
0
 
misterpiAuthor Commented:
Thanks for your reply Dan.
   That's the thing - all of the calls return successfully, yet nothing gets printed on the printer. Now I think it may have something to do with the printer's setup - right now it is set to RAW mode, which I thought might enable me to bypass the windows driver, but I will try the GENERIC/TEXT mode, although I really don't know the difference.
   The file of ZPLII printer commands I sent is listed below. Unfortunately my type of question probably requires a bit of expertise over 2 or 3 areas (ZPLII commands and LP2844 printer knowledge as well as Win32). If I can rule out the incorrectness of my Win32 code as a source of the problem, I guess that helps.
^XA
^FO10,10
^A0,40,40
^FD
Hello World!
^FS
^XZ

Open in new window

0
 
DanRollinsCommented:
I found your code in the MS knowledgebase
   HOWTO: Send Raw Data to a Printer by Using the Win32 API
   http://support.microsoft.com/kb/138594
I don't know about that printer, but some hints I saw here:
   http://www.bigresource.com/VB-VB-Printing-to-Zebra-TLP2844-Printing-tOX7N9Ar.html

lead me to wonder about two things.
First, I'd expect that the printer wants to see escape sequences.  For instance, one way to read:
   ^XA
is:
    caret, uppercase X, uppercase A
Another way to read it is:
    ctrl-X, uppercase A
such escape sequences often need a terminating character, such as LF (Ctrl-J, or 0x0a)
The ASCII value of "ctrl-X" is
   0x18
so you might need to send:
   0x18, 0x41, 0x0A
Second, there is some mention in there that the printer itself might need to be told what to expect as the "lead-in" characterfor an escape sequence.  One guy mentioned that he had to set both the Control Prefix and the Format Prefix (whatever they are) to be the same.
0
 
misterpiAuthor Commented:
Thanks again Dan,
  After studying the printer manual closely, it looks like I could be using the wrong version of the language appropriate for this particular model printer - the documentation is sparse in this area. I am adjusting my testing accordingly. You can consider this case temporarily closed. I really appreciate your time and help!
0
 
DanRollinsCommented:
In that case, please see: How do I close a question? Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now