B9X Ladder Editor v1.48
Detailed Element and Feature Documentation
This manual documents the B9X Ladder Editor v1.48, including ladder elements, editor controls, B9X C export behavior, include-file blocks, timing variables, and recommended use patterns.
1. Overview
B9X Ladder Editor is a ladder-logic editor that creates PLC-style rung programs and exports them to B9X C. The editor is intended for B9X C projects and uses a graphical ladder interface with contacts, coils, timers, counters, sequencers, compare blocks, inline/file include blocks, and export tools.
The core workflow is: create or load a ladder app, edit rungs and elements, optionally assign rung comments or function groups, then export compressed B9X C.
Area |
Summary |
Editor target |
Ladder Logic Project. |
Runtime target |
B9X C on compatible B9X C runtime hardware. |
Primary output |
B9X C source code. |
Project file format |
Text-based saved ladder app loaded and saved by the editor. |
Important v1.48 addition |
Reserved B9X timing variables: b9x_wait_time, b9x_logic_time, b9x_scan_time, b9x_tx. |
2. Main Editor Layout
The editor contains a ladder canvas, rung list/preview area, element buttons, label/value edit fields, rung comment tools, export buttons, and utility buttons. Most ladder elements use the Label field for a variable, tag, or name. Many elements use the shared Value field for preset time, preset count, compare value, sensor number, step number, string value, or file path.
Editor Area |
Purpose |
Ladder canvas |
Displays the selected rung graphically and allows element highlighting. |
Rung preview/list |
Shows all rungs in the project so the user can select and organize them. |
Label field |
Primary editable text for the selected element, often a variable name, tag name, function name, or block name. |
Value field |
Shared numeric/text value used by timers, counters, ADC/TEMP, compares, rung comments, SET STR/DBL, sequencer step/step count, and include file path. |
Apply button |
Applies edits to the selected highlighted element. |
Delete button |
Deletes the selected highlighted element. |
Rung comment field/button |
Adds or edits a comment for the selected rung. Comments can also drive modular function grouping using FUNC:Name. |
3. Basic Editing Workflow
Task |
How to do it |
Add an element |
Select the rung, enter the needed Label/Value text, then click the desired element button. |
Highlight/select an element |
Click the element on the ladder canvas. The editor loads its values into the edit fields. |
Edit an element |
Highlight it, change Label and/or Value, then click Apply. |
Delete an element |
Highlight it and click Delete. |
Add a rung |
Click Add Rung. |
Delete a rung |
Select the rung and click Delete Rung. |
Reorder rungs |
Use Move Up, Move Down, Move To Top, and Move To Bottom. |
Save/load app |
Use Save App and Load App. |
4. Color and Drawing Conventions
The v1.48 editor inherits the v1.41 color convention: input/condition elements are green, output/action elements are red, and rails/rung lines are blue. Block-style output elements are drawn with a wire gap so the rung line does not pass through the graphic.
Visual Type |
Color/Behavior |
Inputs and conditions |
Green: NO, NC, edge contacts, state contacts, done contacts, sequencer contacts, analog/temperature/compare blocks. |
Outputs and actions |
Red: coils, timers, counters, reset elements, print, set variable, function call, include blocks. |
Rung line and rails |
Blue. |
Block elements |
Drawn as a solid block; rung line is stopped on each side. |
5. Contact and Input Elements
Button |
Element |
Label Field |
Value Field |
Export/Behavior |
NO |
Normally Open contact |
Input/bit variable name |
Usually unused |
True when the named variable is 1/true. |
NC |
Normally Closed contact |
Input/bit variable name |
Usually unused |
True when the named variable is 0/false. |
Coil NO |
Coil-state NO contact |
Coil/internal bit name |
Unused |
Uses an output/internal coil state as a normally-open contact. |
Coil NC |
Coil-state NC contact |
Coil/internal bit name |
Unused |
Uses an output/internal coil state as a normally-closed contact. |
↑ |
Rising edge contact |
Input/bit variable name |
Unused |
True for one scan when the named input changes from false to true. |
↓ |
Falling edge contact |
Input/bit variable name |
Unused |
True for one scan when the named input changes from true to false. |
6. Parallel Branch Elements
Parallel branches let a rung implement OR logic. Branch elements are added to the selected rung as alternate paths. The export builds matching OR logic from the branch paths.
Button |
Branch Type |
Use |
Branch NO |
Parallel normally-open contact |
Adds an OR path that is true when its label variable is true. |
Branch NC |
Parallel normally-closed contact |
Adds an OR path that is true when its label variable is false. |
B Coil NO |
Parallel coil-state NO contact |
Adds an OR path based on an existing coil state. |
B Coil NC |
Parallel coil-state NC contact |
Adds an OR path based on the inverse of an existing coil state. |
Branch ↑ |
Parallel rising-edge contact |
Adds an OR edge-detect branch. |
Branch ↓ |
Parallel falling-edge contact |
Adds an OR falling-edge branch. |
Delete Branch |
Remove selected branch |
Deletes the selected parallel branch element. |
7. Coil and Output Elements
Button |
Element |
Label Field |
Value Field |
Behavior |
OUT |
Normal output coil |
Output/internal bit name |
Unused |
Sets the output/bit true when rung logic is true and false when rung logic is false. |
SET |
Set/latch coil |
Output/internal bit name |
Unused |
Latches the bit/output true when rung logic becomes true. |
RST |
Reset/unlatch coil |
Output/internal bit name |
Unused |
Forces the bit/output false when rung logic becomes true. |
8. Timer Elements
Timer elements use the shared Value field for timer preset or timer number depending on the element. Timer blocks are output/action elements and are drawn as solid blocks with no rung line through the graphic.
Button |
Element |
Label Field |
Value Field |
Behavior |
TON |
Timer On Delay |
Timer name/number |
Preset milliseconds |
Starts timing when rung is true. Done becomes true after preset time. Resets when rung is false. |
TOF |
Timer Off Delay |
Timer name/number |
Preset milliseconds |
Output remains true for preset time after rung goes false. |
TP |
Pulse Timer |
Timer name/number |
Pulse width in ms |
Creates a timed pulse when triggered. |
T DN NO |
Timer Done NO contact |
Timer name/number |
Unused or timer number |
True when the referenced timer done bit is true. |
T DN NC |
Timer Done NC contact |
Timer name/number |
Unused or timer number |
True when the referenced timer done bit is false. |
T RST |
Timer Restart/Reset |
Timer name/number |
Timer number if applicable |
Restarts or clears the referenced timer state. |
9. Counter Elements
Button |
Element |
Label Field |
Value Field |
Behavior |
CTU |
Counter Up |
Counter name |
Preset value |
Counts upward on rung transitions or trigger logic. Done when count reaches preset. |
CTD |
Counter Down |
Counter name |
Preset/start value |
Counts downward. Done/terminal state depends on exported counter logic. |
C DN NO |
Counter Done NO contact |
Counter name |
Unused |
True when referenced counter done bit is true. |
C DN NC |
Counter Done NC contact |
Counter name |
Unused |
True when referenced counter done bit is false. |
C RST |
Counter Reset |
Counter name |
Unused |
Resets the referenced counter. |
10. Analog, Temperature, and Compare Elements
Button |
Element |
Label Field |
Value Field |
Behavior |
ADC |
Analog input |
Analog variable name |
ADC channel/value setting |
Reads or references an ADC value. |
TEMP |
Temperature sensor |
Temperature variable name |
Sensor number, typically 0 or 1 |
Exports code using get_temperature(sensorNumber). |
> |
Greater Than |
Variable name |
Compare value |
True when variable > value. |
< |
Less Than |
Variable name |
Compare value |
True when variable < value. |
= |
Equal |
Variable name |
Compare value |
True when variable == value. |
>= |
Greater Than or Equal |
Variable name |
Compare value |
True when variable >= value. |
<= |
Less Than or Equal |
Variable name |
Compare value |
True when variable <= value. |
<> |
Not Equal |
Variable name |
Compare value |
True when variable != value. |
11. Variable and Print Elements
Button |
Element |
Label Field |
Value Field |
Export/Behavior |
SET DBL |
Set double variable |
Double variable name |
Numeric value/expression |
Exports an assignment such as variable=value;. |
SET STR |
Set string variable |
String variable name |
String value without quotes |
Exports B9X string assignment and auto-quotes the value. String variables are declared before use. |
Print string |
String text/message |
Unused |
Exports a print output for a string message. Use sparingly in fast scan loops. |
|
PRINT DBL |
Print double |
Double variable name |
Unused |
Exports a printf/print style output for a double variable. Use sparingly at 115200 baud. |
12. Function, Inline, and Include Elements
These elements allow the ladder app to call B9X C functions or insert external/source code. They are powerful and should be used carefully because inserted code is exported as-is.
Button |
Element |
Label Field |
Value Field |
Export Location |
CALL |
Function call output |
Function name |
Unused |
Inside loop, under rung conditions. |
CALL INITIALIZATION |
Pre-loop function call |
Function name |
Unused |
Placed for initialization at startup. |
INCLUDE FILE |
Rung-position file include |
Block name |
Path to .c/.txt file |
Contents are inserted where the rung is exported. |
INCLUDE INIT |
Pre-loop include file |
Block name |
Path to .c/.txt file |
Contents are inserted at startup. |
13. One Shot Element
Button |
Element |
Label Field |
Value Field |
Behavior |
ONE SHOT |
One-scan pulse output |
Pulse/internal bit name |
Unused |
Creates a one-scan pulse when the rung condition transitions true. Useful for counters, sequencers, and one-time actions. |
14. Sequencer Elements
The sequencer is a PLC-style step controller. Step 0 is the normal startup/idle step. A trigger advances the sequencer through its steps and wraps back to 0 after the last step.
Button |
Element |
Label Field |
Value Field |
Behavior |
SEQ |
Sequencer advance block |
Sequencer name |
Number of steps |
Advances the named sequencer when rung logic is true. |
SEQ RST |
Sequencer reset block |
Sequencer name |
Unused |
Forces the named sequencer back to step 0. |
SEQ STEP |
Sequencer step contact |
Sequencer name |
Step number |
True when the named sequencer is currently at the specified step. |
SEQ DONE |
Sequencer done contact |
Sequencer name |
Unused |
True when the sequencer is at its final step. |
//
Example sequence idea
// Step 0 = Idle
// Step 1 = Clamp
//
Step 2 = Process
// Step 3 = Unclamp
// Startup
state: Step 0
// Trigger 1 -> Step 1
// Trigger 2 ->
Step 2
// Trigger 3 -> Step 3
// Trigger 4 -> Step 0
15. Rung Management Features
Feature |
Description |
Add Rung |
Creates a new empty rung. |
Delete Rung |
Removes the selected rung. |
Move Up/Down |
Moves the highlighted rung one position. |
Move To Top/Bottom |
Moves the highlighted rung to the first or last position. |
Rung comments |
Each rung can have a comment. Comments are exported as readable comments in normal export and can be used for modular grouping with FUNC:Name. |
Rungs Preview |
Opens or refreshes a preview window/list for all rungs. |
16. Save, Load, and Variable Browser
Feature |
Description |
Save App |
Saves the ladder application to the editor text format. |
Load App |
Loads a saved ladder application. |
Variables |
Opens a variable browser/report window generated from the current rung/app text. |
Reserved variables |
v1.48 reserves b9x_wait_time, b9x_logic_time, b9x_scan_time, and b9x_tx as generated runtime variables. |
17. B9X C Export Modes
Button/Mode |
Purpose |
|
|
Export Compressed B9X C |
Compressed export. |
|
|
18. Runtime Timing Variables in v1.48
Every export should include B9X runtime timing variables with a b9x_ prefix to avoid user-variable collisions. These variables let you measure ladder logic time and total scan period.
Variable |
Default |
Meaning |
b9x_wait_time |
10 |
Default scan pacing wait time used by wait(b9x_wait_time);. |
b9x_logic_time |
0 |
Measured ladder logic execution time before the wait. |
b9x_scan_time |
0 |
Measured total scan time including the wait. |
|
|
|
19. Compressed Export
The compressed export is intended to generate compact B9X C. It should preserve behavior while reducing whitespace and comments, except for the required copyright header.
20. Recommended PLC Design Practices
Practice |
Why it matters |
Keep prints out of fast scans |
At 115200 baud, many printf statements can add seconds of delay. |
Use b9x_logic_time and b9x_scan_time |
They show whether time is spent in logic or scan pacing. |
Use SET/RESET carefully |
Latched states should have clear reset logic. |
Use one-shots for sequencers/counters |
Prevents repeated counts or repeated step advances while a button remains on. |
|
|
|
|
21. Example Ladder Patterns
21.1 Start/Stop Latch
Rung
1: NO StartButton -> SET MotorRun
Rung 2: NO StopButton ->
RST MotorRun
Rung 3: Coil NO MotorRun -> OUT MotorOutput
21.2 Timer On Delay Output
Rung
1: NO Start -> TON timer0, Value=1000
Rung 2: T DN NO timer0
-> OUT DelayedOutput
21.3 Counter Up with Reset
Rung
1: Rising Edge PartSensor -> CTU partCounter, Value=10
Rung
2: C DN NO partCounter -> OUT BatchDone
Rung 3: NO
ResetButton -> C RST partCounter
21.4 Sequencer
Rung
1: ONE SHOT StartPulse -> SEQ MachineSeq, Value=4
Rung 2: SEQ
STEP MachineSeq, Value=0 -> OUT IdleLight
Rung 3: SEQ STEP
MachineSeq, Value=1 -> OUT ClampSolenoid
Rung 4: SEQ STEP
MachineSeq, Value=2 -> OUT ProcessMotor
Rung 5: NO Reset ->
SEQ RST MachineSeq
22. File Include Usage
Use INCLUDE FILE to insert external code at the current rung position. Use INCLUDE INIT when the included code must be placed at initialization, such as variable declarations, setup code, or helper definitions.
Use Case |
Recommended Element |
Declare variables, arrays, setup helpers |
INCLUDE INIT |
Run custom code under rung conditions |
INCLUDE FILE |
Add reusable function calls |
CALL or CALL INITIALIZATION |
23. Troubleshooting
Symptom |
Likely Cause |
Fix |
Quote not closed |
SET STR or pasted inline string includes unescaped quotes. |
Enter SET STR value without surrounding quotes; exporter adds quotes. Escape embedded quotes if needed. |
Rung line goes through block |
Element not included in wire-gap drawing list. |
Add the element kind to the output/block drawing gap logic. |
|
|
|
Slow scan time |
Too much printf output, file I/O, or function loading during scan. |
Print less often; load/compile once; use b9x_logic_time and b9x_scan_time. |
Watchdog messages |
Scan loop does not yield enough CPU time. |
Keep wait(b9x_wait_time); at bottom of exported loop. |
Variable collision |
User variable has same name as internal runtime variable. |
Use b9x_ prefix names and reserve them in the editor. |
24. Element Quick Reference
Category |
Elements/Features |
Inputs |
NO, NC, Coil NO, Coil NC, Rising Edge, Falling Edge, timer/counter done contacts, sequencer step/done contacts, compare blocks. |
Outputs/actions |
OUT, SET, RST, TON, TOF, TP, CTU, CTD, resets, ONE SHOT, SEQ, function calls, print, set variables, include blocks. |
Analog/process |
ADC, TEMP, >, <, =, >=, <=, <>. |
Sequencer |
SEQ, SEQ RST, SEQ STEP, SEQ DONE. |
Code integration |
CALL, CALL INITIALIZATION, INCLUDE FILE, INCLUDE INIT. |
Export |
Compressed B9X C. |

