# Barcode Component encoding

**URL:** <https://forum.inductiveautomation.com/t/barcode-component-encoding/34924>\
**Category:** Ignition\
**Tags:** ignition78, ignition79\
**Created:** [May 21, 2020, 3:31am UTC](https://forum.inductiveautomation.com/t/barcode-component-encoding/34924 "2020-05-21T03:31:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.ruel](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@michael.ruel](https://forum.inductiveautomation.com/u/michael.ruel)\
**Post date:** [May 21, 2020, 3:31am UTC](https://forum.inductiveautomation.com/t/barcode-component-encoding/34924/1 "2020-05-21T03:31:52Z")

</div>

Does anyone know if the Barcode Component automatically starts the Code128 with the FNC1 or would one have to put that in their code? Using 7.8.5.  
Also how do you encode the functions in an Expression or script. I have to piece together several pieces of information and am wondering how to put in the ENTER function.

---

<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:** [May 21, 2020, 4:31pm UTC](https://forum.inductiveautomation.com/t/barcode-component-encoding/34924/2 "2020-05-21T16:31:14Z")

</div>

> [@michael.ruel](#):
>
> Does anyone know if the Barcode Component automatically starts the Code128 with the FNC1 or would one have to put that in their code?

I can't guarantee, but it likely doesn't; the component is purely a symbology representation - FNC1 is used to specify that a generic Code 128 barcode is specifically a GS1-128 barcode, so you would have to add the function code yourself.

> [@michael.ruel](#):
>
> Also how do you encode the functions in an Expression or script. I have to piece together several pieces of information and am wondering how to put in the ENTER function.

An enter key would likely be represented by a carriage return, line feed, or both - in both scripting and expressions, use the backslash character to start an 'escape sequence':  
Expressions:  
`{something} + "\n" + {somethingElse}`  
`{something} + "\r\n"`

Scripting:  
`"%s\n%s" % (event.source.something, event.source.somethingElse}`  
`event.source.something + "\r\n" + event.source.somethingElse`

---

<div class="post-metadata">

**Author:** ![michael.ruel](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@michael.ruel](https://forum.inductiveautomation.com/u/michael.ruel)\
**Post date:** [May 27, 2020, 9:00pm UTC](https://forum.inductiveautomation.com/t/barcode-component-encoding/34924/3 "2020-05-27T21:00:45Z")

</div>

Thanks for the reply however the expression doesn’t seem to like the escape character. I’m getting Scan Error: Illegal escape sequence “\x” (Line1, Char 9)

Here is the expression.  
“\<!\>1”+"\x1e"+“ACCEPT”+"\x1e"+“123456789”+"\x1e"+“ACCEPT”+"\x1e"+“ACCEPT”  
\x1e is the Record Seperator. Does ignition not like hex in the expression. I also tried the OCT \036, and Unicode u001e.

---

<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:** [May 27, 2020, 9:59pm UTC](https://forum.inductiveautomation.com/t/barcode-component-encoding/34924/4 "2020-05-27T21:59:35Z")

</div>

Expressions don’t like escape sequences for hex characters (TIL) and there’s no `chr()` function in expressions (yet), so your option to do it in an expression…is to use a script:  
`"test" + runScript("chr(0x1E)", 0) + "test"`  
Or, much more simply, just do it all directly in a script:

```python
fields = ["<!>1", "ACCEPT", "123456789", "ACCEPT", "ACCEPT"]
s = "\x1E".join(fields)
print repr(s)

```
