# Send ZPL command to Zebra 170PAX4 via TCP/IP Socket

**URL:** <https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003>\
**Category:** Ignition\
**Created:** [March 10, 2013, 3:03am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003 "2013-03-10T03:03:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [March 10, 2013, 3:03am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/1 "2013-03-10T03:03:02Z")

</div>

Hello Everyone,  
I'm trying to send print labels to a Zebra printer and been somewhat successful.  
I can send the first print job to the printer and the printer prints the label right away on the second send the printer takes minutes before it prints if I keep trying to send it eventually I get a socket error connection refuse.  
When I use the Zebra Setup Utility to send the same exact command I have not issues therefore it has to be something within Ignition (I'm using the latest version) or I'm doing something wrong.  
 ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

Here is a snip of the code I'm using  
#========================================================================================

# ZPL II commands

#========================================================================================  
strMessage="^XA^LH96,96^LRY^FO10,0^ADN,18,5^FDHUE08161110136^FS^XZ"

#========================================================================================

# Import Socket Library

#========================================================================================

import socket  
#========================================================================================

# Get Printer IP from Database

#========================================================================================  
strIP = system.tag.getTagValue("Murrieta/Printers/Zone1/Left/IP")  
#========================================================================================

# Send Data to Printer

#========================================================================================  
port=9100  
updSocket=socket.socket(socket.AF\_INET,socket.SOCK\_STREAM)  
updSocket.connect((strIP,port))  
updSocket.sendall(strMessage)  
updSocket.close

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [March 11, 2013, 3:34pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/2 "2013-03-11T15:34:41Z")

</div>

Check out this forum thread and see if it helps.

[viewtopic.php?f=70&p=31719](http://www.inductiveautomation.com/forum/viewtopic.php?f=70&p=31719)

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [March 11, 2013, 9:52pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/3 "2013-03-11T21:52:48Z")

</div>

[quote=“Greg.Simpson”]Check out this forum thread and see if it helps.

[viewtopic.php?f=70&p=31719](http://www.inductiveautomation.com/forum/viewtopic.php?f=70&p=31719)[/quote]

Thanks but that is exactly what I’m doing my problem is that after the first message send the printer stops responding, don’t know if there are extra data being send to the printer that is causing it to lock withing the ignition. As mentioned earlier if I use the Zebra Setup Utility to send data it works without problems so its something in ignition.

---

<div class="post-metadata">

**Author:** ![dave.fogle](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dave.fogle](https://forum.inductiveautomation.com/u/dave.fogle)\
**Post date:** [March 12, 2013, 11:26pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/4 "2013-03-12T23:26:43Z")

</div>

I'm not exactly sure what is going on. When you say that you send the exact same command using the Zebra Utility does that also include the python socket connection and sendall commands?

I'm just shooting in the dark here but maybe the sendall function is not terminating like it should or is raising an exception that isn't being caught. Did you try using the sendto function instead of connecting to a socket and then calling sendall?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 13, 2013, 3:16am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/5 "2013-03-13T03:16:39Z")

</div>

Try using Wireshark to see what’s actually going on.

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [March 13, 2013, 5:01am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/6 "2013-03-13T05:01:53Z")

</div>

Great minds think alike, I was just going to post my finding with Wireshark.  
I discovered that using the Python’s socket library when opening the connection Phyton send a Name Query with port 137 (netbios-ns) while the Zebra Utility doesn’t.  
I switch the script to use Java’s socket seems to work the same as the Zebra Utility.  
Once I go back to the customer site on Thursday I will verify with an actual printer.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/979ef0f7943cfe5e9ea759f6cce587978331e0d8.png)  
  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/957a113d9bf4e30692a56b10ceff212180c4a73e.png)  
  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d9f438d04a3923bbc0219200ddb21f2f7e04e1ce.png)

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [April 22, 2013, 9:08pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/7 "2013-04-22T21:08:08Z")

</div>

Sorry for the Delay been busy, changing the script to utilize the Java socket work and now I’m able to print without issues.  
Bellow if a snip of the code if anyone needs it.

strMessage = “^XA^LH10,10^LRY^F010,45^AFN,20,20^FDHELLO^FS^XZ”  
#========================================================================================

# Send Data to Printer

#========================================================================================  
port=9100  
try:  
# Open Socket Connection  
clientSocket=Socket(strIP,port)  
#Open data output stream  
outToPrinter=DataOutputStream(clientSocket.getOutputStream())  
#Send Data to Printer  
outToPrinter.write(strMessage)  
#close data stream and socket  
outToPrinter.close();  
clientSocket.close();  
except IOError:  
print “Error”

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [October 20, 2017, 1:55am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/8 "2017-10-20T01:55:51Z")

</div>

Hello I am trying to use your code as as script on a button

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/36d9bede8a8fcdf9839621d37e368f5c67076298.png)  
But I am getting the following errors:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/1b06fead6bc9214a12a30226801cb5a5a8e617d9.png)  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/86035218abe64658218b8362cb99d37fdb965eb6.png)

Any thoughts?

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [October 20, 2017, 2:14am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/9 "2017-10-20T02:14:58Z")

