BaseCommand

class pyrogue.BaseCommand(*, name=None, description='', value=0, retValue=None, enum=None, hidden=False, groups=None, minimum=None, maximum=None, function=None, background=False, guiGroup=None, **kwargs)[source]

Base class for PyRogue commands.

Parameters:
  • name (str | None, default: None) – Command name.

  • description (str, default: '') – Human-readable description.

  • value (Any, default: 0) – Default command value.

  • retValue (Any | None, default: None) – Example return value used to infer display type.

  • enum (dict[object, str] | None, default: None) – Mapping from object values to display strings.

  • hidden (bool, default: False) – If True, add the command to the Hidden group.

  • groups (list[str] | None, default: None) – Groups to assign.

  • minimum (Any | None, default: None) – Minimum allowed value.

  • maximum (Any | None, default: None) – Maximum allowed value.

  • function (Callable[..., Any] | None, default: None) – Callback executed when the command is invoked. The wrapper provides keyword arguments root, dev, cmd, and arg; the callback may accept any subset of these names. Default to no-op for command if None.

  • background (bool, default: False) – Reserved for background execution.

  • guiGroup (str | None, default: None) – GUI grouping label.

  • **kwargs (Any) – Additional arguments forwarded to BaseVariable.

property arg: bool

Return True if the command accepts an argument.

property retTypeStr: str | None

Return the display string for the return type.

call(arg=None)[source]

Invoke the command and return the raw result.

Parameters:

arg (Any, default: None) – Command argument.

Return type:

Any

callDisp(arg=None)[source]

Invoke the command and return the display-formatted result.

Parameters:

arg (Any, default: None) – Command argument.

Return type:

str

static nothing()[source]

No-op command handler.

Return type:

None

static read(cmd)[source]

Read the command variable.

Parameters:

cmd (BaseCommand) – Command to read.

Return type:

None

static setArg(cmd, arg)[source]

Set the command argument.

Parameters:
  • cmd (BaseCommand) – Command to write.

  • arg (Any) – Value to write.

Return type:

None

static setAndVerifyArg(cmd, arg)[source]

Set the argument and verify by reading it back.

Parameters:
  • cmd (BaseCommand) – Command to write.

  • arg (Any) – Value to write and verify.

Return type:

None

static createToggle(sets)[source]

Create a toggle function that iterates over provided values.

Parameters:

sets (Iterable[Any]) – Values to write sequentially.

Return type:

Callable[[BaseCommand], None]

static toggle(cmd)[source]

Toggle a command by writing 1 then 0.

Parameters:

cmd (BaseCommand) – Command to toggle.

Return type:

None

static createTouch(value)[source]

Create a touch function that writes a fixed value.

Parameters:

value (Any) – Value to write when the touch function is called.

Return type:

Callable[[BaseCommand], None]

static touch(cmd, arg)[source]

Touch the command with a provided argument or 1.

Parameters:
  • cmd (BaseCommand) – Command to touch.

  • arg (Any) – Value to write. If None, writes 1.

Return type:

None

static touchZero(cmd)[source]

Touch the command with 0.

Parameters:

cmd (BaseCommand) – Command to touch.

Return type:

None

static touchOne(cmd)[source]

Touch the command with 1.

Parameters:

cmd (BaseCommand) – Command to touch.

Return type:

None

static createPostedTouch(value)[source]

Create a posted touch function for asynchronous writes.

Parameters:

value (Any) – Value to post.

Return type:

Callable[[BaseCommand], None]

static postedTouch(cmd, arg)[source]

Post a command value without waiting for completion.

Parameters:
Return type:

None

static postedTouchOne(cmd)[source]

Post a value of 1.

Parameters:

cmd (BaseCommand) – Command to post.

Return type:

None

static postedTouchZero(cmd)[source]

Post a value of 0.

Parameters:

cmd (BaseCommand) – Command to post.

Return type:

None

replaceFunction(function)[source]

Replace the command callback function.

Parameters:

function (Callable[..., Any]) – New callback for this command. The wrapper provides keyword arguments root, dev, cmd, and arg; the callback may accept any subset of these names.

Return type:

None

get(read=True, index=-1)[source]

Return the cached command argument value.

Parameters:
  • read (bool, default: True) – Unused for commands.

  • index (int, default: -1) – Unused for commands.

Return type:

Any

add(node)

Add a node as a child.

Return type:

None

Parameters:

node (Node | Iterable[Node])

addDependency(dep)

Add a dependency variable. When this variable changes, the dependency variable will be notified.

Parameters:

dep (BaseVariable) – The dependency variable to add.

Return type:

None

addListener(listener)

Add a listener Variable or function to call when variable changes. This is useful when chaining variables together. (ADC conversions, etc) The variable and value class are passed as an arg: func(path,varValue)

Parameters:

listener (BaseVariable | Callable[[str, VariableValue], None]) – Variable or callback function to notify.

Return type:

None

addNode(nodeClass, **kwargs)

Construct and add a node of nodeClass.

Return type:

None

Parameters:
addNodes(nodeClass, number, stride, **kwargs)

