# Unicode ftp-8 TCP communications

**URL:** <https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259>\
**Category:** Ignition\
**Created:** [February 17, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259 "2022-02-17T15:29:02Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 17, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/1 "2022-02-17T15:29:02Z")

</div>

I’ve set up an EMPERIA in-line printer as a TCP device and communication was working well. Then they wanted to put up and down arrows in the text being printed. When I added an up arrow, the printer showed this as a ‘?’ so it was not getting the coding correct. The documents say it is utf-8 coding for the command language.  
In the printer, I set a variable up and put in an up arrow (U+2191 on their popup keyboard) and then read out the variable to Ign. What I got was ‘â†’ . If I copy that into the message I send to the printer, it does receive it as an arrow. I have tried some things I found online for encoding to utf-8 but nothing helps if I start with an actual arrow in the sting. I thought I would just put in a brute force decoding of the string before sending it and substitute in the characters it wants but I ran into a problem. This all happened on v8.0.13 so I updated to 8.1.14 last night. Now when I pull in a variable from the printer with a symbol, I actually see the symbol in the string, not the hieroglyphics I was getting before. Now I can’t even use that trick to get the ‘code’ for additional symbols. Can anyone point me in the right direction on how to encode these things properly?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 17, 2022, 4:10pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/2 "2022-02-17T16:10:00Z")

</div>

How are you definining your strings, exactly?  
Python 2 requires that strings that contain non-ASCII be prefixed with `u` to mark them as unicode literals, e.g.:  
`variable = u"â†"`

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 17, 2022, 4:21pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/3 "2022-02-17T16:21:26Z")

</div>

I gave them a button to add arrows when setting the text to print.  
newMsg = oldMsg + u’\u2191’  
This shows an up arrow in the string but when I look in the printer it is a ‘?’.  
if instead I do this:  
newMsg = oldMsg + ‘â†‘’  
it shows up in the printer as an arrow, but the messages in my db look like â†‘â†‘Qâ†‘â†‘ which nobody will understand. If I know how to get from u’\u2191’ to â†‘ I can put an interpreter behind the scene, just before sending it to the printer. But I can’t find anything online. I assume it represents the utf-8 ‘0xE2 0x86 0x91’ for an up arrow, but I’m not sure how to translate to that and substitute it into the string as a character. Brute force would work if I knew the down arrow version of â†‘ but then I would still only be handle those two characters. Tomorrow, they will want something else.

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 17, 2022, 4:24pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/4 "2022-02-17T16:24:28Z")

</div>

FYI, even in the post, you are not seeing what I am really pasting in there. It looks like this while I am editing.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/ebf0eae3d75cd6fda5d0ecedd40596a06d58c051.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 17, 2022, 5:12pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/5 "2022-02-17T17:12:35Z")

</div>

Let’s step back a bit - can you share the full code you’re using to write to this printer, and/or any docs you might have from the printer? An encoding loss could be happening at multiple steps along the process.

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 17, 2022, 5:44pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/6 "2022-02-17T17:44:51Z")

</div>

There are a lot of steps that passes this thing around. A lot of this was an attempt to make it clear to future me.

I have a loop that constantly polls for data. In that loop I also have a step that checks if manual commands are in que to be sent. In a button, I add this manual command to that que to set a variable in the printer.

```auto
	var = self.getChild("Dropdown").props.value
	val = self.getChild("TextField_0").props.text
	#val = unicode(val, 'utf-8')
	#val = u'\u2191'
	if len(val) > 0:
		newRow = ['VAR_SET', var, val]
		oldDS = system.tag.read('[default]Printers/MPERIA/Send/PollingMessages').value
		newDS = system.dataset.addRow(oldDS, newRow)
		system.tag.write('[default]Printers/MPERIA/Send/PollingMessages',newDS)

```

Then it is picked up in the while loop (in an asynchronous thread function defined in a button for now) and then calls a script to build the msg in the format that the printer expects.

