# Printing barcode to Zebra printer

**URL:** <https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957>\
**Category:** Ignition\
**Created:** [August 26, 2014, 2:53pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957 "2014-08-26T14:53:56Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 2, 2022, 1:02pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/21 "2022-09-02T13:02:21Z")

</div>

> [@sagar.iparkar](#):
>
> Below code working in vision module.

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

> [@sagar.iparkar](#):
>
> ```auto
> 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"
> 
> ```

> **[ZebraDesigner 3 Software Support & Downloads | Zebra](https://www.zebra.com/us/en/support-downloads/printer-software/zebra-designer-3-downloads.html)**
>
> Software to design barcode labels.

-or-

[Labelary Online ZPL Viewer](http://labelary.com/viewer.html)

---

<div class="post-metadata">

**Author:** ![sagar.iparkar](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sagar.iparkar](https://forum.inductiveautomation.com/u/sagar.iparkar)\
**Post date:** [September 5, 2022, 7:28am UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/22 "2022-09-05T07:28:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 5, 2022, 1:38pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/23 "2022-09-05T13:38:13Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![sagar.iparkar](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sagar.iparkar](https://forum.inductiveautomation.com/u/sagar.iparkar)\
**Post date:** [September 7, 2022, 5:27am UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/24 "2022-09-07T05:27:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sagar.iparkar](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sagar.iparkar](https://forum.inductiveautomation.com/u/sagar.iparkar)\
**Post date:** [September 8, 2022, 10:21am UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/25 "2022-09-08T10:21:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 8, 2022, 10:44am UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/26 "2022-09-08T10:44:05Z")

</div>

No driver required.

> [@JordanCClark](#):
>
> Put it into a project script.

```python
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:

```python
pn = 'ABCDEFGH'
sn = '12345678'
printLabel(pn, sn, '192.168.140.61', 9100)
```

---

<div class="post-metadata">

**Author:** ![Shamsil\_Arefin](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@Shamsil\_Arefin](https://forum.inductiveautomation.com/u/Shamsil_Arefin)\
**Post date:** [April 17, 2023, 4:18am UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/27 "2023-04-17T04:18:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jhahn](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jhahn](https://forum.inductiveautomation.com/u/Jhahn)\
**Post date:** [April 16, 2024, 4:15pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/28 "2024-04-16T16:15:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 16, 2024, 4:28pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/29 "2024-04-16T16:28:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 16, 2024, 8:32pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/30 "2024-04-16T20:32:27Z")

</div>

`~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?

---

<div class="post-metadata">

**Author:** ![Jhahn](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jhahn](https://forum.inductiveautomation.com/u/Jhahn)\
**Post date:** [April 22, 2024, 8:36pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/31 "2024-04-22T20:36:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Francisco\_Ochoa](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@Francisco\_Ochoa](https://forum.inductiveautomation.com/u/Francisco_Ochoa)\
**Post date:** [September 27, 2024, 3:41pm UTC](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/32 "2024-09-27T15:41:32Z")

</div>

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

[Previous page](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957.md?page=1)
