# Converting String to Ascii for DataLogic Scanner

**URL:** https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599
**Category:** General
**Created:** [9 March 2022 14:54 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599 "2022-03-09T14:54:34Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 14:54 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/1 "2022-03-09T14:54:34Z")

</div>

I have a DataLogix Scanner and I am using TCP/IP node to read barcode data from the scanner and trigger the scanner at IP and Port 51240. This is working fine but according to the manufacture you use port 1023 for changing what saved configuration on the scanner you want to use and same port for "Entering Host Mode" which allows you to change the configuration file used. The problem is this requires Ascii commands with string values for file name of the config file on the scanner I want to change and this is not working for me.  
[flows (5).json](https://discourse.nodered.org/uploads/short-url/wZq04w6OPIbgjDsyLP7xplAH6Bw.json) (3.4 KB)

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 14:56 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/2 "2022-03-09T14:56:31Z")

</div>

Here is the instructions from the manufacture for changing the config file that is saved in the scanner memory you want to change to.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/14fd20cb19bdd05e64225a98f7367401320545b6.png)

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 14:58 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/3 "2022-03-09T14:58:26Z")

</div>

here is the instructions on getting the scanner into host mode in order to change configurations files i want to use

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b52b998a658cd44ca07e6c1fb07fe700481a005b.png)

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 15:02 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/4 "2022-03-09T15:02:25Z")

</div>

Its not working and I am not getting a rely like the instructions say I should.

I am not sure how to send these Ascii commands that the scanner is looking for. Any ideas on what I am doing wrong?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 March 2022 15:25 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/5 "2022-03-09T15:25:03Z")

</div>

> [@jts450](#):
>
> Any ideas on what I am doing wrong?

You dont actually send ESC and `<LF>` ...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8c33729a2d374462c2f86ffdfb02c35069ca432.png)

... you should be sending the ASCII equivalent codes

also, as the device is supposed to respond, you should use the TCP Request node, like this...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8b5e0b2f2fd57142fdc047fdcd9a051bab862d49.png)

☝ 100% untested - but should get you closer to a solution

Demo Flow...

