# How to handle modbus decimal to string

**URL:** <https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524>\
**Category:** Ignition\
**Created:** [November 6, 2013, 4:15am UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524 "2013-11-06T04:15:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![getabc](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@getabc](https://forum.inductiveautomation.com/u/getabc)\
**Post date:** [November 6, 2013, 4:15am UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/1 "2013-11-06T04:15:30Z")

</div>

Hi Team,

Created another modbus query to retrieve the software version running on the device.

![](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2f0984456f8dd47c5beb0a68b72c3d6cf62ef2aa.jpeg)

The decimal values returned are as follows,  
50 46 48 51 70 50 50

Converted to ASCII would represent the following,  
2 . 0 3 F 2 2

How do I, firstly get it converted and secondly in a usable string format for IA designer?

Thanks again!

Andrew

---

<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 6, 2013, 12:02pm UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/2 "2013-11-06T12:02:23Z")

</div>

Strings are a bit tricky. There no good way to do it from the browsable tags (well, there is, but it’s really tedious 😒 ). You can however directly set up a MODBUS string directly from within the SQLTag.

Example: [DeviceName]HRS1024:20 Read 20 character string value starting at Holding Register 1024.

In your case, it would be closer to: [DeviceName]HRS1:7

Use this format in place of the browsable name you would normally use.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![getabc](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@getabc](https://forum.inductiveautomation.com/u/getabc)\
**Post date:** [November 8, 2013, 6:00am UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/3 "2013-11-08T06:00:56Z")

</div>

Hi Jordan,

I’ve been racking my brain trying to figure out how to add the SQLTag … _urgh_ ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

Would I be adding it using the SQL Tag Browser in Ignition designer or somewhere is the configuration section?

YELP!

-AC

---

<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 8, 2013, 4:33pm UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/4 "2013-11-08T16:33:00Z")

</div>

> [@getabc](#):
>
> Would I be adding it using the SQL Tag Browser in Ignition designer or somewhere is the configuration section?

Yep! Add the tag using the SQLTag Browser in the Designer. Here's an example of directly addressing in MODBUS:  
[attachment=0]11-8-2013 11-28-15 AM.png[/attachment]

Note how my item is configured in the OPC Item Path.

---

<div class="post-metadata">

**Author:** ![getabc](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@getabc](https://forum.inductiveautomation.com/u/getabc)\
**Post date:** [November 10, 2013, 11:51pm UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/5 "2013-11-10T23:51:33Z")

</div>

Hi Jordan,

Fantastic - thank you for explaining that to me …

Now, when I use [Emerson]1.IR1 it returns 50, but when I use [Emerson]1.HRS1 it returns no value.

[Emerson]1.HRS1:7 also returns no value …

Any ideas?

Andrew

---

<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 11, 2013, 6:15pm UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/6 "2013-11-11T18:15:10Z")

</div>

Did you set your datatype to string?

---

<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 11, 2013, 6:37pm UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/7 "2013-11-11T18:37:37Z")

</div>

Something that just occurred to me. I don’t think it’s going to work. 16-bit registers will hold two characters of ASCII data. Each register you show has one character data in it. the High byte would be null, which would certainly explain the ‘no value’ that you’re getting.

Don’t get me wrong. If I’m pleasantly surprised and it works without issue, then great! Otherwise, it gets a little more involved:

Solution forthcoming. Stay tuned… 😆

---

<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 11, 2013, 7:45pm UTC](https://forum.inductiveautomation.com/t/how-to-handle-modbus-decimal-to-string/7524/8 "2013-11-11T19:45:31Z")

</div>

OK, here goes…

I set up some tags to simulate the incoming OPC values: SW\_Ver (1) through SW\_Ver (7)

[attachment=0]11-11-2013 2-30-45 PM.png[/attachment]

Then I set this code into a gateway Timer Script running every second for testing. Really, you could probably set it to a lot longer if the value isn’t going to change often.

[code]#List of tags to Read  
tags=[‘Test/SW\_Ver/SW\_Ver (1)’,‘Test/SW\_Ver/SW\_Ver (2)’,‘Test/SW\_Ver/SW\_Ver (3)’,‘Test/SW\_Ver/SW\_Ver (4)’,‘Test/SW\_Ver/SW\_Ver (5)’,‘Test/SW\_Ver/SW\_Ver (6)’,‘Test/SW\_Ver/SW\_Ver (7)’]

#Grab Values of the Tags  
values=system.tag.getTagValues(tags)

#Create an empty string  
SW\_Version\_String=’’

for i in range(len(tags)):  
#Concatenate the ASCII values together  
SW\_Version\_String+=chr(values[i])

#Write final concatenated value out to a tag  
system.tag.writeToTag(‘Test/SW\_Ver/SW\_Ver’,SW\_Version\_String)[/code]

One thing to note: I’m running 7.2 and the function names have changed a bit. Even though they’re deprecated, they’ll probably still work. But you should make the following changes:

system.tag.getTagValues ➡ system.tag.readAll  
system.tag.writeToTag ➡ system.tag.write
