# Eliminating Modbus Raw String Null Bits

**URL:** <https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802>\
**Category:** Ignition\
**Created:** [March 3, 2022, 5:49pm UTC](https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802 "2022-03-03T17:49:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Scovronski](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Samuel\_Scovronski](https://forum.inductiveautomation.com/u/Samuel_Scovronski)\
**Post date:** [March 3, 2022, 5:49pm UTC](https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802/1 "2022-03-03T17:49:33Z")

</div>

I am trying to read a string value from my device via Modbus. There are 20 addresses values listed to read the string (max of 20 characters). In order to read the string, I have to select the option to read the raw string (ignore null bits) and specify 40 addresses (instead of the 20) using a manually created Modbus address. This method results in a good string in Ignition, but when I try to save it to SQL it saves as an empty string due to the null bit.

Does anyone know how I can drop the null bits, or change the bit size when using the manual addressing with HRS so I do not get the null bits?

Thanks,  
Sam

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 3, 2022, 6:55pm UTC](https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802/2 "2022-03-03T18:55:17Z")

</div>

Share more details. You should get two characters per address with HRS.

---

<div class="post-metadata">

**Author:** ![Samuel\_Scovronski](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Samuel\_Scovronski](https://forum.inductiveautomation.com/u/Samuel_Scovronski)\
**Post date:** [March 3, 2022, 7:18pm UTC](https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802/3 "2022-03-03T19:18:14Z")

</div>

Hi pturmel,

The device’s manual states that I should read Modbus addresses 16886 to 16905, each address being a single character. However, when I try to read those addresses in Ignition it will return nothing unless I select the read raw strings option, indicating to me that the first byte is null. This is ok for use within Ignition, but when I try to save that same raw string value to SQL it shows up as an empty string.

The string value I am reading is nothing crazy, and I was able to successfully insert it in the MSSQL table manually. I am thinking I need to delete the null bytes before saving the string, but I am unsure how to do this in Ignition. I suppose I could use a script to drop all null values in my the strings character array?

Thanks,  
Sam

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 3, 2022, 7:18pm UTC](https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802/4 "2022-03-03T19:18:48Z")

</div>

> [@Samuel\_Scovronski](#):
>
> I suppose I could use a script to drop all null values in my the strings character array?

This is probably the approach you'll have to take.

---

<div class="post-metadata">

**Author:** ![Samuel\_Scovronski](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Samuel\_Scovronski](https://forum.inductiveautomation.com/u/Samuel_Scovronski)\
**Post date:** [March 3, 2022, 8:21pm UTC](https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802/5 "2022-03-03T20:21:18Z")

</div>

In case anyone else has this issue, here is the function I created to solve the problem.

def dropNull(char\_list):  
new\_str = “”  
for c in char\_list:  
if c != ‘\x00’:  
new\_str = new\_str + c  
return new\_str

---

<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:** [March 3, 2022, 8:23pm UTC](https://forum.inductiveautomation.com/t/eliminating-modbus-raw-string-null-bits/56802/6 "2022-03-03T20:23:49Z")

</div>

Pointless golfing:

```auto
def dropNull(characters):
	return "".join(char for char in characters if char != "\x00")

```

Should be faster and more efficient, since it doesn’t have to allocate a new string for each intermediate operation. Somewhat more inscrutable if you’re not used to Python, though.
