# TCP Driver Writable tag issue

**URL:** <https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542>\
**Category:** Ignition\
**Created:** [January 14, 2015, 3:40am UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542 "2015-01-14T03:40:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DNP3](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@DNP3](https://forum.inductiveautomation.com/u/DNP3)\
**Post date:** [January 14, 2015, 3:40am UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/1 "2015-01-14T03:40:18Z")

</div>

I’m using the TCP driver to connect to a device that sends out data. The device requires an “ACK” message so I’m using the “Writable” tag that is created with the TCP driver. Be default this tag is a String. The last line in the code below is where I’m having my issue. The device is expecting a byte to be written back. In this case I’m trying to write a number 1 or 16x01. What the system.write function is sending is actually 16x31 which is an ASCII 1. I tried changing the “Writable” tag from a string to and Int without success. How can I write a nonASCII value to the “Writable” tag?

from java.lang import \*  
from org.python.core.util import StringUtil  
#Read the tag that stores the data from the TCP driver opject  
data = system.tag.read("[]_Group2_/4103/Message")  
#Convert string into a byte array  
bArr = StringUtil.toBytes(data.value) #Read string into byte array  
#Parse header data  
packetID = bArr[0]  
msgCnt = ((bArr[2] & 0xff) \<\< 8) | bArr[3] & 0xff #Combine two bytes into UInt  
qStat = ((bArr[4] & 0xff) \<\< 8) | bArr[5] & 0xff #Combine two bytes into UInt  
#Send PacketID back to device to increment message  
[color=#0000FF]system.tag.write("[]_Group2_/4103/Writable", bArr[0]) #Sends as ASCII vs byte[/color]

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [January 14, 2015, 1:17pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/2 "2015-01-14T13:17:34Z")

</div>

Did you try wrapping in an int() to force it to an integer value? Maybe Python is just converting to a string value on it’s own.

```auto
system.tag.write("[]_Group2_/4103/Writable", int(bArr[0])) #Sends as ASCII vs byte
```

---

<div class="post-metadata">

**Author:** ![DNP3](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@DNP3](https://forum.inductiveautomation.com/u/DNP3)\
**Post date:** [January 14, 2015, 2:23pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/3 "2015-01-14T14:23:46Z")

</div>

I tried what you suggested and it is still writing an ASCII 1 (16x31) instead of 16x01. I appreciate the suggestion!

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [January 14, 2015, 2:30pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/4 "2015-01-14T14:30:32Z")

</div>

Hmmm… that’s weird. I’ll have to play around with it a little bit and see why it would do that…

You know what… thinking about it a bit more. This is probably a problem with the TCP driver, not writing the correct value to the tag. Just because you’re writing a integer 1 to the tag doesn’t mean that when the TCP driver sends it out that it will send it as an integer. I don’t know much about the TCP driver, as I don’t use it, but I would start looking to see if there is a way to force the TCP driver to send in a specific format.

I would think it would respect the tag data type but you never know…

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [January 14, 2015, 2:48pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/5 "2015-01-14T14:48:03Z")

</div>

I created my own TCP sender code for sending messages to Marquees and other junk, worst case is you can edit/implement this and send what you need on your own and just bypass the TCP driver…

service is the port number. Change that to whatever port number you need or edit the function to be able to pass in a list of port number. Whatever you want.

[code]def sendToMarquee(ipList, message):

```
import socket
from org.apache.log4j import Logger
log = Logger.getLogger("app.Marquees.sendToMarquee")
status = False
statusList = []

for host in ipList:
	service = 49999
	family = socket.AF_UNSPEC
	socktype = socket.SOCK_STREAM
	protocol = 0
	flags = socket.AI_PASSIVE
	
	result = socket.getaddrinfo(host, service, family, socktype, protocol, flags)
		
	for family, socktype, protocol, canonname, sockaddr in result:
		try:
			socket.setdefaulttimeout(.5)
			sock = socket.socket(family, socktype, protocol)
		except socket.error:
			log.error("Problem creating communication socket for marquee: %s." %(host))
			continue
		try:
			sock.connect(sockaddr)
			sock.sendall(message)
			statusList.append(True)
							
		except socket.error:
			sock.close()
			sock = None
			log.error("Communication error or timeout for marquee: %s. Network communication could be down." %(host))
			statusList.append(False)
			continue
		break
		
	if sock != None:
		sock.close()
	
if False in statusList:
	return False
else:
	return True[/code]
```

---

<div class="post-metadata">

**Author:** ![DNP3](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@DNP3](https://forum.inductiveautomation.com/u/DNP3)\
**Post date:** [January 14, 2015, 8:51pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/6 "2015-01-14T20:51:23Z")

</div>

I was hoping to use the TCP driver to manage the connections as I’ll have up 15 connections that will be active all the time. I will start looking into your code and perform direct socket connections. Great code by the way and I appreciate you sharing!!!

---

<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:** [January 14, 2015, 8:56pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/7 "2015-01-14T20:56:23Z")

</div>

If you want to write 0x01 to the tag, try using chr(1) as the value in your write call.

---

<div class="post-metadata">

**Author:** ![DNP3](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@DNP3](https://forum.inductiveautomation.com/u/DNP3)\
**Post date:** [January 14, 2015, 10:52pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-writable-tag-issue/9542/8 "2015-01-14T22:52:33Z")

</div>

Writing chr(1) DOES WORK. I had to change the driver’s “Writable” tag back to a string which is what it is by default.

In summary I had to wrap my chr(bARR[0]) to send nonASCII values down the TCP driver.

Thank you everyone for your help
