Printing a Tag Value

If someone could help point me in a direction, it would be much appreciated.

What I am running into is when

print '\02Telegram Type=Job\nJob ID=1\nRecipe Name=Standard Recipe\nProduct Serial Number=0815sub\03'

I get the result I’m looking for, which is

Telegram Type=Job
Job ID=1
Recipe Name=Standard Recipe
Product Serial Number=0815sub

When I try this

tag_path = "[default]ASTUData"

results = system.tag.readBlocking([tag_path])

print str(results[0].value)

With a result of

'\02Telegram Type=Job\nJob ID=1\nRecipe Name=Standard Recipe\nProduct Serial Number=0815sub\03'

Is there different function I need to be using for the tag information to have the same print result as the plain text?

How are you putting the String value into the tag in the first place?

You’ll need to write it from scripting instead. You can’t type control characters into that text box.

I am very new to this platform, do you have an example or possibly elaborate. What will eventually happen is the information of this tag will be changing from a data base.

So you can get the full picture,

from java.net import Socket
from java.io import PrintWriter, BufferedReader, InputStreamReader, OutputStreamWriter
from java.lang import Exception
import sys

def send_and_receive_multi_line(ip_address, port, message_to_send):
    socket = None
    reader = None
    writer = None
    response_lines = []

    try:
        # 1. Establish connection and set a timeout
        socket = Socket(ip_address, port)
        socket.setSoTimeout(5000) # Timeout in milliseconds (e.g., 5 seconds)

        # 2. Get input and output streams and wrap them with Reader/Writer
        writer = PrintWriter(OutputStreamWriter(socket.getOutputStream(), "UTF-8"), True)
        reader = BufferedReader(InputStreamReader(socket.getInputStream(), "UTF-8"))

        # 3. Send the single-line message with a line terminator
        # The `println` method automatically adds a newline character
        writer.println(message_to_send)
        # Flush the stream to ensure data is sent immediately
        writer.flush()

        # 4. Read the multi-line response
        # The loop will read line by line until `reader.readLine()` returns None,
        # which indicates the end of the stream or the socket is closed by the server.
        # This approach works best if the server closes the connection after sending the full response.
        line = reader.readLine()
        while line is not None:
            response_lines.append(line)
            line = reader.readLine()

    except Exception as e:
        print "Socket Error: %s" % e
        # Handle specific exceptions as needed (e.g., timeout, connection refused)
    finally:
        # 5. Ensure resources are closed
        if writer:
            writer.close()
        if reader:
            reader.close()
        if socket:
            socket.close()

    return "\n".join(response_lines)

# --- Example Usage ---
# Replace with your server's IP and Port
server_ip = "192.168.10.102" 
server_port = 502
# Ensure your message ends with a terminator if the server expects a specific one.
# PrintWriter.println handles standard terminators.
message = "\02Telegram Type=Job\nJob ID=1\nRecipe Name=Standard Recipe\nProduct Serial Number=0815sub\03" 

# Call the function
response = send_and_receive_multi_line(server_ip, server_port, message)

if response:
    print "Received response:"
    print response
else:
    print "No response or an error occurred."

This is what I have found that works, where you see

message = "\02Telegram Type=Job\nJob ID=1\nRecipe Name=Standard Recipe\nProduct Serial Number=0815sub\03" 

I am needing to replace the static text with a tag which will change every time the script is ran.

Don't use a tag, use a PrepQuery, since the value will be coming from a database.

Something like this:

tag_path = "[default]ASTUData"
value = '\02Telegram Type=Job\nJob ID=1\nRecipe Name=Standard Recipe\nProduct Serial Number=0815sub\03'

system.tag.writeBlocking([tag_path], [value])

I have been searching around and this solved my issue

data = "[default]ASTUData"

results = system.tag.readBlocking([data])

raw_val = results[0].value

process = raw_val.replace('\\n', '\n').replace('\\02', '\02').replace('\\03', '\03')

Thank you everyone for you help.