MikeA
MikeA

Reputation: 95

Strings in Python with \r\n not rendering carriage return line feed in SCADA tags

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

Upvotes: 0

Views: 948

Answers (1)

Chicken Max
Chicken Max

Reputation: 29

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

Upvotes: 0

Related Questions