pycertifspec.Client #
Client Objects #
class Client()
Connection to SPEC
You should only need one instance of this class and use it to create Motor, Variable, etc. instances
__init__ #
| __init__(host: str = "localhost", port: int = None, port_range: Tuple[int, int] = (6510, 6530), ports: List[int] = [], timeout: float = 0.5, log_messages: bool = False)
Attempt to create a connection to SPEC
Attributes:
hoststring - The address of the SPEC serverportint - If exact port is known, the port to connect toport_rangetuple[int] - Range of ports to scan (end is inclusive)portslist[int] - List of ports to scantimeoutfloat - Time to wait for answer before trying the next portlog_messagesboolean - Print all incoming SpecMessages
subscribe #
| subscribe(prop: str, callback: Callable[[SpecMessage], None], nowait: bool = False, timeout: float = 0.2) -> bool
Subscribe to changes in a property.
Arguments:
propstring - The name of the propertycallbackfunction - The function to be called when the event is received. Will also be called immediately after subscribingnowaitboolean - By default the function waits for the first event after registering to see if an error occurred. To skip that set Truetimeoutfloat - The timeout to wait for a response after subscribing. Function returns False when it runs out
Returns:
True if successful, False when timeout reached
unsubscribe #
| unsubscribe(prop: str, callback: Callable[[SpecMessage], None]) -> bool
Unsubscribe from changes in the property.
Arguments:
propstring - To property to unsubscribe fromcallbackfunction - The callback function
Returns:
(boolean)- True if the callback was removed, False if it didn’t exist anyways
run #
| run(console_command: str, blocking: bool = True, callback: Callable[[SpecMessage, str], None] = None) -> Tuple[SpecMessage, str]
Execute a command like from the interactive SPEC console
Arguments:
console_commandstring - The command to executeblockingboolean - When True, the function will block until it receives a response from SPEC and return the responsecallbackfunction - When blocking=False, the response will instead be send to the callback function. Expected to accept 2 positional arguments: data, console_output
Returns:
Tuple[SpecMessage, str]: If blocking, the response message from the server and what would be printed to console
set #
| set(prop: str, value: Any, wait_for_error: float = 0.2)
Set a property.
Attributes:
prop_namestring - The name of the propertyvalue- The value (will be converted to string before sending)wait_for_errorfloat - SPEC only sends a message back if the property doesn’t exist. Set the number of seconds to wait for an error message (if there is one)
get #
| get(prop: str, force_fetch: bool = False) -> SpecMessage
Get a property.
Attributes:
prop_namestring - The name of the propertyforce_fetchboolean - If the property is watched, force fetch the value from SPEC
Returns:
(SpecMessage)- None if property doesn’t exist. Else SpecMessage
watch #
| watch(prop: str) -> bool
Listen for changes in prop to speed up .get() method
Arguments:
propstring - Name of the prop to watch
Returns:
(boolean)- True if successful
unwatch #
| unwatch(prop: str)
Stop listening for changes in prop
Arguments:
propstring - Name of the prop to stop watching
motor #
| motor(mne: str) -> Motor
Get the motor as an object
Arguments:
mnestring - The mnemonic name of the motor
Returns:
(Motor)- The motor
var #
| var(name: str, dtype: Type = str) -> Union[Var, ArrayVar]
Get the variable as an object
Arguments:
namestring - The name of the variabledtypeType - The type of the variable
Returns:
(Var or ArrayVar): The variable
abort #
| abort()
Abort all running commands
motors #
| @property
| motors() -> List[str]
List of all available motor mnemonic names
Returns:
(List[str])- List of all motor names
motor_names #
| @property
| motor_names() -> 'OrderedDict[str, str]'
Dict of all available motor mnemonic and pretty names
Returns:
(OrderedDict[str, str]): Dict with mnemonic names as keys and pretty names as values
count #
| count(time: float, callback: Callable = None, refresh_names: bool = False) -> Dict[str, float]
Counts scalers for the time specified. This function is blocking. The callback function will receive occasional updates during counting and when counting is finished.
Arguments:
timefloat - The time to count in secondscallbackfunction - Callback function for updates during countingrefresh_namesboolean - If True, counter names will be refreshed before starting to count. Only necessary if a counter has been added or removed since the script started.
Returns:
(Dict[str, float]): Counter values
stop_counting #
| stop_counting()
Stop counting immediately. Will also cause .count() call to return if started in different thread.