# Sending data to printer over TCP

**URL:** <https://forum.inductiveautomation.com/t/sending-data-to-printer-over-tcp/14161>\
**Category:** Ignition\
**Created:** [April 28, 2017, 6:38am UTC](https://forum.inductiveautomation.com/t/sending-data-to-printer-over-tcp/14161 "2017-04-28T06:38:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [April 28, 2017, 6:38am UTC](https://forum.inductiveautomation.com/t/sending-data-to-printer-over-tcp/14161/1 "2017-04-28T06:38:26Z")

</div>

I have had a look at some other topics involving setting up a TCP connection, and have managed to send some data to a label printer successfully.

Just trying to figure out the best and most reliable way to do it.

**Some background:**  
Printer is an Intermec PD43 label printer.  
Using IPL commands to send data / commands to printer.

I have tried the following two methods:

**1) Purely using Python scripting**  
Unfortunately I cant figure out why sometimes it works and sometimes it doesn’t (with no indication of an error).

Code:

```auto
def printLogLabels(data):
    # data - pyList of serial numbers to print. ie: [1000000321, 1000000123]

 	import socket
	import sys
	
	scriptName = 'shared.production.printLogLabels '
	log = system.util.getLogger("Script Debugger")

	tcp_ip = '192.168.44.198'
	tcp_port = 9101

	try:
		s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		s.connect((tcp_ip, tcp_port))
		# Loop through data list and send print command for each serial number
		for item in data:
			MESSAGE = "<STX><ESC><E2<CAN><ETX><STX><ESC>F1<LF>" + str(item) + "<ETX><STX><ETB><ETX>"
			print MESSAGE
			s.send(MESSAGE)
		# end for

		s.close()
		return True

	except:
		shared.log.scriptError(scriptName + str(sys.exc_info()[1]))	
		return False	
	# end try
# end def

```

I’m wondering if there is some issue with socket connection that i need to check the status of somehow.  
I read in an earlier topic that changing the tcp port and back again worked, which i have had some success with.

* * *

**2) Ignition TCP Driver**  
I have also looked at using the Ignition TCP Driver to do the same thing, and have had some pretty good success with that.  
I’ve been writing directly to the TCP Driver tag using:

```auto
	try:
		for item in data:
			message = "<STX><ESC><E2<CAN><ETX><STX><ESC>F1<LF>" + str(item) + "<ETX><STX><ETB><ETX>"
			system.tag.write("Gisborne01/ProdSystems/IntermecPD43/Writable", message)
		# end for
		return True
		
	except:
		shared.log.scriptError(scriptName + str(sys.exc_info()[1]))	
		return False	
	# end try

```

Is it better practise to use the method mentioned in [this](http://forum.inductiveautomation.com/t/tcp-driver-writable-tag-question/4559/2) post when writing to TCP driver tags?  
Should I be clearing the tag myself after every write? Seems like i don’t have to.

Also how can i detect errors with the connection? I don’t think i can use the Inactivity Timeout because i’m never actually receiving data from the source.  
Pulling the Ethernet cable doesn’t seem to affect tag quality or device status.

Thanks!

---

<div class="post-metadata">

**Author:** ![saadia.gauhar](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@saadia.gauhar](https://forum.inductiveautomation.com/u/saadia.gauhar)\
**Post date:** [March 31, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/sending-data-to-printer-over-tcp/14161/2 "2021-03-31T19:43:07Z")

</div>

Hi,  
Were you successful in communicating with the PD43 printer?

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 31, 2021, 8:01pm UTC](https://forum.inductiveautomation.com/t/sending-data-to-printer-over-tcp/14161/3 "2021-03-31T20:01:04Z")

</div>

Hi,

Yes i got it working by using method #2 above.  
Interesting timing though, as we’ve just started having issues with the printer not working after several years of no problems. So trying to work through that now…

The main problem i’m finding with the method #2 is that there is no real confirmation that the packet was received, and no real errors if things go wrong.

---

<div class="post-metadata">

**Author:** ![saadia.gauhar](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@saadia.gauhar](https://forum.inductiveautomation.com/u/saadia.gauhar)\
**Post date:** [May 3, 2021, 6:20pm UTC](https://forum.inductiveautomation.com/t/sending-data-to-printer-over-tcp/14161/4 "2021-05-03T18:20:28Z")

</div>

How are you mapping the writable tag for TCP driver? I am little confused here the only tags that I find in browse are Last Receive Time and Message under 9100 and Diagnostics

---

<div class="post-metadata">

**Author:** ![saadia.gauhar](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@saadia.gauhar](https://forum.inductiveautomation.com/u/saadia.gauhar)\
**Post date:** [May 3, 2021, 7:55pm UTC](https://forum.inductiveautomation.com/t/sending-data-to-printer-over-tcp/14161/5 "2021-05-03T19:55:03Z")

</div>

I have got that figured out…thanks
