Printing barcode to Zebra printer

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