# 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:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![isaiah](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@isaiah](https://forum.inductiveautomation.com/u/isaiah)\
**Post date:** [September 21, 2018, 1:37am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/21 "2018-09-21T01:37:36Z")

</div>

I am trying to print to a Zebra ZD410. I have used this snippet-  
system.net.httpPost(‘[http://10.50.100.250/pstprnt](http://10.50.100.250/pstprnt)’, postData="^XA^WD^XZ")

I cannot get the printer to do anything. I am able to ping it, and can print to it directly with the Zebra Setup Utility.  
I have a TCP device driver setup for port 6101.  
Can anyone help me out with what we may be missing here?

Thanks!

---

<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 21, 2018, 3:05am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/22 "2018-09-21T03:05:18Z")

</div>

Put something like this in a project script:

```auto
import socket, sys
def sendToZebra(payload):
	zebraAddr = ('10.50.100.250', 6101)
	try:
		s = socket.connect(zebraAddr)
		s.sendAll(payload)
	finally:
		s.close()

```

Then call it from your button event like so:

```auto
project.zebra.sendToZebra("^XA^WD^XZ")

```

Not tested precisely as above, but I use this pattern at a customer site. NOTE: No driver required.

---

<div class="post-metadata">

**Author:** ![isaiah](https://avatars.discourse-cdn.com/v4/letter/i/7ba0ec/32.png) [@isaiah](https://forum.inductiveautomation.com/u/isaiah)\
**Post date:** [September 21, 2018, 4:50am UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/23 "2018-09-21T04:50:34Z")

</div>

Awesome! I will give it a try. Thank you!

---

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [May 6, 2021, 3:07pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/24 "2021-05-06T15:07:29Z")

</div>

Sorry maybe I should make a new post but my question rides right here along the path of this post.  
I have a project in perspective where I need to print a small label, I would love to print usb but it doesn’t look like that is viable option. I have followed the rabbit to the zebra ZPL implementation where I would send a payload to the printer over the network. Looking for anymore success that anyone has had using perspective to print a label. I do not want to render a pdf and rely on the user to choose printing the pdf on the OS either.

---

<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:** [May 6, 2021, 3:35pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/25 "2021-05-06T15:35:27Z")

</div>

As long as the gateway has access to the printer, there should be no issue using ZPL.

> [@Printing barcode to Zebra printer](http://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/11):
>
> 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" strO…

---

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [May 6, 2021, 4:38pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/26 "2021-05-06T16:38:33Z")

</div>

In the one post by malcolm I would like to send the image of the container to the label.  
I will use dropdown menus to populate the values in the container but there are also some graphics, mainly a logo. I also see the other fellow with the zebra API. That looks interesting. I have not decided if perspective is a good application for this or not. Even usb printers have setup involved so I dont know why I am hung up on usb other than past experience and usual lack of ethernet ports not consumed by something. doing the http post sound possible but its the payload being a graphic container. Maybe that is the part I dont understand. How to render a container with other variable content into this ZPL. I am not familiar with ZPL. It surely isn’t a simple as passing the container as an object into some script payload…?

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [May 6, 2021, 4:59pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/27 "2021-05-06T16:59:42Z")

</div>

@tailfire One thing you can do is download Zebra’s label design software called ‘ZebraDesigner’ as well as Zebra setup utilities. Then what you do is design the label in the ZebraDesigner, then change some settings to output the ZPL code for your label to a file rather than sending it to the printer. Then you can copy and paste the ZPL code into a script in perspective. In your script you can insert the data that the user selected into the label’s code before you send the code to the printer. In order to send the code to the printer (assuming your printer is on your network) you can create a socket in your script, connect to the printer using its IP, then convert your ZPL code string to bytes and send it to the printer using the socket.

To send the code to a file you open Zebra Setup Utilities, open Printer Tools for your printer, and change the port to “print to file”. If you google how to send ZPL code to file using ZebraDesigner you should be able to find more information (that’s how I learned about this).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![chandler](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@chandler](https://forum.inductiveautomation.com/u/chandler)\
**Post date:** [May 6, 2021, 5:10pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/28 "2021-05-06T17:10:00Z")

</div>

What I did was put easily recognizable values for each part of my label, so that when I looked at the code they were easy to find and modify for my script. here is a simple example that puts a few strings on a label as well as writes to an RFID tag:

```auto
^XA
^MMT
^PW799
^LL1199
^LS0
^FO19,995^GB760,0,8^FS
^FT159,1078^A0N,83,132^FB433,1,21,C^FH\^CI28^FDthis is my string^FS^CI27
^FT139,1122^A0N,28,30^FB480,1,7,C^FH\^CI28^FD12345678901234567890123456789012^FS^CI27
^RFW,H,1,2,1^FD4000^FS
^RFW,H,2,16,1^FD01234567890123456789012345678901^FS
^PQ1,0,1,Y
^XZ

```

Then I could modify the code to look like this:

```auto
^XA
^MMT
^PW799
^LL1199
^LS0
^FO19,995^GB760,0,8^FS
^FT159,1078^A0N,83,132^FB433,1,21,C^FH\^CI28^FD{}^FS^CI27
^FT139,1122^A0N,28,30^FB480,1,7,C^FH\^CI28^FD{}^FS^CI27
^RFW,H,1,2,1^FD4000^FS
^RFW,H,2,16,1^FD{}^FS
^PQ1,0,1,Y
^XZ

```

and insert the values that I actually want on the label using python’s `str.format` function before I send the code to the printer.

---

<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:** [May 6, 2021, 7:09pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/29 "2021-05-06T19:09:03Z")

</div>

Hi All,  
What I have done is just what @chandler mentioned, I created the label using the Zebra's label designer send the print to a file exposing the ZPL code. The application I currently have running consist of a Database that has all the parameters of the label including any logos. When ever the particular label needs to be printed I call the database that has all the information and create a string (similar to what @JordanCClark mentioned) that I send to the printer.  
You can use [Labelary Online ZPL Viewer](http://labelary.com/viewer.html) to check the ZPL code.

example:  
#Create Label String  
#Header, LOGOS, BARCODE, ID Number, Item Number, Use Thru Date, Product Name, WEIGHT, PRODUCTION DATE, ORIGIN  
strLabel = "%s%s%s%s%s%s%s^FO1103,464^GB347,103,4^FS^FT1149,549^A0N,75,74^FH^FD%s lb^FS%s%s" %(strLabelHeader,strLabelLogos,strBarcode,strID\_number,strItem\_number,strUseThruDate,strProduct,strLabelWeight,strProductionDate,strCountry)  
#ALLERGEN, ING1, ING2, ING3, ING4, ING5, 2nd Barcode, DIST1, DIST2, LOT, BATCH, SAMPLE, FOOTER  
strLabel = "%s%s%s%s%s%s%s%s%s%s%s^FT1371,837^A0N,83,81^FH^FD%s^FS" %(strLabel,strAllergen,strIngredient1,strIngredient2,strIngredient3,strIngredient4,strIngredient5,str2ndbarcode,strDistributed\_by1,strDistributed\_by2,strLot1,strSerial)

# SAMPLE, FOOTER

strLabel = "%s%s%s" %(strLabel,strSample,strLabelFooter)  
system.tag.write("Petaluma/Cheese/Packing/Label

# Print Label

clientSocket=socket.socket(socket.AF\_INET, socket.SOCK\_STREAM)  
clientSocket.connect((strIP,port))  
clientSocket.sendall(strLabel)  
clientSocket.close()

---

<div class="post-metadata">

**Author:** ![Michael\_Emnett](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@Michael\_Emnett](https://forum.inductiveautomation.com/u/Michael_Emnett)\
**Post date:** [July 8, 2024, 4:50pm UTC](https://forum.inductiveautomation.com/t/send-zpl-command-to-zebra-170pax4-via-tcp-ip-socket/6003/30 "2024-07-08T16:50:47Z")

</div>

I can confirm that this still works. Simply added the printer to the server our gateway runs on, retrieved the IP, and ran that same code.  
Thanks for the help guys 👍

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