Resolving CompactLogix STRING Comparison Syntax Errors

Tom Garrett5 min read
Allen-BradleyCompactLogixTroubleshooting
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

A CompactLogix controller can condition a rung by comparing two STRING values with an Equal instruction, then execute the downstream MOV when the comparison is true. The reported “unbalanced parenthesis or brackets” message is an operand-entry syntax error, not a failed string comparison. Create a second STRING tag containing the exact recipe name and compare the two tags; this avoids ambiguous quotation and escape syntax in an inline constant.

Symptom and error boundary

Separate an editor error from a runtime mismatch. If Studio 5000 rejects the rung with Error: Rung ?, EQU, Operand 1&2: unbalanced parenthesis or brackets., the instruction has not reached runtime evaluation. The parser interpreted part of the entered recipe text as ladder syntax, commonly because the value contains a quotation mark, backslash, bracket, or mismatched delimiter.

The requested value was represented as \7" Round, but that notation is ambiguous. It might include a literal backslash, the digit 7, a quotation mark, a leading space, or formatting characters introduced during entry. Read the live string rather than reconstructing it from its displayed name.

Quantity or state Required condition Where to read it
Instruction validity No operand syntax error Rung verification results
LEN Equal in both strings Each STRING tag in the tag monitor
DATA bytes Equal through the declared length Expanded DATA arrays
Character case Exact match Displayed string and corresponding ASCII bytes
Rung result True only for the selected recipe Online ladder monitoring

STRING equality mechanism

A Logix STRING is structured data containing a length and character storage. Equality therefore depends on the logical content, not merely on a visually similar label. The number that matters is LEN, followed by the bytes represented in DATA. Both strings must have matching lengths and matching, case-sensitive contents.

A trailing space changes the length and adds a different byte. A leading space does the same. Uppercase and lowercase characters are different values, while a quote or backslash may be both data and a meaningful token to the editor. Two names that appear identical on an HMI can consequently compare unequal because the display trims spaces or hides a nonprinting character.

Place the EQU instruction before the action it controls. When equality is true, rung continuity reaches the downstream MOV; when false, the move does not execute. If the intended payload of the move is itself a STRING, verify that the selected transfer instruction supports structured string data rather than treating MOV as a general structure copy.

Diagnostic checks

  1. Monitor TS_Recipename online after the HMI or recipe system selects the target recipe.
  2. Record its displayed value and LEN. Check specifically for leading or trailing spaces.
  3. Expand its DATA member and inspect the characters byte by byte. This resolves whether \7" Round contains a literal backslash, quotation mark, or another character.
  4. Create or inspect a separate expected-value STRING tag. Confirm that its data type matches the source tag.
  5. Compare the expected tag’s LEN and DATA against the live value before testing the rung.
  6. Verify the project. If the parenthesis/bracket error remains, remove the inline text operand and enter only the two valid tag references in EQU.

This sequence distinguishes three faults quickly: invalid operand syntax, unequal string content, and a correctly true comparison whose downstream action is blocked elsewhere.

Tag-to-tag correction procedure

  1. Create a STRING tag to hold the expected recipe name. Use the same string data type as TS_Recipename.
  2. Populate the expected tag with the exact runtime recipe value. Copy from a known-good live value or enter it through the tag monitor, then inspect LEN and DATA.
  3. Configure EQU with TS_Recipename as one operand and the expected-value tag as the other. Avoid embedding the recipe text directly in the instruction.
  4. Place the required MOV after the comparison on the same logical path. Add any permissives that genuinely belong to the move, but test the equality alone first.
  5. For several recipes, use one equality branch per recipe and drive a unique internal selection bit or code. Keep the actual process commands downstream from that decoded selection.
  6. Verify and download the change under the site’s normal change-control procedure, then test each selection.

Tag-to-tag comparison is clean because Studio 5000 parses tag identifiers while the quotation mark and other punctuation remain stored as string data. It also makes the expected recipe visible for commissioning and maintenance.

Runtime verification

Select a nonmatching recipe first and confirm that EQU is false and the downstream MOV does not execute. Select the target recipe and confirm that the comparison becomes true only after the source string has reached its final value. Watch the destination of the move, not only the green rung indication, to prove that the commanded data changed as intended.

Repeat the test with case changes and leading or trailing spaces if the HMI permits them. The comparison must reject every unintended variant. If recipe selection updates the characters and length in separate operations, monitor the source during a changeover and qualify the action with the recipe system’s completed or stable indication when one is available.

Recurring implementation pitfalls

Inline constants become fragile when recipe names contain delimiter characters. Typographic quotation marks copied from documentation are also different from ordinary ASCII quotation marks and may be rejected by the editor or stored as different data.

Checking only the visible characters misses stale or unexpected length data. Checking only DATA misses a length mismatch. Inspect both members and compare the bytes only within the logical string length.

A text recipe name is useful for display but is a brittle control key. If the recipe manager exposes a numeric recipe identifier, decode that stable value for control and reserve the name for presentation. When no identifier exists, centralize the name-to-code comparisons so that process logic uses one internal selection value instead of repeating string comparisons throughout the program.

A latched selection can remain active after the source name changes unless explicit unlatch or replacement logic is provided. Prefer mutually exclusive decoded states, and verify that an unknown name produces no valid recipe selection.

FAQ

Can I compare two STRING tags with EQU in CompactLogix?

Yes. Use two matching STRING tags as the EQU operands; equality requires the same LEN, the same case, and matching DATA content.

Does EQU ignore spaces or letter case in a recipe name?

No. Leading spaces, trailing spaces, and case differences change the string value. Read LEN and expand DATA in the tag monitor when names look identical but compare unequal.

When should I stop troubleshooting and contact official support?

Stop if a verified tag-to-tag EQU still produces an editor error, the monitored LEN or DATA changes unexpectedly without application logic doing so, or the controller behavior cannot be reproduced safely. Record the controller catalog information, firmware revision, Studio 5000 version, rung export, and live tag values, then escalate through official Allen-Bradley support channels.

Back to blog