```auto

elif index == 5:
					# special command (manual stuff)
					# pull the command off of the top of the stack and send it
					# then remove the command. 
					specialMsgs = system.tag.read('[default]Printers/MPERIA/Send/PollingMessages').value
					if specialMsgs.rowCount > 0:
						cmd = specialMsgs.getValueAt(0, 0)
						p1 = specialMsgs.getValueAt(0, 1)
						p2 = specialMsgs.getValueAt(0, 2)
						msg = MPERIA.msg(cmd, p1, p2)
						removed = system.dataset.deleteRow(specialMsgs, 0)
						system.tag.write('[default]Printers/MPERIA/Send/PollingMessages', removed)

```

The script in the project Library that builds the message:

```auto
def msg(name, p1, p2):
	ACK = chr(6) 
	# Acknowledge. Sent from the Controller to indicate the success of a 
	# command sent to the Controller
	
	NAK = chr(21)
	# Negative acknowledge. Sent from the Controller to
	# indicate the failure of a command sent to the Controller.
	
	ETB = chr(23)
	# End of Transmission Block. Used as the final character in
	# all commands sent to the Controller, and as the end of data
	# sent from the Controller as a response to a command.
			
	ESC = chr(27)
	# Escape. Used as the starting character in all commands
	# sent to the Controller.
	
	FS = chr(28)
	# Unit Separator. Separates the command and arguments
	# sent to the Controller, and multiple responses sent from
	# the Controller as a response to a command.
				
	GS = chr(29)
	# Group Separator. Separates components of command
	# arguments into groups.
		
	RS = chr(30)
	# Record separator used to separate groups into records.
	
	US = chr(31)
	# Unit separator used to separate records into units.
	
	if p1 == None:
		msg = ESC + name + ETB
	elif p2 == None:
		msg = ESC + name + FS + p1 + ETB
	else:
		msg = ESC + name + FS + p1 + FS + p2 + ETB

	return msg

```

Then at the end of the loop

```auto
				if index > 0:
					sentTS = system.date.now()
					result = system.tag.writeBlocking(['[default]Printers/MPERIA/Writable'],[msg],1000)

```

[Command-Protocol-Manual-11.2.x.pdf](https://forum.inductiveautomation.com/uploads/short-url/4tpqkcddwyiUpO9KLaZHt9TtPY0.pdf) (407.1 KB)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 17, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/7 "2022-02-17T17:56:04Z")

</div>

I think you want to send your data to the `WritableBytes` tag, not the `Writeable` tag, which does some automatic encoding of data. If you’re trying to send specific data, that’s your best bet.

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 17, 2022, 5:57pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/8 "2022-02-17T17:57:47Z")

</div>

Update:  
I changed all of the chr() statements to unichr() and changed the final statement to write the tag as  
u = msg.encode(‘utf-8’)  
result = system.tag.writeBlocking([’[default]Printers/MPERIA/Writable’],[u],1000)  
and now I see a rectangle in the printer instead of the ‘?’

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 17, 2022, 5:59pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/9 "2022-02-17T17:59:55Z")

</div>

A rectangle on the actual output label? That would (to me) indicate that the printer doesn’t have a font to use to render the character.

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 17, 2022, 6:19pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/10 "2022-02-17T18:19:14Z")

</div>

I assume you are correct.  
I’m going down the road you suggested for the writablebytes tag. When I created the device I was on an older version that did not have that feature so I didn’t even know that was an option. I’ll figure that out and mark as solution if it works. Thanks.

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 18, 2022, 4:20pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/11 "2022-02-18T16:20:49Z")

</div>

I am writing to the WritableBytes tag and I am getting the same results as before.  
I am converting to bytes using this:  
def toBarray(string):  
from java.lang import \*  
from org.python.core.util import StringUtil

```
#Convert string into a byte array
bArr = StringUtil.toBytes(string) #Read string into byte array
return bArr

```

I received a suggestion from MPERIA:

