# LGF_StartValueReadWrite (FB / 1.0.0)

Overview

Author: Simatic Systems Support

## Short description

Read or write start value(s) from variables or complete data blocks

### Block Interface

| LGF_StartValueReadWrite (FB) |
--- | --- | ---
Bool |  |  | read |  | readDone |  |  | Bool
Bool |  |  | write |  | writeDone |  |  | Bool
Variant |  |  | dataSource |  | busy |  |  | Bool
Variant |  |  | dataDestination |  | error |  |  | Bool
|  |  |  |  | lastRead |  |  | DTL
|  |  |  |  | lastWrite |  |  | DTL
|  |  |  |  | status |  |  | Word
|  |  |  |  | diagnostics |  |  | LGF_typeDiagnostics

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
read | Bool | FALSE | Rising edge: Read start value of data block / Variable of data block
write | Bool | FALSE | Rising edge: Write actual value(s) to start value of data block / Variable of data block
dataSource | Variant | --- | Data (block / variable) source, if a separate source is needed. May also be `NULL` - then the target is also used as the source
dataDestination | Variant | --- | Data (block / variable) destination

### Output parameter

Identifier | Data type | Description
--- | --- | ---
readDone | Bool | TRUE: Read has been completed successfully
writeDone | Bool | TRUE: Write has been completed successfully
busy | Bool | TRUE: FB is not finished and new output values can be expected
error | Bool | TRUE: An error occurred during the execution of the FB
lastRead | DTL | Timestamp of last read access
lastWrite | DTL | Timestamp of last write access
status | Word | 16#0000 - 16#7FFF: Status of the FB, 16#8000 - 16#FFFF: Error identification
diagnostics | LGF_typeDiagnostics | Diagnostic information

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0001 | STATUS_READ_DONE Read execution finished without errors
16#0002 | STATUS_WRITE_DONE Write execution finished without errors
16#7000 | STATUS_NO_CALL No job being currently processed
16#7001 | STATUS_READ Read value(s) in progress
16#7002 | STATUS_WRITE Write value(s) in progress
16#8400 | ERR_MULTIPLE_COMMANDS Error: Multiple commands add the same time not allowed.
16#8600 | ERR_UNDEFINED_STATE Error: Undefined state in state machine
16#8601 | ERR_READ Error: Read value(s) `READ_DBL` - see `diagnostics.subfunctionStatus`
16#8602 | ERR_WRITE Error: Write value(s) `WRITE_DBL` - see `diagnostics.subfunctionStatus`
16#8611 | ERR_READ_TIME Error: Read timestamp `RD_LOC_T` while read values - see `diagnostics.subfunctionStatus`
16#8612 | ERR_WRITE_TIME Error: Write timestamp `WR_LOC_T` while write values - see `diagnostics.subfunctionStatus`

## User defined datatype(s)

### LGF_typeDiagnostics (UDT / V1.0.1)

Diagnostic structure to store and transfer diagnostic information from blocks through the interface.

Identifier | Data type | Default value | Description
--- | --- | --- | ---
status | Word | 16#0000 | Status of the Block or error identification when error occurred
subfunctionStatus | Word | 16#0000 | Status or return value of called FB's, FC's and system blocks
stateNumber | DInt | 0 | State in the state machine of the block where the error occurred

## Functional description

The function reads or writes the start value of a single variable, a structured variable or an entire data area or data block from the source to the destination.

The parameter `dataDestination` must always be present, the parameter `dataSource` is optional.
If `dataSource` is not used, the function...

- reads the start value(s) of the destination(s) and writes them to the current value of the same variable(s)/data block.
- writes the start value(s) of the target to the start value(s) of the same variable(s) of the data block.

NOTE
  If the start values are written, the data block then appears in engineering as an "inconsistent" data block after the values have been written by the user program.

NOTE
  In order to use complete data blocks, they must be derived from a PLC data type.

Note
  A change to the start values can no longer be reversed without further modifications.

  The possibilities are, for example:

  - using an "empty" source with default values
  - overwriting the value again with a different value
  - downloading the original data block from the engineering system

Caution
  The changes are written to the SMC (Simatic Memory Card).
  The SMC is a flash memory with limited write cycles, so you should not write cyclically to the SMC!

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Simatic Systems Support
| 2025-05-05 | First released version