iQ-F - Conversion between single STRING and array of WORD values

iQ-F - Conversion between single STRING and array of WORD values

This article contains GX Works3 function blocks for iQ-F CPU that that allow 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 specified separator or to convert string with specified separator to an array of numbers. An example of 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 by default a String(68) variable. If you need to have a longer string than (68) you can change it.


Conversion example