I am having a hard time getting a Zebra ZT230 to print a barcode label from a Project script. I am using a slight variation of a script from a earlier post.
I am getting this error: TypeError:'com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleModule' object is not callable I am calling this from the script console and also tried from a button event onActionPerformed with no luck.
I will admit I have never had experience setting up a printer, as well as getting a barcode to print form Ignition. Is there any articles that I should look into? Or is this still possible with the script I have with rework?
Let me know if I need to provide anymore information.
Ah that got rid of the first error! Although, now it is giving this error: TypeError: java.net.Socket(): 1st arg can't be coerced to java.net.InetAddress, String
It was written for ethernet. It won't work on USB.
If you are running this in a perspective session, the gateway needs access to the printer, not the client session, where I assume the printer is located.
That worked perfectly! I am not getting any errors within the script as well as the script console. Although, now I need to figure out why it isn't printing once I run the script!
The Script Hint Scope just lets you chose what types of functions it will hint you for. For instance if you set it to Client, then you wont see functions that can only run in the gateway. It’s just a “Hint” to what you can use. It doesn’t play any role in what scope the script is actually executed in.
In perspective, all scripts run on the gateway. Scripts run in the script console are local to the machine / user running the designer.
Since both the script console and a designer session wont work in this context, would using the perspective workstation be a good way to test?
I also added in a loop as requested from support, which does seem to find the printer name as it loops, but once I get to the if foundService it doesn't seem to print. I am using the script console at the moment to be able to view the print statements.
Perspective workstation does not provide scripted access to client-local printers. So, no.
Testing in the script console is utterly useless for something that needs to later work in gateway scope (Perspective script scope is an extension of gateway scope.)
Use logging instead of prints (via system.util.getLogger()) and monitor the gateway logs.
{ You need to plug your USB printer into the gateway, not your local workstation. }
After talking with support, we were able to get this script to print a serial number:
def printLabel(serialNum, printerName):
from javax.print import PrintService, PrintServiceLookup, DocFlavor, SimpleDoc
from java.lang import System
from org.python.core.util import StringUtil
from java.net import Socket
from java.io import DataOutputStream
foundService = False
printServices = PrintServiceLookup.lookupPrintServices(None, None)
for printService in printServices:
print("Made it in loop")
if printerName in printService.toString():
foundService = True
# break
if foundService:
print('Found serv')
strMessage100 = '^XA'
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+strMessage112+strMessage113+strMessage199
job = printService.createPrintJob()
flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE
byteArray = StringUtil.toBytes(strOut)
doc = SimpleDoc(byteArray, flavor, None)
job.print(doc, None)
Although, I would like to print a barcode with this serial number. Is this possible with a bit of rewrite with this code, or would it be better suited to look into the reporting module to get my results?
Zebra printers tend to support barcode generation internally. You just need the correct ZPL commands. I vaguely recall someone posting a ZPL "playground" website that might help you.
Which prints out the barcode alongside the serial number. Though when I go to scan this barcode it seems that the serial number isn't within the barcode itself.
Scratch that, it seems to be printing the serial number within the barcode!
Full working code for solution:
def printLabel(serialNum, printerName):
from javax.print import PrintService, PrintServiceLookup, DocFlavor, SimpleDoc
from java.lang import System
from org.python.core.util import StringUtil
from java.net import Socket
from java.io import DataOutputStream
foundService = False
printServices = PrintServiceLookup.lookupPrintServices(None, None)
for printService in printServices:
print("Made it in loop")
if printerName in printService.toString():
foundService = True
# break
if foundService:
print('Found serv')
strMessage100 = '^XA'
strMessage112 = '^FO50,50^B3N,N,100,Y,N^FD%s^FS' % serialNum
strMessage113 = '^XZ'
strOut = strMessage100+strMessage112+strMessage113
job = printService.createPrintJob()
flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE
byteArray = StringUtil.toBytes(strOut)
doc = SimpleDoc(byteArray, flavor, None)
job.print(doc, None)