Printing barcode to Zebra printer

Put it into a project script. Then you can use it from any scope.

-or-

Labelary Online ZPL Viewer

2 Likes

In network PC below code not working. Any other solution for network PC(Perspective module)?

The Perspective module cannot print from the client. Its scripts run in the gateway. The java socket code should work just fine in the gateway as long as the gateway has outbound network privileges and the Zebra printer is reachable on your network. (If your gateway is Windows, you will have to alter LOCAL_SYSTEM or use a different user for the gateway service.)

Thank you so much for your help :slightly_smiling_face:
If server side(Gateway) more than 1 printer available then using this code can we pass printer name to print(without set default printer ).

Hi ,
In perspective module for (barcode print) printer implementation gateway side is it necessary printer drives installation or only printer IP and Port access required?
We have deployed (Ignition application)gateway on Linux operating system and client told us
difficult to install printer driver in Linux server (Gateway server) and he checking with there IT team so
can you please suggest ? How to use below code in project for barcode print (Network).

printerIP=‘192.168.140.61’
port=9100

try:

Open Socket Connection
clientSocket=Socket(printerIP,port)
#Open data output stream
outToPrinter=DataOutputStream(clientSocket.getOutputStream())
#Send Data to Printer
outToPrinter.write(strOut)
#close data stream and socket
outToPrinter.close();
clientSocket.close();
except IOError:
print “Error”, row

No driver required.

def printLabel(partNum, serialNum, printerIP, port):
	from java.net import Socket
	from java.io import DataOutputStream


	strMessage100 = '^XA'
	strMessage110 = '^BY3,3,60^FT065,120,^BCN,N,N,N,N^FDP%s^FS' % partNum
	strMessage111 = '^FT170,040^A0N,40,45^FD%s^FS' % partNum
	strMessage112 = '^FT065,260,^BCN,N,N,N,N^FDS%s^FS' % serialNum
	strMessage113 = '^FT170,170^A0N,40,45^FD%s^FS' % serialNum
	strMessage199 = '^PQ1,0,1,Y^XZ'

	strOut = strMessage100+strMessage110+strMessage111+strMessage112+strMessage113+strMessage199
	 
	try:
	  # Open Socket Connection
	  clientSocket=Socket(printerIP,port)
	  #Open data output stream
	  outToPrinter=DataOutputStream(clientSocket.getOutputStream())
	  #Send Data to Printer
	  outToPrinter.write(strOut)
	  #close data stream and socket
	  outToPrinter.close();
	  clientSocket.close();
	except IOError:
	  print 'Error', row

Then call it from anywhere:

pn = 'ABCDEFGH'
sn = '12345678'
printLabel(pn, sn, '192.168.140.61', 9100)
2 Likes

How did you get the Zebra API installed under ignition? Tried the jars in your Ignition gateway’s ../lib/core/common and restart. Got error from the LicenseManager.

I realize this is old.
I am able to to use that code to print the label.

However it prints the last label printed as well as what I sent out on the same label.
any idea how to get clear the buffer

There's no buffer (in Ignition, at least) in this case; Jordan's code above is creating a "fresh" socket connection each time the script is run. And as far as I remember, ^XA and ^XZ are the only message delimiters defined for ZPL, so it sounds like a printer problem, not a problem with the script.

~XJ will send a clear buffer. I used to send one at the beginning of the string, but newer firmware halts anything new going in for a few seconds.

That said, it sounds like you're sending data twice. Once without the ^XZ.

What happens if you cycle power on the printer and print one? What kind of result do you get?

4 Likes

That was the issue. I had to clear the buffer on the printer. Thank you

this part where i can put it?
pn = 'ABCDEFGH'
sn = '12345678'
printLabel(pn, sn, '192.168.140.61', 9100)