### SGSLP – Set, get, save and load parameters

Function Description
The SGSLP block is a special function block for manipulation with parameters of other function blocks in the REXYGEN system configuration. It works also in the Matlab-Simulink system but its scope is limited to the .mdl file it is included in.

The block can manage up to 16 parameter sets, which are numbered from 0 to 15. The number of parameter sets is given by the nps parameter and the active set is defined by the ips input. If the ips input remains unconnected, the active parameter set is $\mathtt{\text{ips}}=0$. Each set contains up to 16 different parameters defined by the string parameters sc0 to sc15. Thus the SGSLP block can work with a maximum of 256 parameters of the REXYGEN system. An empty sc$i$ string means that no parameter is specified, otherwise one of the following syntaxes is used:

1. <block>:<param> – Specifies one function block named block and its parameter param. The same block and parameter are used for all nps parameter sets in this case.
2. <block>:<param><sep><block>:<param> – This syntax allows the parameters to differ among the parameter sets. In general, each sc$i$ string can contain up to 16 items in the form <blok>:<param> separated by comma or semi-colon. E.g. the third item of these is active for $\mathtt{\text{ips}}=2$. There should be exactly nps items in each non-empty sc$i$ string. If there is less items than nps none of the below described operations can be executed on the incomplete parameter set.

It is recommended not to use both syntaxes in one SGSLP block, all 16 sc$i$ strings should have the same form. The first syntax is for example used when producing nps types of goods, where many parameters must be changed for each type of production. The second syntax is usually used for saving user-defined parameters to disk (see the SAVE operation below). In that case it is desirable to arrange automated switching of the ips input (e.g. using the ATMT block from the LOGIC library).

The broot parameter is suitable when all blocks whose parameters are to be controlled by the SGSLP block reside in the same subsystem or deeper in the hierarchy. It is inserted in front of each <block> substring in the sc$i$ parameters. The ’.’ character stands for the subsystem where the SGSLP block is located. No quotation marks are used to define the parameter, they are used here solely to highlight a single character. If the broot parameter is an empty string, all <block> items must contain full path. For example, to create a connection to the CNR block and its parameter ycn located in the same subsystem as the SGSLP block, $\mathtt{\text{broot}}=\mathtt{\text{.}}$ and $\mathtt{\text{sc0}}=\mathtt{\text{CNR:ycn}}$ must be set. Or it is possible to leave the broot parameter empty and put the ’.’ character to the sc0 string. See the GETPR or SETPR blocks description for more details about full paths in the REXYGEN system.

The SGSLP block executes one of the below described operations when a rising edge (off$\to$on) occurs at the input of the same name. The operations are:

SET – Sets the parameters of the corresponding parameter set ips to the values of the input signals u$i$. In case the parameter is successfully set, the same value is also sent to the y$i$ output.
GET – Gets the parameters of the corresponding parameter set ips. In case the parameter is successfully read, its value is sent to the y$i$ output.
SAVE – Saves the parameters of the corresponding parameter set ips to a file on the target platform. The parameters of the procedure and the format of the resulting file are described below.
LOAD – Loads the parameters of the corresponding parameter set ips from a file on the target platform. This operation is executed also during the initialization of the block but only when $\mathtt{\text{0}}\le \mathtt{\text{ips0}}\le \mathtt{\text{nps}}-1$. The parameters of the procedure and the format of the file are described below.

The LOAD and SAVE operations work with a file on the target platform. The name of the file is given by the fname parameter and the following rules:

• If no extension is specified in the fname parameter, the .rxs (ReX Status file) extension is added.
• A backup file is created when overwriting the file. The file name is preserved, only the extension is modified by adding the ’ ’ character right after the ’.’ (e.g. when no extension is specified, the backup file has a . rxs extension.
• The path is relative to the folder where the archives of the REXYGEN system are stored. The file should be located on a media which is not erased by system restart (flash drive or hard drive, not RAM).

The SAVE operation stores the data in a text file. Two lines are added for each parameter sc$i$, $i=0,\dots ,m$, where $m<16$ defines the nonempty sc$m$ string with the highest number. The lines have the form:

• "<block>:<param>", …, "<block>:<param>"
• <value>, …, <value>

There are nps individual items "<block>:<param>" which are separated by commas. The second line contains the same number of <value> items which contain the value of the parameter at the same position in the line above. Note that the format of the file remains the same even for sc$i$ containing only one <block>:<param> item (see the syntax no. 1 above). The "<block>:<param>" item is always listed nps-times in the file, which allows seamless switching of the sc$i$ parameters syntax without modifying the file.

Consider using the SILO block if working with only a few values.

Inputs

 u$i$ $i$-th analog input signal, $i=0,\dots ,15$ Double (F64) ips Parameter set index (numbered from zero) Long (I32) SET Set the parameters of the ips parameter set according to the values of the u$i$ inputs. The values can be found at the y$i$ outputs after a successful operation. Bool GET Get the parameters of the ips parameter set. The values can be found at the y$i$ outputs after a successful operation. Bool SAVE Save the ips parameter set to a file on the target device Bool LOAD Load the ips parameter set from a file on the target device Bool

Outputs

 y$i$ $i$-th analog output signal, $i=0,\dots ,15$ Double (F64) E Error flag Bool off .. No error on ... An error occurred (see iE) iE Error or warning code of the last operation Long (I32) 0 .... Operation successful 1 .... Fatal error of the Matlab system (only in Simulink), the block is no longer executed 2 .... Error opening the file for reading (LOAD operation) 3 .... Error opening the file for writing (SAVE operation) 4 .... Incorrect file format 5 .... The ips parameter set not found in the file 6 .... Parameter not found in the configuration, name mismatch (LOAD operation) 7 .... Unexpected end of file 8 .... Error writing to file (disk full?) 9 .... Parameter syntax error (the ’:’ character not found) 10 ... Only whitespace in the parameter name 11 ... Error creating the backup file 12 ... Error obtaining the parameter value by the GET operation (non-existing parameter?) 13 ... Error setting the parameter value by the SET operation (non-existing parameter?) 14 ... Timeout during obtaining/setting the parameter 15 ... The specified parameter is read-only 16 ... The ips parameter is out of range

Parameters

 nps Number of parameter sets  $↓$1 $↑$16 $\odot$1 Long (I32) ips0 Index of parameter set to load and set during the block initialization. No set is read for $\mathtt{\text{ips0}}<0$ or $\mathtt{\text{ips0}}\ge \mathtt{\text{nps}}$  $↓$-1 $↑$15 Long (I32) iprec Precision (number of digits) for storing the values of double type in a file  $↓$2 $↑$15 $\odot$12 Long (I32) icolw Requested column width in the status file. Spaces are appended to the parameter value when necessary.  $↓$0 $↑$22 Long (I32) fname Name of the file the SAVE and LOAD operations work with  $\odot$status String broot Root block in hierarchy, inserted at the beginning of all sc$i$ parameters, see the description above  $\odot$. String sc$i$ Strings defining the connection of u$i$ inputs and y$i$ outputs to the parameters, $i=0,\dots ,15$, see details above String

2020 © REX Controls s.r.o., www.rexygen.com