Hi, Ed,
TDM (https://github.com/diverhao/tdm/releases/tag/v2507)
has a “Seq Graph” tool to visualize and run a state machine in the frontend. This tool roughly follows the snl grammar to define the state machine, such as ss/state/when(). The logic must be written in _javascript_. It provides several functions to read/write
PVs. For example, await delay(2) to delay 2 seconds, value_of(“pv_name”) to obtain the value, caput(“pv_name”, 33) to PUT a value, connect(“pv_name1”, “pv_name2”) to connect and monitor the PVs.
You can also visualize an existing C-like snl code using the “Emulation mode”, but you cannot run the code.
How to run a _javascript_ state machine code:
https://github.com/diverhao/misc/blob/main/tdm/run-state-machine.gif
How to visualize a SNL code:
https://github.com/diverhao/misc/blob/main/tdm/visualize-snl-state-machine.gif
The following code is a simple _javascript_ traffic light state machine:
// --------------------------------------------
// global variables must be written in global.xxx
global.R = 0;
global.Y = 1;
global.G = 2;
global.lights = [
"traffic:red_light",
"traffic:yellow_light",
"traffic:green_light"
];
connect(...global.lights);
global.red_time = 3.0;
global.red_yellow_time = 1.0;
global.green_time = 4.0;
global.yellow_time = 1.0;
ss light {
// no code allowed here
state red {
// no code allowed here
entry {
caput(global.lights[global.R], 1);
caput(global.lights[global.Y], 0);
caput(global.lights[global.G], 0);
}
when (await delay(global.red_time)) {
print("switch to red-yellow light");
} state red_yellow
}
state red_yellow {
entry {
caput(global.lights[global.R], 1);
caput(global.lights[global.Y], 1);
caput(global.lights[global.G], 0);
}
when (await delay(global.red_yellow_time)) {
print("switch to green light");
} state green
}
state green {
entry {
caput(global.lights[global.R],0);
caput(global.lights[global.Y],0);
caput(global.lights[global.G],1);
}
when (await delay(global.green_time)) {
print("switch to yellow light");
} state yellow
}
state yellow {
entry {
caput(global.lights[global.R],0);
caput(global.lights[global.Y],1);
caput(global.lights[global.G],0);
}
when (await delay(global.yellow_time)) {
print("switch to red light");
} state red
}
}
// --------------------------------------------
Best,
Hao
From:
Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Ed Janke via Tech-talk <tech-talk at aps.anl.gov>
Date: Thursday, June 26, 2025 at 8:56 PM
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: [EXTERNAL] Generation of state diagram documentation from SNL
Hello! Does anyone know if there is software out there that can parse the SNL in an EPICS Sequence file to generate a state diagram for every state set? I was considering
doing this by hand but figured I would ask the greater community in case
Hello!
Does anyone know if there is software out there that can parse the SNL in an EPICS Sequence file to generate a state diagram for every state set?
I was considering doing this by hand but figured I would ask the greater community in case this already exists.