From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to print a Zebra label with PrintTextFile?

I am trying to print a barcode label in CVI 8.5 to a Brady 600X-plusII printer.  I've constructed a label in a text file with a .zpl extension using ZPLII commands.  If  I send  this file to the printer using the PrintTextFile command or the PrintTextBuffer command the printer will print the actual code of the text file.
If I use the system print command (system ("command.com /C print C:\\labels\\test.zpl");) the label will print correctly.

Is there a way to configure the system so the PrintTextFile command acts the same as the system print command.  The reason being I need to get the printer off the parallel port and on to a USB port.
0 Kudos
Message 1 of 7
(7,983 Views)

I think , difference between using the print command and the CVI PrintTextfile() function is, that the latter uses the windows printer driver system, which usually  prepends some setup commands ( i.e for formatting , setting up font etc. ) before sending your command text  to the printer, whereas the command line print command just pipes it to the printer without any change.  

Windows also provides a  Generic/ Text Only  printer driver. That driver probably doesn't use any setup for the printer. What happens if you use that printer driver when printing your label ?   

 

0 Kudos
Message 2 of 7
(7,955 Views)
I tried the Generic/text only driver and that had a different result but it didn't work.  To your point, I think you sent me in the right direction though.
0 Kudos
Message 3 of 7
(7,942 Views)

What was your solution to this?  I am seeing the same symptom with a Zebra S4M printer, where it is printing the contents of the file or buffer (I have tried it using the PrintTextBuffer function, as well).  Fix?

0 Kudos
Message 4 of 7
(6,830 Views)

Unfortunately there was no fix for this.  I ended up using the system command from my original post.  My printer has a parallel port so I was stuck using that with the system command.  I was never able to get it to work though USB.  It looks like the system print command will only dump it to the parallel port.

0 Kudos
Message 5 of 7
(6,812 Views)

May I ask exactly what label printer are you use?  Zebra or Brady? 

0 Kudos
Message 6 of 7
(6,753 Views)

I know this post is quite old but I found a solution that others may find useful.  A recent project has required me to send ZPL or EPL commands directly to a label printer again but serial or parallel are no longer an option.

 

The simplified function below will send the commands directly to the printer (regarless if USB, parallel, etc.) without Windows doing any processing.  You will need to make sure there is a CR/LF at the end of each line sent to the printer.  This also requires the "windows.h" header and "winspool.dll" available from the Microsoft Windows SDK.

 

//Will require
#include "windows.h"
#include "winspool.h"


//* Print Label(s) to selected printer ********************************************************************************
int	PrintLabel (unsigned char strLabelBuffer[], unsigned char strPrintJobName[], unsigned int uiNumCopies){

	unsigned int	uiPrinted;
	int				iBytesSent;
	HANDLE			PrintHandle;
	DOC_INFO_1 		DocInfo;
	
	
	if (!OpenPrinter (strLabPrinter, &PrintHandle, NULL)){			//Open printer and get handle
		MessagePopup ("Printer Error", "Open Printer error!\nCheck Printer selection settings.");
		return -1;
	}

	//Definitions for DOC_INFO_1
	DocInfo.pDocName = (LPTSTR)(strPrintJobName);				   	                //Print job name
	DocInfo.pOutputFile = NULL;									//NULL = sent to printer
	DocInfo.pDatatype= (LPTSTR)("RAW");							   	//RAW = send directly to printer (no processing)
	
	
	if (!StartDocPrinter (PrintHandle, 1, (LPBYTE)&DocInfo)){   	//Start print job
		MessagePopup ("Printer Error", "Could not start Print Job.");
		return -1;
	}
	for (uiPrinted = 0; uiPrinted < uiNumCopies; uiPrinted++){ 		//Print number of copies requested
		StartPagePrinter (PrintHandle);				   				//Start "page"
		WritePrinter (PrintHandle, strLabelBuffer, strlen (strLabelBuffer), &iBytesSent);	//Send data to printer
		EndPagePrinter (PrintHandle);								//End "page"
	}
	EndDocPrinter (PrintHandle);									//End Print Job
	ClosePrinter (PrintHandle);								   	//Close Printer
	
	return 0;
}

Hope this helps!

0 Kudos
Message 7 of 7
(5,484 Views)