Can you try this in Hex?

1B 76 61 72 5F 73 65 74 1C 76 61 72 31 1C **E2 86 91** 17  
Seen as ascii:  
var\_setvar1 **â†‘**

Here is a convert from u+ (2191) to UTF8

> <https://gist.github.com/hakre/2351606>

I cannot figure out how to send his string of hex.  
I do know that when I put var\_setvar1 **â†‘** (with the ascii commands send as chr equivalents, ie unichr( 27) for )  
I get  
array(‘b’, [27, 83, 69, 84, 95, 86, 65, 82, 28, 118, 97, 114, 49, 28, 63, 23])

is it possible to send the hex version to the writeablebytes tag?

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 18, 2022, 4:46pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/12 "2022-02-18T16:46:34Z")

</div>

Again, when I put in the strings to this forum they look fine until I post it. Here is what the blurb from MPERIA actually looks like:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/6/964008e1d2b94eb09708f82875a4af4f7dc007fb.png)

---

<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:** [February 18, 2022, 5:22pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/13 "2022-02-18T17:22:06Z")

</div>

try using the array library

```python
import array

stringIn = 'ABCD ↑'

# For display purposes. Printing the array will return decimals.
hexValues = [elem.encode('hex') for elem in stringIn]

bArray = array.array('B', stringIn)

print hexValues
print bArray

```

Output:

```nohighlight
['41', '42', '43', '44', '20', 'e2', '86', '91']
array('B', [65, 66, 67, 68, 32, 226, 134, 145])
>>> 

```

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 18, 2022, 6:07pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/14 "2022-02-18T18:07:33Z")

</div>

> [@JordanCClark](#):
>
> `hexValues = [elem.encode('hex') for elem in stringIn]`

Thank-you  
That may have put me on to something.  
This reflects how I am adding the arrows to my strings and the results I get using your code:  
import array  
a = u'\u2191'  
strIn = 'ABCD ' + a  
print strIn  
hexValues = [elem.encode('hex') for elem in strIn]  
print hexValues

ABCD ↑  
['41', '42', '43', '44', '20', 'e28691']

I'm not sure if you just used the keyboard shortcut to type your up arrow, but that is not an option for this application. It appears the way I am doing it is causing an error.

---

<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:** [February 18, 2022, 7:36pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/15 "2022-02-18T19:36:36Z")

</div>

Try wrapping your string with a bytes() function

```python
import array

stringIn = bytes(u'ABCD \u2191')

hexValues = [elem.encode('hex') for elem in stringIn]

bArray = array.array('B', stringIn)

print hexValues
print bArray

```

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 18, 2022, 7:56pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/16 "2022-02-18T19:56:02Z")

</div>

That worked.  
Now I know how to recreate the hex code they want me to send which is good progress but I don’t seem to be able to send that to the WriteableBytes tag of my TCP device.

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [February 18, 2022, 8:28pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/17 "2022-02-18T20:28:54Z")

</div>

Thanks Jordan, your suggestion led to the solution. I ended up not needing the hex values at all.  
I was sending my strings to be printed to a script to turn them into a byte array.  
def toBarray(string):  
from java.lang import \*  
from org.python.core.util import StringUtil

```
#Convert string into a byte array
bArr = StringUtil.toBytes(string) #Read string into byte array
return bArr

```

I was sending them with the line  
bArr = MPERIA.toBarray(msg)  
I changed it to this:  
bArr = MPERIA.toBarray(bytes(msg))

now it works. It seems strange to need to change a string to bytes before sending it to a script I found that is supposed to make bytes itself but I’m not poking it with a stick.

---

<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:** [February 18, 2022, 9:30pm UTC](https://forum.inductiveautomation.com/t/unicode-ftp-8-tcp-communications/56259/18 "2022-02-18T21:30:01Z")

</div>

Unicode can be annoying. I’ve spent many hours pulling my hair out over similar stuff. 🙄
