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?
Share more details. You should get two characters per address with HRS.
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?
This is probably the approach you’ll have to take.
In case anyone else has this issue, here is the function I created to solve the problem.
new_str = “”
for c in char_list:
if c != ‘\x00’:
new_str = new_str + c
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.