Add a series of nodes with indexed names.

Return type:

None

Parameters:
addToGroup(group)

Add this node to a group and propagate to children.

Parameters:

group (str) – Group name to add.

Return type:

None

property alarmSeverity: str

Return the current alarm severity.

property alarmStatus: str

Return the current alarm status.

callRecursive(func, nodeTypes=None, **kwargs)

Call a named method on this node and matching children.

Parameters:
  • func (str) – Method name to call.

  • nodeTypes (Iterable[type[Node]] | None, default: None) – Node types to include.

  • **kwargs (Any) – Arguments forwarded to the method call.

Return type:

None

property commands: OrderedDict[str, BaseCommand]

Return direct child commands.

commandsByGroup(incGroups=None, excGroups=None)

Return commands filtered by group.

Return type:

OrderedDict[str, BaseCommand]

Parameters:
delListener(listener)

Remove a listener Variable or function

Parameters:

listener (BaseVariable | Callable[[str, VariableValue], None]) – Variable or callback function to remove.

Return type:

None

property dependencies: list[BaseVariable]

Return registered dependency variables.

property description: str

Return the node description.

property deviceList: list[Device]

Return a recursive list of devices.

property devices: OrderedDict[str, Device]

Return direct child devices.

devicesByGroup(incGroups=None, excGroups=None)

Return devices filtered by group.

Return type:

OrderedDict[str, Device]

Parameters:
property disp: str

Return the display formatter.

property enum: dict[object, str] | None

Return the enum mapping, if any.

property enumYaml: str

Return the enum mapping as YAML.

property expand: bool

Return the expand state.

filterByGroup(incGroups, excGroups)

Return True if the node passes include/exclude filters.

Parameters:
  • incGroups (str | list[str] | None) – Group name or group names to include.

  • excGroups (str | list[str] | None) – Group name or group names to exclude.

Return type:

bool

find(*, recurse=True, typ=None, **kwargs)

Find all child nodes that are a base class of ‘typ’ and whose properties match all of the kwargs. For string properties, accepts regexes.

Parameters:
  • recurse (bool, default: True) – If True, recurse into child nodes.

  • typ (type[Node] | None, default: None) – Base class type to match.

  • **kwargs (Any)

Returns:

List of nodes that match the criteria.

Return type:

list[Node]

genDisp(value, *, useDisp=None)

Generate a display string for a value.

Parameters:
  • value (Any) – Value to format for display.

  • useDisp (str | None, default: None) – Display formatter override. If None, use the variable’s disp formatter.

Return type:

str

getDisp(read=True, index=-1)

Perform a get() and return the display string for the value.

Parameters:
  • read (bool, default: True) – If True, perform a read transaction.

  • index (int, default: -1) – Optional index for array variables.

Return type:

str

getExtraAttribute(name)

Return an extra attribute by name, if present.

Parameters:

name (str) – Attribute name to look up.

Return type:

Any | None

getNodes(typ, excTyp=None, incGroups=None, excGroups=None)

Get a filtered ordered dictionary of nodes. pass a class to typ to receive a certain type of node exc is a class type to exclude, incGroups is an optional group or list of groups that this node must be part of excGroups is an optional group or list of groups that this node must not be part of

Parameters:
  • typ (type[Node])

  • excTyp (type[Node] | None, default: None) – Type to exclude.

  • incGroups (str | list[str] | None, default: None) – Group name or group names to include.

  • excGroups (str | list[str] | None, default: None) – Group name or group names to exclude.

Returns:

Ordered dictionary of nodes.

Return type:

OrderedDict[str, Node]

getVariableValue(read=True, index=-1)

Return the value after performing a read from hardware if applicable. Hardware read is blocking. An error will result in a logged exception. Listeners will be informed of the update.

Parameters:
  • read (bool, default: True) – If True, perform a read transaction.

  • index (int, default: -1) – Optional index for array variables.

Return type:

VariableValue

getYaml(readFirst=False, modes=['RW', 'RO', 'WO'], incGroups=None, excGroups=None, recurse=True)

Return current values as YAML text.

Parameters:
  • readFirst (bool, default: False) – If True, perform a full hardware read before exporting.

  • modes (list[str], default: ['RW', 'RO', 'WO']) – Variable modes to include. Allowed values are 'RW', 'WO', and 'RO'.

  • incGroups (str | list[str] | None, default: None) – Group name or group names to include.

  • excGroups (str | list[str] | None, default: None) – Group name or group names to exclude.

  • recurse (bool, default: True) – If True, recurse into child devices.

Returns:

YAML-formatted representation of the node subtree.

Return type:

str

property groups: list[str]

Return the node groups.

property guiGroup: str | None

Return the GUI group label.

property hasAlarm: bool

Return True if any alarm thresholds are configured.

property hidden: bool

Return True if the node is hidden.

property highAlarm: Any | None

Return the high alarm threshold.

property highWarning: Any | None

Return the high warning threshold.

inGroup(group)

Return True if the node is in the provided group or groups.

Parameters:

