# String latch

Process

Captures a string input value on a pulse and holds it internally. The captured value is sent to the output on trigger or optionally on capture.

String latch
V
C
T
R
V

# Inputs

IDAbbrevNameTypeDefaultDescription
valueVValueSTRINGThe string input value available for capture.
captureCCaptureBOOLEANfalsePulse input. Rising edge latches the current input value internally. If 'Trigger on capture' is enabled, also sends the value to the output.
triggerTTriggerBOOLEANfalsePulse input. Rising edge sends the captured value to the output, even if the output already holds the same value.
resetRResetBOOLEANfalsePulse input. Rising edge resets the output and captured value to the configured default value. Dominant input.

# Outputs

IDAbbrevNameTypeDefaultDescription
valueVValueSTRINGThe latched string value. Updated on trigger, on capture when auto-trigger is enabled, or on reset.

# Configuration

IDNameTypeDefaultUnitDescription
default_valueDefault valueSTRINGThe value restored to the output and captured state on reset.

Details:

Required
trigger_on_captureTrigger on captureBOOLEANtrueWhen enabled, capturing a value also immediately sends it to the output. When disabled, capture only stores the value internally until an explicit trigger.

# State

IDNameTypeDefaultUnitDescription
captured_valueCaptured valueSTRINGHolds the internally captured string value.
prev_capturePrevious capture stateBOOLEANfalseStores the previous state of the capture input to detect rising edges.
prev_triggerPrevious trigger stateBOOLEANfalseStores the previous state of the trigger input to detect rising edges.
prev_resetPrevious reset stateBOOLEANfalseStores the previous state of the reset input to detect rising edges.

# Source Code

View Volang source
channel = input::channel()
value = input::value()

// Handle "reset" input first (dominant input)
if (channel == "reset") {
    prev_reset = state::get("prev_reset")

    if (value and !prev_reset) {
        // Rising edge on reset - restore default value
        default_value = config::get("default_value")
        state::set("captured_value", default_value)
        output::set("value", default_value)
    }

    state::set("prev_reset", value)
    return
}

// Handle "trigger" input
if (channel == "trigger") {
    prev_trigger = state::get("prev_trigger")

    if (value and !prev_trigger) {
        // Rising edge on trigger - send captured value to output
        output::set("value", state::get("captured_value"))
    }

    state::set("prev_trigger", value)
    return
}

// Handle "capture" input
if (channel == "capture") {
    prev_capture = state::get("prev_capture")

    if (value and !prev_capture) {
        // Rising edge on capture - latch current input value internally
        captured = input::get("value")
        state::set("captured_value", captured)

        // Optionally send to output immediately
        if (config::get("trigger_on_capture")) {
            output::set("value", captured)
        }
    }

    state::set("prev_capture", value)
    return
}

// "value" input changes are ignored - output holds until next capture, trigger, or reset
Captures a string input value on a pulse and holds it internally. The captured value is sent to the output on trigger or optionally on capture.