Skip to main content

Memory Computation

Memory computation is used to maintain memory variables under the Memory device (virtual device inside the gateway). Memory variables do not directly connect to field devices and are usually used to store script calculation results, intermediate values in rule flow, internal status, statistics, or data that needs to be reused within the gateway.

Create and verify a variable​

First Look at Terms​

TerminologyOn-site Understanding
Memory deviceA virtual device inside the gateway. It does not connect to a PLC, instrument, or serial port.
Memory variablesInternal gateway points, which can store calculation results, temporary status, statistics, or manually written values.
Read expressionA rule for calculating or reading a memory variable. When empty, the variable does not update automatically through calculation.
Write expressionA rule applied when a value is written. It can validate, convert, or link the value to another variable.
Execution intervalThe interval between periodic calculation or refreshing of memory variables. Too short a gap increases CPU pressure.
Value FilteringCollection filters do not establish how a manual memory write behaves; check the actual type and write path.
Alarm suppressionA Data Conversion script returns true to allow and false to block; empty adds no condition.

Function Entry​

After logging into TGateway Web, click the menu on the left "Develop Configuration → Memory Calculation."

Memory Calculation Page

Before you start​

  • Decide whether each variable is updated by a manual write, a read expression, a script, or a rule flow. Avoid multiple sources overwriting one value.
  • Confirm name, unit, initial value, interval, and permissions. Memory configuration uses Object; inspect the actual runtime type after assigning a value.
  • If a script, rule, or forwarding group references the variable, keep its name stable after it goes live.
  • Review the execution interval before enabling many high-frequency calculations, so CPU usage remains controlled.

Add and Edit Variables​

After clicking "Add Variable," the variable configuration popup will open on the page. Variables created on memory calculation pages belong to memory devices by default, without needing to select channels or collection devices.

Configuration ItemDescription
Variable NameRequired. It is recommended to use English, numbers, and underlines to facilitate script and rule references.
Assigned devicefixed to Memory device.
UnitEngineering unit for variable values.
Enableto control whether variables participate in running.
DescriptionExplanation of variable usage.
Read and write permissionsControl whether variables allow read, write, or read/write access.
Execution intervalThe interval used for periodic calculation or refresh.
Read expression parametersSelect or fill in memory variables to calculate the expression parameters used.
Write expression parametersFill in when you need to handle the write value.
Remarks fieldcan be used for business expansion, grouping, encoding, or external system mapping.
Alarm ConfigurationConfigure alarm groups and numeric state mappings. Alarm expressions use Data Conversion scripts.
Value FilteringVerify actual memory assignment separately from numeric collection filtering.

After configuration, choose “Save” to keep editing in the popup, or choose “OK” to save and close it.

Minimum usable configuration​

  1. Click Add Variable, name it ManualValue, keep device Memory and data type Object, set initial value 0, and leave it enabled.
  2. Allow read/write access and leave both expressions empty for this manual test.
  3. Click OK, find the row, and open Write.
  4. Enter 12.5 without quotes, submit, and refresh. The current value should be 12.5.

ManualValue after writing 12.5, with Object as its configured type

The write dialog recognizes numbers, Boolean values, and JSON objects or arrays. Runtime Data Type describes the stored value; it can show Decimal for this input while configuration remains Object. Use a new test variable, because writing an existing variable referenced by a rule can trigger downstream actions.

For automatic calculation, select a Memory Variable read script, save its arguments, choose a trigger, and check the result after execution. A manual value with no read expression does not recalculate periodically.

Save, enable, and verify​

CheckPass standard
Save resultThe variable appears in the list with the expected name, data type, and enabled state.
Runtime resultA write or expression updates the value with the expected time and quality. A manually assigned point with no expression need not receive new timestamps between writes.
Write resultThe page reports success, and the current value plus any rule or script result using it is as expected.
Downstream useAfter adding the variable to a rule or forwarding group, the downstream log or receiver shows the expected value.

Saving a variable is not enough when it is disabled, its expression is not running, or a downstream target receives no value.

Variable settings reference​

Page Structure​

RegionDescription
Filter AreaFilter memory variables by variable name, read expression, and state.
Operation AreaDisplays the total data count, providing refresh, new variable, column settings, variable import, variable export, and export everything.
Variable TableDisplays variable runtime values and configuration summaries under the Memory device.
Batch Operation BarDisplays after checking variables, allowing batch editing or batch deletion.
Pagination barSwitch pages and the number of rows displayed per page.

Variable List​

ColumnDescription
Variable NameMemory Variable Name. Naming should be stable and avoid frequent modifications after being referenced by scripts, rules, or forwarded configurations.
DescriptionExplanation of variable usage.
Current ValueThe current value of the variable.
Original valueOriginal value before conversion or formatting.
Data TypeData type configured by variable.
Runtime Data TypeData type corresponding to the current runtime.
Read ExpressionsExpressions used to calculate or read variable values.
Online statusDisplays whether the variable is currently normal.
Collection timeThe time when the variable value was last updated.
Change timeThe time when the variable value last changed.
Error messageError details when calculation or update fails.
OperationsView details, write, edit, copy, or delete variables.

Calculation triggers​

Bind a Memory Variable read script using Tag for dependencies. The write expression uses Data Conversion instead. Verify collection time, change time, quality, and errors along with results.

ModeBehavior with registered dependencies
On changeRecalculates when a Tag input changes. An interval such as 4000 does not make stable inputs recalculate every four seconds.
ScheduledMilliseconds or six-field Cron, for example 1000 or */2 * * * * *.
Scheduled or on changeEither event can run the calculation.

