# Modbus TCP and SQLTag String

**URL:** <https://forum.inductiveautomation.com/t/modbus-tcp-and-sqltag-string/7485>\
**Category:** Ignition\
**Created:** [October 29, 2013, 7:31am UTC](https://forum.inductiveautomation.com/t/modbus-tcp-and-sqltag-string/7485 "2013-10-29T07:31:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnguyen](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gnguyen](https://forum.inductiveautomation.com/u/gnguyen)\
**Post date:** [October 29, 2013, 7:31am UTC](https://forum.inductiveautomation.com/t/modbus-tcp-and-sqltag-string/7485/1 "2013-10-29T07:31:38Z")

</div>

Hi,

A SQLTag, string type, 20 char. long, ex. HRS1:20. When you write it, let say ‘1234’, so less than the 20 maxi. char, the empty char are replaced by space (x20), not null (x00), causing some difficulties to my plc.  
It’s the first time I see this behavior, is it normal ?

Ignition 7.6.3 (b2013090513)

Thank you

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [December 26, 2013, 9:51pm UTC](https://forum.inductiveautomation.com/t/modbus-tcp-and-sqltag-string/7485/2 "2013-12-26T21:51:49Z")

</div>

I had to check with the developers on this one, and it is supposed to write spaces. If you really need it to be nulls (0x00) then you’ll have to create the ascii string through scripting. You could even make a function out of it so you could use it all over the place. IE:[code]def padNulls(var):  
# pad with 20 0x00’s  
for i in range(20):  
var = var+chr(0)  
# return the first 20 characters  
return var[:20]

print padNulls(“1234”)[/code]

---

<div class="post-metadata">

**Author:** ![gnguyen](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gnguyen](https://forum.inductiveautomation.com/u/gnguyen)\
**Post date:** [January 6, 2014, 6:58am UTC](https://forum.inductiveautomation.com/t/modbus-tcp-and-sqltag-string/7485/3 "2014-01-06T06:58:04Z")

</div>

Thank you. I’ll test it asap.

Best wishes for 2014.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [August 6, 2019, 7:20pm UTC](https://forum.inductiveautomation.com/t/modbus-tcp-and-sqltag-string/7485/4 "2019-08-06T19:20:39Z")

</div>

I just ran into this issue writing string values to a Modicon device. One-liner to right pad the string with nulls (replace 12 with Modbus string length):

```python
system.tag.writeAsync([tagPath], [value.ljust(12, chr(0))])

```
