Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions examples/check_chassis_battery.py
Comment thread
zoechanzy marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,25 @@ def main(chassis_name: str) -> None:
""" # noqa: D301
try:
physical_channel_names = f"{chassis_name}/BatteryVoltageSensor"
connection_timeout = 10.0
reservation_access = ReservationAccess.READ_ONLY
reservation_group = "admin"
reservation_timeout = 10.0

with Session.initialize_session_with_physical_channels(
None,
physical_channel_names=physical_channel_names,
connection_timeout=connection_timeout,
reservation_access=reservation_access,
reservation_group=reservation_group,
reservation_timeout=reservation_timeout,
) as session:
sensor_lower_critical = session.get_physical_channel_property_double(
physical_channel_names=physical_channel_names,
property_name="SensorLowerCritical",
physical_channel_names=physical_channel_names,
)
sensor_reading = session.get_physical_channel_property_double(
physical_channel_names=physical_channel_names,
property_name="SensorReading",
physical_channel_names=physical_channel_names,
)
health_state = session.get_physical_channel_property_string(
physical_channel_names=physical_channel_names,
property_name="HealthState",
physical_channel_names=physical_channel_names,
)
needs_replacement = sensor_reading < sensor_lower_critical

Expand Down
5 changes: 0 additions & 5 deletions examples/reset_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ def main(device_names: str) -> None:
reset_device SLSC-12001-XXXXXXXX-Mod1,SLSC-12001-XXXXXXXX-Mod2
""" # noqa: D301
try:
connection_timeout = 10.0
reservation_access = ReservationAccess.READ_ONLY
reservation_group = "admin"
reservation_timeout = 10.0

with Session.initialize_session_with_devices(
None,
device_names=device_names,
connection_timeout=connection_timeout,
reservation_access=reservation_access,
reservation_group=reservation_group,
reservation_timeout=reservation_timeout,
) as session:
session.reset_devices(device_names)
print(f"Reset command sent to device(s) {device_names}")
Expand Down
15 changes: 5 additions & 10 deletions examples/show_command_and_property_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,13 @@ def get_command_and_property_tree(device_name: str) -> dict:
Returns:
Dictionary containing the command and property tree of the device.
"""
connection_timeout = 10.0
reservation_access = ReservationAccess.READ_ONLY
reservation_group = "admin"
reservation_timeout = 10.0

with Session.initialize_session_with_devices(
None,
device_name,
connection_timeout,
reservation_access,
reservation_group,
reservation_timeout,
) as session:

data = {
Expand All @@ -70,18 +65,18 @@ def get_command_and_property_tree(device_name: str) -> dict:
}

device_commands = session.get_device_property_string_array(
device_name,
DeviceProperty.COMMANDS,
device_name,
)

device_properties = session.get_device_property_string_array(
device_name,
DeviceProperty.PROPERTIES,
device_name,
)

device_physical_channels = session.get_device_property_string_array(
device_name,
DeviceProperty.PHYSICAL_CHANNELS,
device_name,
)

for physical_channel in device_physical_channels:
Expand Down Expand Up @@ -138,10 +133,10 @@ def get_command_and_property_tree(device_name: str) -> dict:
for physical_channel in device_physical_channels:

physical_channel_commands = session.get_physical_channel_property_string_array(
physical_channel, PhysicalChannelProperty.COMMANDS
PhysicalChannelProperty.COMMANDS, physical_channel
)
physical_channel_properties = session.get_physical_channel_property_string_array(
physical_channel, PhysicalChannelProperty.PROPERTIES
PhysicalChannelProperty.PROPERTIES, physical_channel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkeryan With $DefaultPhysChans and $DefaultDevices set, we have to put the physical_channel and device_name to the back. Feels a bit weird (I am still fine with it).
Alternative is having positional arguments default to None or "", then we error out if not set. But that will probably mess the docstring and IntelliSense. Thoughts?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it seems a little weird.

The approach used by other NI driver APIs for Python is to have a collection of objects (e.g. nidaqmx channels or MI repeated capabilities) that returns proxy objects with the 1st parameter bound (e.g. device).

# session.devices["Mod1"] returns a Device object that is bound to Mod1
session.devices["Mod1"].set_property_string_array(XYZ, ["a","b","c"]) # passes Mod1 for 1st parameter

SLSC is not an IVI driver, but the new Python IVI spec also uses this approach.

The collection can expose a separate property that returns a proxy that is bound to $DeviceDevices:

# session.devices.default returns a Device object that is bound to $DefaultDevices
session.devices.default.set_property_string_array(XYZ, ["a","b","c"]) # passes $DefaultDevices for 1st parameter

That is a bigger API change, though. Working within the current API, I think it would be ok for (get|set)_device_xyz(), (get|set)_phys_chan_xyz(), (get|set)_nvmem_bytes(), etc. to not have a default for the "active context" (1st parameter that specifies which device/physchan/nvmem you are accessing).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the default "active context" parameter, users can still write session.set_device_property_string_array("$DefaultDevices", XYZ, ["a","b","c"]).

Also, I think that defining constants for the resource aliases like DEFAULT_DEVICES_ALIAS = "$DefaultDevices" would make them more discoverable.

@zoechanzy zoechanzy Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(get|set)_device_xyz(), (get|set)_phys_chan_xyz(), (get|set)_nvmem_bytes(), etc. to not have a default for the "active context" (1st parameter that specifies which device/physchan/nvmem you are accessing)

I think there is a few ways to address it:
Method1:
drop devices, physChans or nvmemAreas default value of (get|set)_device_xyz(), (get|set)_phys_chan_xyz(), (get|set)_nvmem_bytes(), etc from nislscapi.json directly

Method2:
Remain devices, physChans or nvmemAreas default value of (get|set)_device_xyz(), (get|set)_phys_chan_xyz(), (get|set)_nvmem_bytes(), etc in nislscapi.json. Add addtional function in function_helpers.py to ignore the corresponding default values in the setter / getter, etc

I think method 1 is easier and straight-forward.

)

for physical_channel_command in physical_channel_commands:
Expand Down
20 changes: 20 additions & 0 deletions generated/nislsc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@
class StrEnum(str, Enum):
"""StrEnum fallback for Python versions < 3.11."""

CONNECTED_DEVICES_ALIAS = "$ConnectedDevices"
"""A resource alias representing the session's connected devices."""

DEFAULT_DEVICES_ALIAS = "$DefaultDevices"
"""A resource alias representing the session's default devices."""

DEFAULT_NVMEM_AREAS_ALIAS = "$DefaultNVMEMAreas"
"""A resource alias representing the session's default NVMEM areas."""

DEFAULT_PHYS_CHANS_ALIAS = "$DefaultPhysChans"
"""A resource alias representing the session's default physical channels."""

RESERVED_DEVICES_ALIAS = "$ReservedDevices"
"""A resource alias representing the session's reserved devices."""

SESSION_ALIAS = "$Session"
"""A resource alias for accessing session properties."""

SYSTEM_ALIAS = "$System"
"""A resource alias for accessing system properties."""

class ReservationAccess(Enum):
"""Define SLSC reservation access modes."""
Expand Down
Loading