strTemplateGenerateString (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

ALL

Firmware version:

2.10.00


strTemplateGenerateString generates a new dynamic string from the template, using the current value of the variables.

 

 

Input:

st: SYSHANDLE

A handle to the string template.

 

Output:

str : STRING

The generated string.

 

Returns: INT

1

- Success

0

- Function is not supported.

-1

- Invalid handle.

-2

- Template is not ready.

-3

- Not enough resources to create string.

 

 

 

Declaration:

FUNCTION strTemplateGenerateString;
VAR_INPUT
  st       : SYSHANDLE;
  str     : ACCESS STRING;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
 
PROGRAM test;
VAR
  st       : SYSHANDLE;
  rc       : INT;
  str_in   : STRING;
  str_out  : STRING;
END_VAR;
 
  str_in := "Time since reset: $${time}, Temperature: $${temp}, Values: $"$${time}, $${temp}, $${value}$"";
 
  // Parse string and create template.
  rc := strTemplateCreate(st:=st, str:=str_in, sov := "$${", eov := "}");
  DebugFmt(message:="strTemplateCreate: \1", v1:=rc);
 
  // Set the value for the fixed variable
  rc := strTemplateSetVar(st:=st, name:="value", value := "value");
  DebugFmt(message:="strTemplateSetVar: \1", v1:=rc);
 
BEGIN
  // Set the value for the dynamic variables
  rc := strTemplateSetVar(st:=st, name:="time", value:=dintToStr(v:=boardTimeSinceReset()/1000));
  DebugFmt(message:="strTemplateSetVar: \1", v1:=rc);
 
  rc := strTemplateSetVar(st:=st, name:="temp", value:=floatToStr(v:=FLOAT(boardTemperature())/100.0));
  DebugFmt(message:="strTemplateSetVar: \1", v1:=rc);
 
  // Generate string
  rc := strTemplateGenerateString(st:=st, str:=str_out);
  DebugFmt(message:="strTemplateGenerateString: \1", v1:=rc);
 
  // Print string to device output
  DebugMsg(message:=str_out);
 
  Sleep(delay:=10000);
END;
 
END_PROGRAM;