String functions
Application
The string functions allow you to define and process strings using QS parameters (e.g., in order to create variable logs with FN 16: F-PRINT). In computing, a string designates an alphanumerical sequence of characters.
Related topics
- Ranges of variables
Description of function
You can assign up to 255 characters to a QS parameter.
The following characters are permitted within QS parameters:
- Characters
- Numbers
- Special characters, for example ?
- Control characters, for example \ for paths
- Spaces
The values of QS parameters can be processed or checked with the Formula Q/QL/QR and String formula QS NC functions.
Syntax | NC function | Higher-level NC function |
---|---|---|
DECLARE STRING | Assign an alphanumeric value to a QS parameter | |
STRING FORMULA | Concatenate contents of QS parameters and assign them to a QS parameter | String formula QS |
TONUMB | Convert the alphanumeric value of a QS parameter to a numerical value and assign it to a Q, QL, or QR parameter | Formula Q/QL/QR |
TOCHAR | Convert a numerical value to an alphanumeric value and assign it to a QS parameter | String formula QS |
SUBSTR | Copy a substring from a QS parameter and assign it to a QS parameter | String formula QS |
SYSSTR | Read system data and assign the contents to a QS parameter | String formula QS |
INSTR | Search for a substring in a QS parameter and assign the retrieved characters to a Q, QL, or QS parameter | Formula Q/QL/QR |
STRLEN | Determine the string length of a QS parameter and assign it to a Q, QL, or QR parameter Determining the number of characters in QS parameter contents | Formula Q/QL/QR |
STRCOMP | Compare QS parameters in ascending lexical order and assign the result to a Q, QL, or QR parameter | Formula Q/QL/QR |
CFGREAD | Read the content of a machine parameter and assign it to a QS parameter |
|
The control provides the following options to enter formulas:
- Auto-complete
- Pop-up keyboard for formula input from the action bar or from within the form
- Formula input mode of the virtual keyboard
Read system data with SYSSTR
With the SYSSTR NC function, you can read system data and save the contents in QS parameters. Select the system datum by means of a group number (ID) and a number (NR).
Optionally, you can enter IDX and DAT.
You can read the following system data:
Group name, ID no. | Number | Meaning |
---|---|---|
Program information, 10010 | 1 | Path of the current main program or pallet program |
2 | Path of the currently executed NC program | |
3 | Path of the NC program selected with Cycle 12 PGM CALL | |
10 | Path of the NC program selected with SEL PGM | |
Channel data, 10025 | 1 | Name of the current channel (e.g., CH_NC) |
Values programmed in the tool call, 10060 | 1 | Current tool name Tip The NC function saves the tool name only if the tool has been called using its tool name. |
Current system time, 10321 | 1 to 16, 20 |
|
Touch-probe data, 10350 | 50 | Type of the active TS workpiece touch probe |
70 | Type of the active TT tool touch probe | |
73 | Name of the active TT workpiece touch probe from the activeTT machine parameter | |
Data for pallet machining, 10510 | 1 | Name of the pallet being machined |
2 | Path of the currently selected pallet table | |
NC software version, 10630 | 10 | Number of the NC software version |
Tool data, 10950 | 1 | Current tool name |
2 | Content of the DOC column of the current tool | |
3 | AFC control settings of the current tool | |
4 | Tool-carrier kinematics of the current tool |
Reading machine parameters with CFGREAD
With the CFGREAD NC function, you can read out machine parameter contents of the control as numerical or alphanumeric values. The read-out numerical values are always given in metric form.
To read a machine parameter, you need to determine the following contents in the configuration editor of the control:
Icon | Type | Meaning |
---|---|---|
Key | Group name of the machine parameter The group name can be specified optionally | |
Entity | Parameter object The name always begins with Cfg | |
Attribute | Name of the machine parameter | |
Index | List index of the machine parameter The list index can be specified optionally |
You can change the display of the existing parameters in the configuration editor for the machine parameter. By default, the parameters are displayed with short, explanatory texts.
Each time you want to read out a machine parameter with the CFGREAD NC function, you must first define a QS parameter with attribute, entity and key.
Assigning an alphanumeric value to a QS parameter
Before you can use and process alphanumeric values, you need to assign characters to the QS parameters. Use the DECLARE STRING command to do so.
To assign an alphanumeric value to a QS parameter: | ||
| ||
| ||
|
In this example, the control assigns an alphanumeric value to the QS parameter QS10.
11 DECLARE STRING QS10 = "workpiece" | ; Assign alphanumeric value to QS10 |
Concatenation of alphanumeric values
With the || concatenation operator, you can concatenate the contents of multiple QS parameters. This allows you to combine fixed and variable alphanumeric values.
To concatenate the contents of multiple QS parameters: | ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
|
In this example, the control concatenates the contents of the QS parameters QS12 and QS13. The alphanumeric value is assigned to the QS parameter QS10.
11 QS10 = QS12 || QS13 | ; Concatenate contents of QS12 and QS13 and assign them to the QS parameter QS10 |
Parameter contents:
- QS12: Status:
- QS13: Scrap
- QS10: Status: Scrap
Converting alphanumeric values to numerical values
With the TONUMB NC function, you save exclusively numeric characters from a QS parameter to a different variable type. Then, you can use these values in calculations.
In this example, the control converts the alphanumeric value of the QS parameter QS11 to a numerical value. This value is assigned to the Q parameter Q82.
11 Q82 = TONUMB ( SRC_QS11 ) | ; Convert alphanumeric value from QS11 to a numerical value and assign it to Q82 |
Converting numerical values to alphanumeric values
With the TOCHAR NC function, you can save the content of a variable in a QS parameter. The saved content can, for example, be concatenated with other QS parameters.
In this example, the control converts the numerical value of the Q parameter Q50 to an alphanumeric value. The control assigns this value to the QS parameter QS11.
11 QS11 = TOCHAR ( DAT+Q50 DECIMALS3 ) | ; Convert a numerical value from Q50 to an alphanumeric value and assign it to the QS parameter QS11 |
Copying a substring from a QS parameter
With the SUBSTR NC function, you can save a defined substring from a QS parameter to another QS parameter. For example, you can use this NC function to extract the file name from an absolute file path.
In this example, the control saves a substring of the QS parameter QS10 to the QS parameter QS13. Using the BEG2 syntax element, you define that the control ignores the first two characters and starts copying from the third character. With the LEN4 syntax element, you define that the control copies the next four characters.
11 QS13 = SUBSTR ( SRC_QS10 BEG2 LEN4 ) | ; Assign substring from QS10 to the QS parameter QS13 |
Searching for a substring within QS parameter contents
With the INSTR NC function , you can check whether a particular substring is contained within a QS parameter. This allows you to determine, for example, whether the concatenation of multiple QS parameters was successful. For the check, you must indicate two QS parameters. The control searches the first QS parameter for the content of the second QS parameter.
If the substring is found, the control saves the number of characters until it reaches the occurrence of the substring in the result parameter. If multiple occurrences are found, the result is identical because the control saves the first one.
If the substring searched for is not found, the control saves the total number of characters in the result parameter.
In this example, the control searches the QS parameter QS10 for the string saved in QS13. The search starts from the third character. When counting the characters, the control starts from zero. The control assigns the occurrence to the Q parameter Q50 as a number of characters.
37 Q50 = INSTR ( SRC_QS10 SEA_QS13 BEG2 ) | ; Search QS10 for substring from QS13 |
Determining the number of characters in QS parameter contents
The STRLEN NC function determines the number of characters in QS parameter contents. With this NC function, you can, for example, determine the length of a file path.
If the selected QS parameter has not been defined, the control returns the value -1.
In this example, the control determines the number of characters in the QS parameter QS15. The numerical value of the number of characters is assigned to the Q parameter Q52.
11 Q52 = STRLEN ( SRC_QS15 ) | ; Determine the number of characters in QS15 and assign it to Q52 |
Comparing the lexical order of two alphanumerical strings
With the STRCOMP NC function, you can compare the lexical order of the content of two QS parameters.
The control returns the following results:
- 0: The content of the two parameters is identical
- -1: In the lexical order, the content of the first QS parameter comes before the content of the second QS parameter
- +1: In the lexical order, the content of the first QS parameter comes after the content of the second QS parameter
The lexical order is as follows:
- Special characters (e.g., ?_)
- Numerals (e.g., 123)
- Uppercase letters (e.g., ABC)
- Lowercase letters (e.g., abc)
Starting from the first character, the control proceeds until the contents of the QS parameters differ from each other. If the contents differ starting from, for example, the fourth digit, the control aborts the check at this point.
Shorter contents with identical strings are displayed first in the order (e.g., abc before abcd).
In this example, the control compares the lexical order of QS12 and QS14. The result is assigned to the Q parameter Q52 as a numerical value.
11 Q52 = STRCOMP ( SRC_QS12 SEA_QS14 ) | ; Compare the lexical order of the values of QS12 and QS14 |
Accepting the contents of a machine parameter
Depending on the content of the machine parameter, you can use the CFGREAD NC function to take over alphanumeric values to QS parameters or numerical values to Q, QL or QR parameters.
In this example, the control saves the overlap factor from the pocketOverlap machine parameter as a numerical value in a Q parameter.
Specified settings in the machine parameters:
- ChannelSettings
- CH_NC
- CfgGeoCycle
- pocketOverlap
11 QS11 = "CH_NC" | ; Assign the key to the QS parameter QS11 |
12 QS12 = "CfgGeoCycle" | ; Assign the entity to the QS parameter QS12 |
13 QS13 = "pocketOverlap" | ; Assign the attribute to the QS parameter QS13 |
14 Q50 = CFGREAD( KEY_QS11 TAG_QS12 ATR_QS13 ) | Read out the contents of the machine parameter |
The CFGREAD NC function contains the following syntax elements:
- KEY_QS: Group name (key) of the machine parameter
- Tip
It no group name is available, define a blank value for the corresponding QS parameter.
- TAG_QS: Object name (entity) of the machine parameter
- ATR_QS: Name (attribute) of the machine parameter
- IDX: Index of the machine parameter
Note
If you use the String Formula QS NC function, the result is always an alphanumeric value. If you use the Formula Q/QL/QR NC function, the result is always a numerical value.