Connect IoT - How Values Travel Tutorial#
Overview#
A workflow reads like a short program: each task is a call that receives inputs, emits outputs, and then signals Success or Error. Many defects that look like bad equipment data come from how values move between those calls: a task that never runs, a value left from an earlier event, or a value that the next event replaces before it is used.
This tutorial is for integrators who completed Connect IoT - Basic Configuration Tutorial and build workflows in the Automation Controller designer. A File Raw driver plays the equipment, so you raise each event yourself by dropping a file into a folder, and you read each result on the Automation Manager console.
At the end, you have a Data Flow workflow that shows each mechanism one at a time, and a Control Flow workflow that handles overlapping files without mixing their values.
Info
For more information, see Create a Workflow - Data Flow, Create a Workflow - Control Flow, and Log Message.
Before You Start#
- Prepare a File Raw integration: an Automation Protocol on the
@criticalmanufacturing/connect-iot-driver-filerawpackage, an Automation Driver Definition with the driver's shipped events, and an Automation Controller with that driver. Connect IoT - Control Flow Configuration Tutorial creates these entities, and Connect IoT - Raw File Driver lists the eventsOnNewFileandOnFileDeletedand the properties they carry. - Set
pathin theEquipment Configurationtask of the controller setup workflow to an empty folder, for examplec:/temp/Handler. KeepalwaysStatat its default,true, so thatOnNewFilecarriesSize. - Run an Automation Manager in console mode with an instance of the controller.
- Raise the events by hand, or from an automated test with the Test Orchestrator File-Raw simulator ↗, which creates and deletes files in the watched folder.
Note
From version 12.0, the File Drivers tasks, such as New File Event, are deprecated. Listen to file events with On Equipment Event, as this tutorial does, and run file operations with Execute Equipment Command. See the File Raw tasks migration guide ↗.
Sequence of Steps#
Step 1: Log Each New File#
A task runs when a value reaches its Activate input. A value that reaches any other input waits there until the task is activated.
- In the Automation Controller, add a Data Flow workflow named, for example,
How Values Travel. - Add an
On Equipment Eventtask and set Equipment Event toOnNewFile. Its outputs includeFileNameandSize. - Add a
Log Messagetask namedLog file name, with ModeRawTextand Default Message(no file yet). -
Link the
FileNameoutput to themessageinput ofLog file name, save, and drop a file, such asa.csv, into the watched folder.No line from
Log file nameappears: a value onmessagedoes not run the task. -
Link the
Successoutput ofOn Equipment Eventto theActivateinput ofLog file name, save, and dropb.csv.The console shows
b.csv.
Every task has Activate, Success, and Error. A task emits its own outputs first and Success last, so a task activated by Success finds the values already on its inputs. Link the values that a task reads, then link Success to Activate to say when to read them. Switch follows the same rule: it compares only when a value reaches Activate.
Note
From version 12.0, Log Message and Switch run only from Activate. The 12.0.0 migration adds, in Data Flow workflows, an Activate link from each output already linked to these tasks. See the normalized tasks migration guide ↗.
Step 2: Activate the Log From Another Event#
In Data Flow, one instance of each task serves the whole workflow, and an input keeps its value until something clears or replaces it. Log Message clears its inputs after each line while Reset inputs on activate is on, its default.
- Add a second
On Equipment Eventtask with Equipment EventOnFileDeleted, link itsSuccessto theActivateinput ofLog file name, and save. -
Drop
c.csv, and then delete it.The console shows
c.csvwhen the file arrives and(no file yet)when you delete it. The first line clearedmessage, so the second activation falls back to Default Message. -
Turn off Reset inputs on activate, save, and repeat with
d.csv.The deletion now shows
d.csvagain: the task reads a value that another event left on its input, and nothing in the log says so. -
Turn Reset inputs on activate back on, delete the
OnFileDeletedtask, and save.
Tasks differ in what they keep between runs. Execute Equipment Command, for example, keeps its arguments unless Clear Inputs (on activate) is on, and that setting is off by default. Check the reference page of each task, and feed each chain from one event, so that every activation brings every value the task reads.
Step 3: Log Several Values Through Added Ports#
Some tasks cannot declare in advance the values they carry, so you add their ports. Linking an output to the Link here to add new input of such a task adds a named input.
- Add a
Log Messagetask namedLog file details, with ModeMultipleInputs. - Link the
FileNameandSizeoutputs ofOn Equipment Eventto theLink here to add newinput ofLog file details, linkSuccessto itsActivate, and save. -
Drop
e.csv.Log file detailsshowsFileName = e.csvandSize = <bytes>. Each label is the name of the added input.
The canvas labels an added port with the name you gave it, but each task stores the port under a name of its own. A Data Flow link uses the stored name without showing it, while a Control Flow input row or expression must write it:
| Task | Added port on the canvas | Stored port name |
|---|---|---|
On Equipment Event | output FileName | FileName |
Log Message, MultipleInputs mode | input FileName | FileNameIn. In Control Flow, the task also reads a row named FileName |
Code | input Size, output status | SizeIn, statusOut |
Synchronize | FileName | FileNameIn and FileNameOut |
Store Data, Retrieve Data | entry count | count |
Table: Stored names of added ports
A wrong port name raises no error. The value does not arrive, and the task logs <null> or runs on a default value.
Step 4: Tell null From undefined#
An output that emits undefined changes nothing on the input it reaches, so it activates nothing. An output that emits null is delivered like any other value, and it activates the task it reaches.
- Add a
Codetask namedclassify, and on its Outputs tab add an outputstatusof typeString. - Link the
Sizeoutput ofOn Equipment Eventto theLink here to add newinput ofclassify, which adds the inputSize, and linkSuccessto itsActivate. -
On the Code tab, make
mainreturn a status: -
Add a
Log Messagetask namedLog status, with ModeRawTextand Default Message(no status). Link thestatusoutput ofclassifyto both themessageand theActivateinputs ofLog status, and save. -
Drop a file with some text in it, and then an empty file, such as
empty.csv.Log statusshowshas data, and then(no status). ThenullreachedActivateand ran the task, and the emptymessagefell back to Default Message. -
Replace
nullwithundefinedin the code, save, and drop another empty file.Log statusshows nothing: theundefineddid not activate it. -
Replace
undefinedwith"empty", save, and drop another empty file.Log statusshowsempty.
Give a value its fallback where you produce it, and do not emit null. The link from status to Activate only makes the difference visible: in a workflow, activate Log status from the Success of classify.
Step 5: Let Two Files Share One Task Instance#
Overlapping events share every Data Flow task. When a second event reaches an input before the first run reads it, the second value replaces the first.
- Add a
Sleeptask with Interval5000. Remove the link fromSuccessofOn Equipment EventtoActivateofLog file name, link thatSuccessto theActivateofSleep, and link theSuccessofSleepto theActivateofLog file name. Keep the link fromFileNametomessage, and save. -
Drop
f1.csv, and dropf2.csvwithin five seconds.Five seconds after each file,
Log file nameshowsf2.csv, and then(no file yet). The second file replacedf1.csvonmessagewhile the first run waited, and the first line cleared it.
The Sleep only makes the window visible. Events that arrive closer together than their chain takes to run overwrite values in the same way. When a second value reaches an input before the first was delivered, the controller warns Task '<page>\<task>' input '<input>' will receive value '<new>' instead of '<old>'. No task or workflow setting makes Data Flow safe for fast events.
Step 6: Rebuild the Handler in Control Flow#
A Control Flow branch builds its tasks anew for each event, so each run reads only its own values. There are no links: an input row reads an earlier task through an expression, {{ $<block name>.<stored output name> }}. This step writes the On Equipment Event block as onFile and the Code block as classify; in your workflow, type $ inside {{ }} and pick the block names that the designer suggests.
- In the
How Values Travelworkflow, turn off Auto Enable onOn Equipment Event, so that only the new workflow reacts to files, and save. - Add a Control Flow workflow named, for example,
How Values Travel CF, and place anOn Equipment Eventtask with Equipment EventOnNewFile. -
Place these tasks in the handler of the event, in this order:
Task Settings Input rows SleepInterval 5000- CodeInput Sizeof typeInteger, outputstatusof typeString, and the code from Step 4 with"empty"SizeIn:{{ $onFile.Size }}Log MessageMode RawText, and Default Message{{ $onFile.FileName }}: {{ $classify.statusOut }}- Table: Tasks in the Control Flow handler
The field after
Logon the block is Default Message. In Control Flow,Log Messageevaluates the expressions in it. -
Save, drop
g1.csvwith some text in it, and drop an emptyg2.csvwithin five seconds.After each wait, the console shows
g1.csv: has dataand theng2.csv: empty, each line under the execution context of its own file.
An expression that reads $classify.status gets nothing, because Code emits its added output as statusOut. Handle a fast or overlapping event in Control Flow. Data Flow suits events spaced further apart than their chain takes to run, and workflows that switch their own triggers on and off.
Validate the Result#
-
Drop three files within five seconds, one of them empty.
How Values Travel CFshows one line per file, each with its own name and status.How Values Travelshows nothing, because its trigger is off. -
Turn Auto Enable back on in
How Values Travel, save, and repeat.Log file detailsandLog statusshow each file immediately.Log file nameshows the name of a later file after the first wait and(no file yet)after the others. The Control Flow lines stay correct.
What You Learned#
- A task runs when a value reaches
Activate, and it emits its outputs beforeSuccess. - A Data Flow task is one instance for the whole workflow: it keeps what its inputs received unless it clears them, as Reset inputs on activate does for
Log Message. - An added port has the name you gave it on the canvas and a stored name, such as
statusOut, that Control Flow rows and expressions use. - An
undefinedoutput activates nothing, and anulloutput is delivered. - Overlapping events overwrite values in Data Flow, and Control Flow gives each event its own run.
Next Steps#
Continue with Connect IoT - Control Flow in Depth Tutorial to branch, loop, and handle failures in Control Flow, and with Connect IoT - Timing and State Tutorial to add clocks, time limits, and values that outlive a run. The Connect IoT - Learning Path lists the full sequence.



