Troubleshooting Stage OUT and STREAMIN Termination

Brian Holt3 min read
AutomationDirectPLC HardwareTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Stage transitions execute termination behavior on the following scan. That behavior can turn off values controlled by an OUT and cancel an unfinished STREAMIN. Account for this delayed cleanup when outputs, asynchronous serial operations, or device resources appear to change after a stage has been left.

Diagnose OUT State Changes After a Stage Jump

After a JMP leaves a stage, the stage receives one final termination pass on the next scan. During that pass, outputs targeted by OUT are turned off. Consequently, an OUT in the terminating stage can nullify a value written by a subsequent stage, even though an increment or other diagnostic confirms that the subsequent logic executed.

Observation Interpretation Check
Loop-completion counter increments The program reached the end of the loop Inspect the following scan for stage termination
Y0 or C0 does not remain on An earlier stage may still manage that address through OUT Search active and terminating stages for every write to the address
A later SET appears ineffective The terminating stage's OUT can overwrite it Separate stage-managed outputs from latched state

Avoid Mixing SET/RST and OUT Ownership

Do not mix SET/RST and OUT instructions for the same address across stage logic. The instructions have different persistence behavior, while stage termination specifically manages OUT targets. Assign each address one intentional ownership strategy.

  1. Find every OUT, SET, and RST that writes the affected address.
  2. Identify which stage is terminating on the scan after the jump.
  3. Use separate memory locations to capture the state for diagnosis; the evidence used C2 and C3 to record Y0 and C0.
  4. Run the transition again and verify the captured state before and after the termination scan.
RST C2
RST C3
STR Y0
SET C2
STR C0
SET C3

Complete or Cancel STREAMIN Deliberately

A triggered STREAMIN locks its device and should continue executing until it finishes successfully or with an error. Keep its stage enabled until completion when possible, using its On Success or On Error stage-jump options to align the transition with the asynchronous result.

Leaving the stage early with JMP or SGRST, or stopping its program code block with EXIT or HALT, invokes termination cleanup. This cancels STREAMIN, releases resources including the serial port, and can produce an error or warning. Characters may still arrive physically after cancellation, so execute DEVCLEAR before the next transaction to flush stragglers. For variable response delays, monitor the port-device structure member containing the input-queue byte count, apply timing control in logic, and invoke STREAMIN after one or more bytes arrive. If fixed fast and slow behaviors are required instead, use two STREAMIN instances; the reported response cases were 400 ms and 2 s.

Use Serial Device Handles Only When Required

A directly referenced serial port does not require OPENDEV and CLOSE. Use OPENDEV when logic needs a device handle—an indirect device reference selected at runtime. Use CLOSE only for a device opened through an OPENXXX operation such as OPENDEV or OPENTCP. These rules also apply when the serial operation uses an H2-SERIO-4.

FAQ

Why does Y0 turn off after a stage JMP?

The stage performs a termination pass on the following scan, and that pass turns off addresses managed by OUT. Check the stage being left for an OUT Y0 that overwrites later logic.

What happens if I leave a stage before STREAMIN finishes?

Stage termination cancels the unfinished STREAMIN, releases the locked device resource, and can report an error or warning. Use DEVCLEAR if characters may arrive after the cancellation.

Do I need OPENDEV for an H2-SERIO-4 serial port?

No, not when the logic references the serial port directly. Use OPENDEV only to create an indirect device handle selected at runtime, and use CLOSE for devices opened through an OPENXXX call.

Back to blog