Models: what the instrument measures
A query with respuesta: "{tension}" returns what was configured. A measurement
is something else: the current a supply delivers depends on the voltage, the
load and whether the output is on. That is a model.
modelos:
corriente_medida:
tipo: formula
cuando: { salida: true }
expr: "min(tension / carga_ohm, limite_corriente) + gauss(0, 1e-5)"
fallback: 0.0
formato: fijo:5
And the query that uses it:
- patron: "MEASure[:SCALar]:CURRent[:DC]"
query: true
modelo: corriente_medida
Fields
| Field | What it is |
|---|---|
tipo | Always formula. |
expr | The formula. |
cuando | Conditions on the state. If any is not met, fallback is answered. If there are several, all must hold. |
fallback | The answer when cuando is not met. Defaults to 0.0. Number or text. |
formato | How the number is written. Optional. |
What goes in expr
- State variables, by name:
tension,carga_ohm. - Numbers:
10,0.5,1e-3,2.5E+2. + - * /with the usual precedence, parentheses and unary minus.- Functions:
| Function | Result |
|---|---|
gauss(mean, sigma) | Gaussian noise. It changes on every read, but the series repeats the same each time you start Crucible, so automated tests are reproducible. |
abs(x) | Absolute value. |
sqrt(x) | Square root. |
min(a, b), max(a, b) | Minimum and maximum. |
There are no conditionals inside the formula: cuando only chooses between the
formula and a fixed fallback.
The supply’s model, running
Against a freshly started bench:
$ printf 'MEAS:CURR?\n' | nc -q1 127.0.0.1 5025
0.00000
$ printf 'OUTP?\n' | nc -q1 127.0.0.1 5025
0
$ printf 'VOLT 5;:OUTP ON;:MEAS:CURR?\n' | nc -q1 127.0.0.1 5025
0.50001
$ printf 'VOLT 20;:MEAS:CURR?;:OUTP?\n' | nc -q1 127.0.0.1 5025
0.99999;1
$ printf 'MEAS:VOLT?\n' | nc -q1 127.0.0.1 5026
+3.300139E+00
Step by step:
- With the output off
cuandois not met, and the measurement is thefallback, written in the model’s format:0.00000. OUTP?answers0, notfalse: it is answered by thesalida_como_numeromodel, withformato: entero, like a real instrument.- At 5 V across 10 Ω, half an ampere plus noise.
- At 20 V it would be 2 A, but
minclips it to the 1 A limit: the supply goes into constant current. - The multimeter writes scientific notation, like most do.
formato
Your software expects numbers written the way the real instrument writes them:
formato | Example answer | Typical use |
|---|---|---|
| (not set) | 1.0, 4.501385029307777 | — |
entero (integer) | 1, 0, -3 | States (OUTP?) and counters. |
fijo:N (fixed) | fijo:4 → 4.5014 | Supplies that answer with fixed decimals. |
cientifico:N (scientific) | cientifico:6 → +4.501385E+00 | Multimeters and most SCPI measurements. |
The format also applies to fallback when it is numeric.
Queries with respuesta: "{variable}" return the value as it is (5.0). If
your software expects another form, use a model whose expr is the variable,
with the right formato.
Errors in formulas
Syntax errors —an unclosed parenthesis, a function that does not exist— show up when validating or starting, with the position:
dispositivo:
modelo: DMM-ABC
idn: "ACME,DMM-ABC,SN12345,FW2.01"
protocolo: scpi
estado:
tension_entrada: 0.0
comandos:
- patron: "MEASure:VOLTage[:DC]"
query: true
modelo: lectura
modelos:
lectura:
tipo: formula
expr: "tension_entrada + gaus(0, 0.0001)"
$ crucible --validar perfiles/formula_rota.yaml
error: perfiles/formula_rota.yaml: perfil inválido: modelo 'lectura': error de evaluación: fórmula 'tension_entrada + gaus(0, 0.0001)': función 'gaus' desconocida; existen: gauss, abs, sqrt, min, max (posición 23)
The message says the function gaus is unknown, lists the ones that exist and
gives the position.
A variable that does not exist in the state, however, is only detected when
the query is made: no answer arrives and SYST:ERR? returns
-200,"Execution error;…la variable '…' no existe en el estado…" (the variable
does not exist in the state). Declare in estado every variable your formulas
use.