```auto
[{"id":"f47c01500424c2da","type":"debug","z":"7c13b8452619581b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1398,"y":1024,"wires":[]},{"id":"79dd3d36b4c1d8a1","type":"tcp in","z":"7c13b8452619581b","name":"","server":"client","host":"192.168.1.50","port":"51240","datamode":"stream","datatype":"utf8","newline":"","topic":"","base64":false,"tls":"","x":1140,"y":1024,"wires":[["f47c01500424c2da"]]},{"id":"d1f99ee1e6c3b126","type":"inject","z":"7c13b8452619581b","name":"A: Exit Host Mode","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"A","payloadType":"str","x":922,"y":768,"wires":[["ef2cd4b1e7de0fc3"]]},{"id":"ef2cd4b1e7de0fc3","type":"function","z":"7c13b8452619581b","name":"Generate MODE command","func":"//A == Exit Host Mode\n//B == Enter Programming Mode\n//C == Enter Host Mode\n\n\nconst ESC = '\\x1B';\nconst MODE = \"A\"; //A == Exit Host Mode\nmsg.payload = `${ESC}[${MODE}`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1192,"y":768,"wires":[["94e0163bdde35c75"]]},{"id":"bce4cad9ea51bfb3","type":"inject","z":"7c13b8452619581b","name":"B: Enter Programming Mode","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"B","payloadType":"str","x":888,"y":800,"wires":[["ef2cd4b1e7de0fc3"]]},{"id":"e7eacbeafbae0d4f","type":"inject","z":"7c13b8452619581b","name":"C: Enter Host Mode","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"C","payloadType":"str","x":922,"y":832,"wires":[["ef2cd4b1e7de0fc3"]]},{"id":"94e0163bdde35c75","type":"tcp request","z":"7c13b8452619581b","name":"","server":"192.168.1.50","port":"1023","out":"time","ret":"buffer","splitc":"0","newline":"","tls":"","x":1372,"y":832,"wires":[["94892378cca31021"]]},{"id":"94892378cca31021","type":"debug","z":"7c13b8452619581b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1402,"y":880,"wires":[]},{"id":"5adef4ee2d63b1b8","type":"inject","z":"7c13b8452619581b","name":"Change Scanner to Config1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"CHANGE_CFG Config1","payloadType":"str","x":904,"y":896,"wires":[["721a64f983d3a9e5"]]},{"id":"721a64f983d3a9e5","type":"function","z":"7c13b8452619581b","name":"Add LF","func":"// \\n is the escape code for a new line (LF) in JS\n// \\r is the escape code for a carraige return (CR) in JS\nmsg.payload = `${msg.payload}\\n`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1132,"y":896,"wires":[["94e0163bdde35c75"]]},{"id":"8b2ecb1161cadae9","type":"inject","z":"7c13b8452619581b","name":"Trigger Scan","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"T","payloadType":"str","x":954,"y":976,"wires":[["1bcf0218d03d5834"]]},{"id":"1bcf0218d03d5834","type":"tcp out","z":"7c13b8452619581b","name":"","host":"192.168.1.50","port":"51240","beserver":"client","base64":false,"end":false,"tls":"","x":1354,"y":976,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 15:47 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/6 "2022-03-09T15:47:12Z")

</div>

Thank you, I will give it a try

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 18:07 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/7 "2022-03-09T18:07:08Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5395366e3668457c28a724421f89483542ebfed7.png)

Still not getting a response even though its connected

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 March 2022 18:51 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/8 "2022-03-09T18:51:04Z")

</div>

Add a debug to the output of "Generate MODE command" and "Add LF"  
Check the debug sidebar - do they look correct?

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 20:52 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/9 "2022-03-09T20:52:09Z")

</div>

Like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4fc191333a0889d4cd5d91d162691e6c7b2a1bf.png)

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 20:54 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/10 "2022-03-09T20:54:28Z")

</div>

it looks correct for the LF

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4fc191333a0889d4cd5d91d162691e6c7b2a1bf.png)

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 20:56 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/11 "2022-03-09T20:56:02Z")

</div>

Opps wrong snip, Here is the debug for the LF

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/56a6bd280e5ed706043c77072a096297760eaf54.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 March 2022 21:09 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/12 "2022-03-09T21:09:23Z")

</div>

In your screenshots, dont you see the "A" in every one of the commands? Doesnt that make you think there is a problem with the flow?

In the function `Generate MODE command` change the line...

```auto
const MODE = "A"; //A == Exit Host Mode

```

... to ...

```auto
const MODE = msg.payload; 

```

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 21:53 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/13 "2022-03-09T21:53:25Z")

</div>

Yes I have to look at the function node to see why the B or C are not showing up when injected but I am not sure how to get the ascii ESC to show up instead of the ? mark.

Thank you.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 March 2022 22:12 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/14 "2022-03-09T22:12:20Z")

</div>

> [@jts450](#):
>
> but I am not sure how to get the ascii ESC to show up instead of the ? mark.

ESC is a non printable character.

If you want to be certain the correct ASCII codes are being generated, convert the string to a buffer in the function by adding `msg.payload=Buffer.from(msg.payload, 'utf8')` just before `return msg`

In the debug you will see a buffer with 3 values. The are the ASCII values of `ESC [ A` (refer to an online ASCII table for the values)

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 23:16 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/15 "2022-03-09T23:16:02Z")

</div>

I changed msg.payload; and now see the other letters but I'm a little confused here.. what is 'utf8" for and in the Generate Mode function node what does line 6 do, const ESC = '\x1B'; ?

in the ASCII table I am looking at the Decimal value for ESC is 27 but should I even be looking at decimal conversion?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [9 March 2022 23:24 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/16 "2022-03-09T23:24:25Z")

</div>

> [@jts450](#):
>
> const ESC = '\x1B

Hexadecimal 1B is decimal 27

> [@jts450](#):
>
> what is 'utf8"

[https://gprivate.com/5yjgn](https://gprivate.com/5yjgn)

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [9 March 2022 23:35 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/17 "2022-03-09T23:35:19Z")

</div>

lol...sorry total newb here. Ill see if I can figure it out.

Thanks

---

<div class="post-metadata">

### Author: ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)
#### Post date: [10 March 2022 16:33 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/18 "2022-03-10T16:33:57Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d20b588e266aa5a47771594529e87f1b33bd8557.png)

Got it working  
Thank you Steve for your help!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [9 May 2022 16:34 UTC](https://discourse.nodered.org/t/converting-string-to-ascii-for-datalogic-scanner/59599/19 "2022-05-09T16:34:29Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
