Printing barcode to Zebra printer

Based on the other thread, I’d say yes. I’ll get a printer onto the network and play-- er… research and develop…

I should have a more definitive answer and/or methodology for you tomorrow. :wink:

I have worked with a similar Intermec Printer, I found it was acceptable to create a container on screen with the aspect ratio the same as label to use, then layout all the data as labels, text, values, barcodes as controls within the container and finally use ‘system.print.createPrintJob’ to create a print job to the printer to print the container.

This allowed a label image to be show in the ignition window of the exact label printed.

Just wondering if you ever got around to attempting this? We have huge value here at our facility if we could pull this off

Don't have my full code in front of me but this may help:

Note that I no longer recommend the python socket module in jython due to poor timing and ambiguous non-ASCII encodings. Use java.net or java.nio equivalents.

2 Likes

Finally made it back to my desk. Here’s a chopped down version of what I use.

from java.net import Socket
from java.io import DataOutputStream

partnum = 'ABCBEFGH'
serialNum = '12345678'

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
  
  
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
3 Likes

Called the second shift team lead and asked him to check the zebra printer and voila, like magic. Thank you both! Shouldn’t have done this before bed though, cue brain overdrive mode.

@pturmel I will look into some Java solutions for a long term permanent solution to this problem, but this is a good start

What Phil was saying was to use java libraries instead of the Jython ones. If you take a look at the imports at the top of the example I posted, you'll see we're using java libraries.

1 Like

Indeed. Though I haven’t seen the DataOutputStream used like that. I usually use a PrintWriter.

The java code works fine, we have similar code today printing to the zebra printers.

Recently I have been exploring the Zebra API as well. I was able to easily install the jars into Ignition and do some printing with their native API. Its actually quite good.

I’ll be switching over our current code to use their library in the future. If your using a newer zebra printer with LinkOS, the API code is even simpler and gives you a ton of options including full bi-directional status info.

I’d love to actually build a module around their API where the printers could be added as devices with tags for status and scripting functions for printing. But, with about 110% of my time consumed, that realistically won’t happen, but if some other module devs want to collaborate, let me know.

6 Likes

How did you get the Zebra API installed under ignition?

Never mind I figured it out.

1 Like

This is what we use and works fine in a windows environment. Then we just assemble an EPL string and send it to the printer.

def CreatePrintJob(EPLString):

	from javax.print import PrintService
	from javax.print import PrintServiceLookup
	from javax.print import SimpleDoc
	from javax.print import DocFlavor
	from org.python.core.util import StringUtil
	from jarray import array
	
	#print "print triggered "+ event.source.name 
	
	pserv = PrintServiceLookup.lookupDefaultPrintService()
	if pserv == None:
		print "ERROR-01: no default print service"
	
	#data = array(EPLString,'b')
	data = StringUtil.toBytes(EPLString)
	#print data
	
	doc = SimpleDoc(data, DocFlavor.BYTE_ARRAY.AUTOSENSE, None)
	pserv.createPrintJob().print(doc, None)
	return
	
def LookupPrintServices():
	
	from javax.print import PrintService
	from javax.print import PrintServiceLookup
	from javax.print import SimpleDoc
	from javax.print import DocFlavor
	
	from jarray import array
	
	#print "print triggered "+ event.source.name 
	
	pservList = PrintServiceLookup.lookupPrintServices(None,None)
	if pservList == None:
		print "ERROR-01: no default print service"
	
	print pservList
	return
	
def CreateLabelPrintJob(EPLString,Name):

	from javax.print import PrintService
	from javax.print import PrintServiceLookup
	from javax.print import SimpleDoc
	from javax.print import DocFlavor
	from org.python.core.util import StringUtil

	from jarray import array
	
	pservList = PrintServiceLookup.lookupPrintServices(None,None)
	if pservList == None:
		print "ERROR-01: no default print service"
	
	printer = None
	for i in range(len(pservList)):
		s = str(pservList[i])
		r = s.find(Name)
		if r != -1:	printer = pservList[i]
	
	if printer == None:
		print "ERROR-01: no Label Printer"
		system.gui.messageBox("Printer " + Name + " not located, ensure correct printer is connected.","PRINTER NOT FOUND")
	else:
		#data = data = array(EPLString,'b')
		data = StringUtil.toBytes(EPLString)
		#print data
		
		doc = SimpleDoc(data, DocFlavor.BYTE_ARRAY.AUTOSENSE, None)
		printer.createPrintJob().print(doc, None)
		return
1 Like

Hi,
Below code working in vision module. Can you please share code for Ignition Perspective module ( version 8.1.15 web browser running application print )?
like:- Table dataset record print

[quote=“JordanCClark, post:11, topic:8957”]

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"
Hi,
Can you please share which tools use for to design barcode print label?
e,g,:- auto tools  generated code create : "^FT170,040^A0N,40,45^FD%s^FS"

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