group (str) – Group name or list of groups to test.

Return type:

bool

property isCommand: bool

Return True if this node is a command.

property isDevice: bool

Return True if this node is a device.

property isVariable: bool

Return True if this node is a variable (excluding commands).

isinstance(typ)

Return True if this node is an instance of typ.

Return type:

bool

Parameters:

typ (type[Node])

property lock: threading.Lock | None

Return the underlying lock, if available.

property lowAlarm: Any | None

Return the low alarm threshold.

property lowWarning: Any | None

Return the low warning threshold.

makeRecursive(func, nodeTypes=None)

Create a recursive wrapper for a named method.

Parameters:
  • func (str) – Method name to call.

  • nodeTypes (Iterable[type[Node]] | None, default: None) – Node types to include.

Return type:

Callable[..., None]

property maximum: Any | None

Return the maximum allowed value.

property minimum: Any | None

Return the minimum allowed value.

property mode: str

Return the access mode (RW, RO, WO).

property name: str

Return the node name.

property nativeType: Type[object]

Return the native Python type.

property ndType: Type[dtype]

Return the numpy dtype for array variables.

property ndTypeStr: str

Return the numpy dtype as a string.

node(name)

Return a direct child node by name.

Parameters:

name (str) – Child node name.

Return type:

Node

property nodeCount: int

Return the total node count.

property nodeList: list[Node]

Return a recursive list of nodes.

nodeMatch(name)

Match a node name, including array-style accessors.

Parameters:

name (str) – Node name or array accessor string.

Returns:

Matching nodes.

Return type:

list[Node]

property nodes: OrderedDict[str, Node]

Return an ordered dictionary of direct child nodes.

property parent: Node

Return the parent node.

parseDisp(sValue)

Parse a string representation of a value into a Python object.

Parameters:

sValue (str) – Display-formatted value to parse.

Return type:

object

property path: str

Return the full node path.

property pollInterval: float

Return the poll interval.

post(value, *, index=-1)

Set the value and write to hardware if applicable using a posted write. This method does not call through parent.writeBlocks(), but rather calls on self._block directly.

Parameters:
  • value (Any) – Value to set.

  • index (int, default: -1) – Optional index for array variables.

Return type:

None

property precision: int

Return the display precision for float-like values.

printYaml(readFirst=False, modes=['RW', 'RO', 'WO'], incGroups=None, excGroups=None, recurse=False)

Print the YAML representation to stdout.

Parameters:
  • readFirst (bool, default: False) – If True, perform a full hardware read before exporting.

  • modes (list[str], default: ['RW', 'RO', 'WO']) – Variable modes to include. Allowed values are 'RW', 'WO', and 'RO'.

  • incGroups (str | list[str] | None, default: None) – Group name or group names to include.

  • excGroups (str | list[str] | None, default: None) – Group name or group names to exclude.

  • recurse (bool, default: False) – If True, recurse into child devices.

Return type:

None

properties()

Return a dictionary of properties and current value.

Return type:

dict[str, Any]

removeFromGroup(group)

Remove this node from a group.

Parameters:

group (str) – Group name to remove.

Return type:

None

property revEnum: dict[str, object] | None

Return the reverse enum mapping, if available.

property root: Root

Return the root node.

set(value, *, index=-1, write=True, verify=True, check=True)

Set the value and write to hardware if applicable Writes to hardware are blocking. An error will result in a logged exception.

Parameters:
  • value (Any) – Value to set.

  • index (int, default: -1) – Optional index for array variables.

  • write (bool, default: True) – If True, perform a write transaction.

  • verify (bool, default: True) – If True, verify after write.

  • check (bool, default: True) – If True, wait for the transaction to complete.

Return type:

None

setDisp(sValue, write=True, index=-1)

Set the value of the variable using a string representation of the value.

Parameters:
  • sValue (str) – Display-formatted value to set.

  • write (bool, default: True) – If True, write the value to the hardware.

  • index (int, default: -1) – Optional index for array variables.

Return type:

None

setPollInterval(interval)

Set the poll interval.

Parameters:

interval (float) – Poll interval to use.

Return type:

None

property typeStr: str

Return the type string for this variable.

property units: str | None

Return the engineering units.

property updateNotify: bool

Return True if update notifications are enabled.

value(index=-1)

Return the current value without reading.

Parameters:

index (int, default: -1) – Optional index for array variables.

Return type:

Any

valueDisp(index=-1)

Return a display string for the current value without reading.

Parameters:

index (int, default: -1) – Optional index for array variables.

Return type:

str

property variableList: list[BaseVariable]

Return a recursive list of variables and commands.

property variables: OrderedDict[str, BaseVariable]

Return direct child variables (excluding commands).

variablesByGroup(incGroups=None, excGroups=None)

Return variables filtered by group.

Return type:

OrderedDict[str, BaseVariable]

Parameters:
write(*, verify=True, check=True)

Force a write of the variable.

Parameters:
  • verify (bool, default: True) – If True, verify after write.

  • check (bool, default: True) – If True, check transaction completion.

Return type:

None