iQ-F – Conversion between a single STRING and an array of WORD values
This article contains GX Works3 function blocks for iQ-F CPU that allow the division of a single string into an array of WORD values and joining an array of WORD values into a single string.
Function blocks
These function blocks can be used to convert an array of numbers to one string with a specified separator or to convert a string with a specified separator to an array of numbers. An example of an application where this could be useful is exchanging multiple numerical values with another device over serial communication.
a) Array to string conversion
This block takes all the WORD values specified by wArray (up to wArrayLength) and converts them to one string (sResult) containing the numbers separated by sSeparator.
Input:
bEnable– signal to start the conversion [bit]
wArray– array of numbers [Word [Signed](0..4)]
sSeparator– separator of numbers in final string [String(32)]
wArrayLength– length of wArray [Word[Signed]] (maximum value is 5 by default)
Output:
sResult– result string [String(68)]
b) String to array conversion
This block takes the string specified by sString, searches it for separators based on sSeparator and divides the string into an array of WORD values (wArrayOutput).
Input:
bEnable– signal to start the conversion [bit]
sString– string which will be converted [String(68)]
sSeparator– separator of words in sString [String(32)]
Output:
wArrayOutput– array of numbers [Word [Signed](0..4)]
In both cases the size of WORD arrays is 5, it is possible to change the sizes of the arrays by changing local variables of function blocks.
The same situation with the output string, which is a String(68) variable by default. You can change it if you need to have a longer string than (68).
Conversion example
DOWNLOAD – String to array and array to string conversion function blocks
Original article for more downloads – Article