Printing barcode to Zebra printer

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