0

I have a python script where I am building a string one line at a time. I add the '\r\n' at the end of each line of a string with exception of the last line. This string gets written into a tag in Ignition SCADA. When I examine the contents of the tag, where the '\r\n' should have created the carriage return/new line all I have is a space (' ').

Any idea why this is behaving this way and what I can do to get the string to format correctly?

Thanks!

Edit: Here's the code:

myStr = ''
for i in range(1, 10):
    myStr += 'This is line ' + str(i) + '.\r\n'
resp = system.tag.write('myStrTag', myStr)
print myStr
MikeA
  • 65
  • 6
  • 2
    Show your code. – dfundako Jun 01 '18 at 15:47
  • It also depends on the Python version you are using. – mad_ Jun 01 '18 at 15:47
  • Are you sure that Ignition SCADA tags even allow multiline input? What happens if you insert "Hello,\r\nworld!" into a tag? – Kevin Jun 01 '18 at 15:49
  • I believe Ignition us currently using the 2.x version of python. Yes, string tags in Ignition "contain" the new line data because if I write the string tag contents to a file the new lines are there. Unfortunate I am NOT ultimately writing this data to a file, but writing it into a field in a database record. – MikeA Jun 01 '18 at 16:01

1 Answers1

0

Ignition is sanitizing the input for those string tags. You can't have multi-line strings but it "knows" you wanted to include that. So it's translating your input to a white space character rather than leaving it as the literal "\r\n". If you wanted to have that you could include two backslash characters.

myStr += 'This is line ' + str(i) + '.\\r\\n'

If you want the string to actually show up on screens as multiple lines you need to format it as an HTML string. That is the method that Ignition uses for storing and displaying strings with additional formatting. It actually works pretty well and can understand most HTML and CSS attributes. An example provided below.

myStr = '<html>'
for i in range(1, 10):
    myStr += 'This is line ' + str(i) + '<br>'
myStr += 'This is the final line' + '</html>'
resp = system.tag.write('[default]Development/String Testing', myStr)
print myStr