</div>

You have to import the Socket class from Java.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [October 20, 2017, 3:34am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/10 "2017-10-20T03:34:58Z")

</div>

Please note that there is a much simpler way to communicate with Zebra nowadays using HTTP.

[https://km.zebra.com/kb/index?page=content&id=WH133&actp=LIST](https://km.zebra.com/kb/index?page=content&id=WH133&actp=LIST)

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [October 20, 2017, 3:50am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/11 "2017-10-20T03:50:26Z")

</div>

Many many thanks for your response.  
I am going to read that one too!!

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [October 20, 2017, 3:51am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/12 "2017-10-20T03:51:03Z")

</div>

I believe there is going to be a Zebra printer module released very soon. Not by me, but soon, very soon.

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [October 20, 2017, 12:20pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/13 "2017-10-20T12:20:40Z")

</div>

REALLY!!! You have peaked my interest…

Also, really cool API I found is [http://labelary.com/](http://labelary.com/) it can be used to preview ZPL code to images and has a nice webservice. I have used it in Ignition to preview labels before sending them to a printer.

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [October 20, 2017, 12:30pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/14 "2017-10-20T12:30:28Z")

</div>

Thanks for the HTTP tip. I did not know this was possible this easily.

Here is an Ignition snippet for reference that prints ZPL to a printer

```auto
system.net.httpPost('http://192.168.1.10/pstprnt', postData="^XA^WD^XZ")

```

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [October 20, 2017, 10:48pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/15 "2017-10-20T22:48:14Z")

</div>

Also check out their SDK.  
The printers now have JSON out of band management on port 9200. They should also come with Bluetooth and RFID sticker on the side, at least for the ZT410s.  
We have done a lot of work around this. At one point we had a simple iPhone app that our techs could run whenever they needed to provision a printer. The app sent all the necessary payloads to configure the printer, point it back to an FTP server (Zebra Mirror) for firmware updates. etc. Another thing we tried is to put the label templates on each printer and send XML print jobs direct over HTTP, but without a management tool it was a hassle and we settled on NiceLabel. Coincidentally Zebra’s label designer is a stripped down OE version of NiceLabel. NiceLabel software is nice, but their support sucks, and development is in Europe.

… and then we got pissed at Zebra and moved to Honeywell. In the end a printer is a printer is a printer. But the techs do miss the app.

Let me know if I can help more with these printers.

> **[Link-OS Multiplatform SDK | Zebra](https://www.zebra.com/us/en/products/software/barcode-printers/link-os/link-os-sdk.html)**
>
> The Link-OS™ Multiplatform SDK enables app creation on PCs, smart phones and tablets supporting the most popular operating systems.

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [October 21, 2017, 12:18am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/16 "2017-10-21T00:18:05Z")

</div>

Thank you so much for your help:  
I was able to print by pressing a button on Igniton:  
All I needed to do was set the following code on the Script Editor of the mousedPressed\* and I was able to print Hello World! hahaha. Thank you guys.  
system.net.httpPost(‘[http://192.168.16.10/pstprnt](http://192.168.16.10/pstprnt)’, postData="^XA^FO50,50^A0N50,50^FDHello World!^FS^XZ")

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8dff3e597451ad13bf7dbe3e73ee2483dd8f6e15.png)

By the way, this is a great tool for generating the zpl code you need: [Labelary Online ZPL Viewer](http://labelary.com/viewer.html)  
Thanks for sharing!!

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [October 21, 2017, 12:42am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/17 "2017-10-21T00:42:10Z")

</div>

I think I posted a video about our solution before, but here it is again.

---

<div class="post-metadata">

**Author:** ![automatisme.iton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/automatisme.iton/32/5254_2.png) [@automatisme.iton](https://forum.inductiveautomation.com/u/automatisme.iton)\
**Post date:** [August 1, 2018, 10:02am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/18 "2018-08-01T10:02:48Z")

</div>

Hello

I need to preview a label before printing like you

can you tell me how you did it?

---

<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:** [August 1, 2018, 12:07pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/19 "2018-08-01T12:07:05Z")

</div>

I use an image component with the Labelary url in the Image Path.Works pretty slick. Here’s a sample window for you.

[test\_LabelPreview\_2018-08-01\_0804.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/aafd63e5cffb27c70379dc3fd60c14368c3de3f8.proj) (5.8 KB)

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [August 1, 2018, 1:08pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/20 "2018-08-01T13:08:42Z")

</div>

^ what he said 🙂

here is the function I use to get the preview image formatted for an Ignition Image path. depending on how I am using it, I either return it as a image path or wrapped in HTML for embedding in other things.

```auto
def getPreview(zpl, png=True):
	import urllib

	if zpl:
		zpl = zpl.replace('\r', '').replace('\n', '').replace('\t', '')
		zpl = urllib.quote(zpl, '^:~,')
		url = "http://api.labelary.com/v1/printers/12dpmm/labels/3x2/0/%s" % zpl
		if png:
			return url
		else:
			return "<html><img style='width:100%; height: auto;' src='" + url + "' /></html>"
	else:
		return ''

```

[Next page](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003.md?page=2)
