32 lines
920 B
GDScript
32 lines
920 B
GDScript
class_name Utils
|
|
extends Node
|
|
|
|
static func read_string(tag_group_name: String, base_tag_name: String) -> String:
|
|
"""Reads the log string from PLC DATA array"""
|
|
var result = ""
|
|
|
|
# Construct the length and data tag names
|
|
var len_tag = base_tag_name + ".LEN"
|
|
var data_tag = base_tag_name + ".DATA"
|
|
|
|
# Read the actual string length from PLC (if available)
|
|
var string_length = OIPComms.read_int32(tag_group_name, len_tag)
|
|
|
|
# Limit to 82 max and ensure it's valid
|
|
if string_length <= 0 or string_length > 82:
|
|
string_length = 82
|
|
|
|
# Read each character
|
|
for i in range(string_length):
|
|
var data_tag_indexed = data_tag + "[" + str(i) + "]"
|
|
var char_value = OIPComms.read_int8(tag_group_name, data_tag_indexed)
|
|
|
|
# Check for null terminator or invalid ASCII
|
|
|
|
|
|
# Convert SINT to ASCII character
|
|
if char_value > 0 and char_value < 128: # Valid ASCII range
|
|
result += char(char_value)
|
|
|
|
return result
|