Functions
Chopper FUB
Combines ChopCompile and ChopRender to a single call in FUB format.
Direction | Name | Type | Description |
---|---|---|---|
In | pTemplate | Chop_Template_typ* | Where compiled data is stored |
In | pDest | STRING* | Pointer to destination where rendered string is written to |
In | destSize | STRING | Name of PV without task name to be used as action |
In | pSource | STRING | Name of PV to be used for parameters |
In | recompile | BOOL | Force a compile |
Out | renderLength | UDINT | Length of last render |
Out | status | DINT | Status of last fub call. Refer to status_information |
ChopCompile
ChopCompile does a compile from pSource into pTemplate. Returns function status as DINT. Refer to status for more information. Variables in source should be surrounded by double curly braces “{{”, “}}”, and should be specified in format TaskName:VarName for local variables and VarName for global variables. Only variables declared in .var files can be used by name. For more information variable formatting see section in usage. Chopper currently supports a maximum number of variables in a source denoted by constant CHOP_TEMPLATE_MAX_VARIABLES. Note: Due to current implementation maximum number of variables is 1 less than reported by CHOP_TEMPLATE_MAX_VARIABLES.
Direction | Name | Type | Description |
---|---|---|---|
Out | pTemplate | Chop_Template_typ* | Template to compile into |
In | pSource | STRING* | Template source to compile |
Return | status | DINT | Status of compile command refer to status_information |
Chopper Compiles can take an some time for larger sources. It is recommended to use caution when compiling in a fast cyclic.
variable.text:= 'Chopper';
source:= 'This is a {{var.text}} example!';
ChopCompile(ADR(template), ADR(source));
ChopRender
ChopRender does render from pTemplate into pDest. If renderLength is larger than destSize then a the pDest will end with ‘…’, followed by a null character. If pRenderLength is not 0 then it will be filled with renderLength.
Direction | Name | Type | Description |
---|---|---|---|
Out | pDest | STRING* | Destination to render template into |
In | pTemplate | Chop_Template_typ* | Template to render |
In | DestSize | UDINT | Sizeof pDest to prevent string overflow |
Out | pRenderLength | UDINT* | Pointer to be populated with the string length of pDest after rendering (Optional) |
Return | status | DINT | Status of render command refer to status_information |
Chopper Renders are quick when using a precompiled template and are okay to use in a fast cyclic.
variable.text:= 'Chopper';
source:= 'This is a {{var.text}} example!';
ChopCompile(ADR(template), ADR(source));
ChopRender(ADR(destination), ADR(template), SIZEOF(destination), ADR(length));
// destination = 'This is a Chopper example!'
// length = 26
NOTE: Any variable that can not be found is replaced with “undefined” when rendered.
ChopReplaceVar
ChopReplaceVar replaces all pTag in pTemplate with variable specified by name in pVarName. Variable name is in format TaskName:VarName for local variables and VarName for global variables.
Direction | Name | Type | Description |
---|---|---|---|
In/Out | pTemplate | Chop_Template_typ* | Template to be modified |
In | pTag | STRING* | Tag name to be replaced in template |
In | pVarName | STRING* | Variable name to be added |
Return | status | DINT | Status of last fn call refer to status_information |
firstVar:= 1;
secondVar:= 2;
ChopCompile(ADR(template), ADR('My variable value is {{firstVar}}'));
ChopRender(ADR(dest), ADR(template), SIZEOF(template), ADR(renderLength));
//dest= 'My variable value is 1'
ChopReplaceVar(ADR(template),ADR('firstVar'),ADR('secondVar'));
ChopRender(ADR(dest), ADR(template), SIZEOF(template), ADR(renderLength));
//dest= 'My variable value is 2'
ChopReplace
ChopReplace replaces all pTag in pTemplate with a new variable. Specified by address and type. Types are specified as VAR_TYPE_enum, refer to VarTools documentation for more information.
Direction | Name | Type | Description |
---|---|---|---|
In/Out | pTemplate | Chop_Template_typ* | Template to be modified |
In | pTag | STRING* | Tag name to be modified in template |
In | address | UDINT | Variable address to be added to pTag |
In | type | VAR_TYPE_enum | Variable type to be added to pTag |
Return | status | DINT | Status of last fn call refer to status_information |
firstVar:= 1;
secondVar:= 2;
ChopCompile(ADR(template), ADR('My variable value is {{firstVar}}'));
ChopRender(ADR(dest), ADR(template), SIZEOF(template), ADR(renderLength));
//dest= 'My variable value is 1'
ChopReplace(ADR(template),ADR('firstVar'),ADR(secondVar),VAR_TYPE_USINT);
ChopRender(ADR(dest), ADR(template), SIZEOF(template), ADR(renderLength));
//dest= 'My variable value is 2'
ChopGetErrorMsg
ChopGetErrorMsg retrieves text for given errorID and copies it to pDest. ChopGetErrorMsg returns a status.
Direction | Name | Type | Description |
---|---|---|---|
Out | pDest | STRING* | Destination to be populated |
In | maxDestLength | UDINT | Max length of pDest |
In | errorID | DINT | Status to get message for. See status_information |
Return | status | DINT | Status of last fn call refer to status_information |
ChopGetErrorMsg(ADR(msg), 50000);
// msg = Input to function is invalid