Skip to content

Commit

Permalink
TMCL-Mdoule: Revive the facilities to store parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
trinamic-bp committed Jan 21, 2025
1 parent bca8d3b commit 18cdcd0
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions pytrinamic/modules/tmcl_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import warnings

from typing import Optional, Union
from abc import ABC, abstractmethod


class TMCLModule(object):
Expand Down Expand Up @@ -241,9 +240,10 @@ def category(self):
return self.parent.category


class ParameterApiDevice(ABC):
class ParameterApiDevice:

def get_parameter(self, get_target: Union[Parameter]):
"""Get the value of a parameter using the GAP or GGP command."""
if isinstance(get_target, Parameter):
parameter = get_target
else:
Expand All @@ -261,10 +261,11 @@ def get_parameter(self, get_target: Union[Parameter]):
signed=signed,
)
else:
raise ValueError("Unsupported parameter type.")
raise ValueError("Unsupported ParameterGroup.Category!")
return value

def set_parameter(self, set_target: Union[Parameter, Parameter.Option], value: Optional[Union[int, bool]] = None):
"""Set the value of a parameter using the SAP or SGP command."""
if isinstance(set_target, Parameter):
parameter = set_target
if value is None:
Expand All @@ -288,20 +289,40 @@ def set_parameter(self, set_target: Union[Parameter, Parameter.Option], value: O
value=value,
)
else:
raise ValueError("Unsupported parameter type.")
raise ValueError("Unsupported ParameterGroup.Category!")

def store_parameter(self, store_target: Parameter):
"""Store the value of a parameter using the STAP or STGP command."""
if isinstance(store_target, Parameter):
parameter = store_target
else:
raise ValueError("store_target must be a Parameter!")
if parameter.category == ParameterGroup.Category.AXIS:
return self._store_axis_parameter(
parameter.index,
)
elif parameter.category == ParameterGroup.Category.GLOBAL:
return self._store_global_parameter(
parameter.index,
bank=parameter.block,
)
else:
raise ValueError("Unsupported ParameterGroup.Category!")

@abstractmethod
def _get_axis_parameter(self, index: int, signed: bool):
raise NotImplementedError

@abstractmethod
def _set_axis_parameter(self, index: int, value: int):
raise NotImplementedError

@abstractmethod
def _get_global_parameter(self, index: int, bank: int, signed: bool):
raise NotImplementedError

@abstractmethod
def _set_global_parameter(self, index: int, bank: int, value: int):
raise NotImplementedError

def _store_axis_parameter(self, index: int):
raise NotImplementedError

def _store_global_parameter(self, index: int, bank: int):
raise NotImplementedError

0 comments on commit 18cdcd0

Please sign in to comment.