# TCP driver hex send problem

**URL:** <https://forum.inductiveautomation.com/t/tcp-driver-hex-send-problem/10784>\
**Category:** Ignition\
**Created:** [November 13, 2015, 11:47am UTC](https://forum.inductiveautomation.com/t/tcp-driver-hex-send-problem/10784 "2015-11-13T11:47:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivakhiv](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@vivakhiv](https://forum.inductiveautomation.com/u/vivakhiv)\
**Post date:** [November 13, 2015, 11:47am UTC](https://forum.inductiveautomation.com/t/tcp-driver-hex-send-problem/10784/1 "2015-11-13T11:47:19Z")

</div>

Hi.  
I have device and I conected to him using Ignition TCP Driver.  
This device understend only HEX values.  
In Ignition I write script that send HEX values to device.

```auto
def fromhex():
	a = '1b02141b03e7'.decode('hex')
        system.tag.write("_IJ600_/4001/Writable", a)
```

This HEX command `1b02141b03e7` means that the device must return devices status.  
Device must reply this code `1B060000140302000000001B03DE`  
Also I write script to convert devices Tag Wrtitable and Massage to HEX:

`def tohex():	
		readMes = (system.tag.read("_IJ600_/4001/Message")).value
		readWrit = (system.tag.read("_IJ600_/4001/Writable")).value
		encodeMes = readMes.encode('hex')
		encodeWrit = readWrit.encode('hex')
		system.tag.write("_IJ600_/Mess_hex",encodeMes)
		system.tag.write("_IJ600_/Writ_hex",encodeWrit)
`

Problem - when I use my script to send data and conver what I send and what I received, I got this result:   
At first sight problem is whit my device, but I cread simple TCP client using Python and using my script send him HEX data. And what I see: `1b02141b033f`   
Why Ignishion change last two HEX sybols from e7 to 3f I dont understand.  
After that I picked the right code for Ignition, it is `1b02141b0337`.  
When i send it to my simple TCP client I see thes: `1b02141b03e7`  
  
Then I send new Hex to my device using Ignition and what I recive: `140302fdfdfdfdfdfdfdfd1b032e`  
  
According to the instructions of the device I should get this HEX code `1B060000140302000000001B03DE` why Ignition changing some bits I dont understabd.  
Please explain why Ignition does it, because when the I used simple TCP client, writing using python, to send commands and receive responses from the device, everything works correctly.  
What is the solution of this problem?

---

<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:** [November 13, 2015, 2:13pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-hex-send-problem/10784/2 "2015-11-13T14:13:37Z")

</div>

> [@vivakhiv](#):
>
> And what I see: `1b02141b033f`   
> Why Ignishion change last two HEX sybols from e7 to 3f I dont understand.

The TCP driver is best used for ASCII data wich is good for up to 0x7f. Any characters it does not recognize gets changed to a question mark (0x3f).

I imagine the same sort of thing is happening in reverse on the responses.

Check out [this thread](https://inductiveautomation.com/forum/viewtopic.php?f=72&t=14247&p=52158). It's relating more to UDP, but should be very similar.

---

<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:** [November 13, 2015, 2:56pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-hex-send-problem/10784/3 "2015-11-13T14:56:41Z")

</div>

Jordan beat me to it!

He’s right, it’s the same problem as in the other thread - the UDP and TCP driver are for simple text transfers, and the message tag is a string, which is UTF-8 encoded. Only a subset of binary data can survive the conversion from binary -\> utf8 -\> binary.

What you’re doing looks sufficiently complicated enough that you should just be opening a socket in scripting as well.

---

<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:** [November 13, 2015, 4:15pm UTC](https://forum.inductiveautomation.com/t/tcp-driver-hex-send-problem/10784/4 "2015-11-13T16:15:57Z")

</div>

[quote=“Kevin.Herron”]Jordan beat me to it!

He’s right…[/quote]

Be sure to tell my wife! 😆