Empty interval uses the memory device default rather than disabling execution. Scripts without registered Tag dependencies enter periodic scheduling. A time-returning script without dependencies cannot verify change-only behavior.

Dependencies in conditional branches​

Change triggers follow the Tag reads actually executed in the current evaluation. After switching branches, sources no longer read leave the dependency set. Read the branch selector through Tag as well so changing it can trigger reevaluation.

For a formula selecting A or B, change A while A is selected and confirm recalculation; changing B should not trigger that branch. Switch to B and reverse the checks. Observe sample timestamps and execution errors, since an unchanged result alone does not mean the formula did not execute.

After a read-chain failure, sources already accessed can still trigger recovery; old dependencies in the unexecuted remainder stop triggering. If no effective source dependency remains, check recovery through periodic scheduling. Remove cyclic dependencies before verifying downstream results.

Create inputs Memory.InputA=10 and Memory.InputB=20, then a read-only sum. Check 30, change A to 15 for 35, and B to 25 for 40. Test stable and changing inputs in each mode. A read-only result blocks external writes while allowing calculation updates. Avoid direct or indirect cycles.

For a write expression multiplying input by Scale, bind 2 and write 5 to obtain 10; bind 3 for 15. Clear the write-expression selection and save, then write 5 again to obtain 5. Check RPC enablement, access permission, and system read-only identity independently.

Initial value and latest snapshot​

SettingsPersistence
Save Initial Value offRuntime values can change without updating the configured starting value. Force Save is disabled.
Saving on, Force Save offPeriodic background saving, normally about every 30 minutes unless deployment settings change it. Wait for the actual database write.
Both onUpdates merge per variable and are processed about once per second in the background. This is not synchronous persistence of every sample.

Collection snapshots use the raw value. If a read expression converts raw 1234 into current 12.34, the saved starting point is still 1234. After reconstruction, wait for new collection and conversion before treating a value as a fresh engineering reading.

Snapshots restore state after task reconstruction; they are not history. Fast intermediate values can merge. Use History Storage for a complete process. Disabling saving does not erase a previously saved starting value.

Verify a safe new value, wait for persistence, and restart data tasks in a maintenance window. Check the same variable and continuing collection afterward. Data-task restart also reconstructs collection and simulator tasks.

System status variables​

The gateway maintains read-only Memory.<DeviceName>_DS for device status (Default, OnLine, OffLine, Pause) and Memory.<ChannelName>_TS for channel status (true/false), typically refreshed about once per second. Find them under system memory variables. They cannot be manually written, edited, or deleted. Names follow resource renames and disappear with their owner.

A channel that needs no ordinary external connection can report true without proving an associated physical device is online.

Maintain and use variables​

Common Operations​

OperationsDescription
RefreshReload the list of memory variables.
Column SettingsSelect Table Display Columns; column preferences are saved separately without affecting the collection configuration page.
DetailsOpen the variable details drawer to view basic information, alarm information, value filtering, historical data, and historical alarms.
WriteManually write variable values. Before writing, confirm that the variable read/write permissions allow writing.
EditChange the configuration settings.
CopyCopy existing variables by quantity, suitable for creating memory variables with similar names and configurations.
Batch EditAfter checking variables, batch modify some configurations.
Batch DeleteBatch delete variables after checking the box. Before deletion, ensure that scripts, rules, and forwarding configurations no longer reference these variables.
Import variablesImport memory variables from Excel files. The import result will display failure lines and error messages.
Export variablesExport memory variables in the current filtered page.
Export allExport all memory variables.

Selecting an import file submits it immediately. Use a current export and preserve headers. To upload a new memory point, add it to forwarding scope explicitly. Numeric states and multi-input Boolean alarms are described in Alarm Conditions.

Usage Recommendations​

ScenariosRecommendations
Rule Intermediate ValuesUse memory variables to store states that need to be reused across processes or nodes.
Script Calculation ValuesPut complex computational logic into the script, and memory variables read the script results.
Data forwarding auxiliary fieldsWhen internal statistics need to be forwarded externally, memory variables can be included in the data forwarding scope.
Manual Write DebuggingDuring debugging, memory variables can be manually written, but the production environment should control write permissions.
Batch CreationFirst, create a template variable, then use copy or Excel import to batch generate.

Usage Precautions​

ScenariosRecommendations
Name ChangeBefore modifying variable names, first check whether scripts, rule flows, data forwarding, and external calls reference the name.
Read expressions are nullVariables do not update according to computational logic and can only rely on writing or other process assignments.
Write failureCheck read/write permissions, data types, and value formats.
State AnomaliesCheck the error message columns and check whether the read expression, script compilation status, and dependencies are normal.
Delete variablesExport backups before deleting and confirm that the rule flow and forwarding targets are no longer referenced.

Fault Handling​

PhenomenonHandling Recommendations
List No VariablesClear filter conditions and refresh; Double-check whether the variable has been created under the Memory device.
Current value does not updateCheck whether the variable is enabled, whether the reading expression is correct, and whether the execution interval is reasonable.
Import failureOpen the import result pop-up window and correct the Excel template based on the failed row.
Alarms do not triggerCheck variable and alarm-group enablement, accepted runtime value/type, strict threshold, delay, and the suppression expression's true/false direction.
Data forwarding does not include this variableCheck in the data forwarding group whether the variable range includes the Memory device or the variable.