-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathpersisted_task.py
117 lines (92 loc) · 3.39 KB
/
persisted_task.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from nidaqmx import task
from nidaqmx import utils
__all__ = ['PersistedTask']
class PersistedTask:
"""
Represents a saved DAQmx task.
Use the DAQmx Persisted Task properties to query information about
programmatically saved tasks.
"""
__slots__ = ['_name', '_interpreter', '__weakref__']
def __init__(self, name, *, grpc_options=None):
"""
Args:
name (str): Specifies the name of the saved task.
grpc_options (Optional[:class:`~nidaqmx.GrpcSessionOptions`]): Specifies
the gRPC session options.
"""
self._name = name
self._interpreter = utils._select_interpreter(grpc_options)
def __eq__(self, other):
if isinstance(other, self.__class__):
return self._name == other._name
return False
def __hash__(self):
return hash(self._name)
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return f'PersistedTask(name={self._name})'
@property
def name(self):
"""
str: Indicates the name of the task.
"""
return self._name
@property
def author(self):
"""
str: Indicates the author of the task.
"""
val = self._interpreter.get_persisted_task_attribute_string(self._name, 0x22cc)
return val
@property
def allow_interactive_editing(self):
"""
bool: Indicates whether the task can be edited in the DAQ
Assistant.
"""
val = self._interpreter.get_persisted_task_attribute_bool(self._name, 0x22cd)
return val
@property
def allow_interactive_deletion(self):
"""
bool: Indicates whether the task can be deleted through MAX.
"""
val = self._interpreter.get_persisted_task_attribute_bool(self._name, 0x22ce)
return val
def delete(self):
"""
Deletes this task from MAX.
This function does not clear the copy of the task stored in memory.
Use the DAQmx Clear Task function to clear that copy of the task.
"""
self._interpreter.delete_saved_task(self._name)
def load(self):
"""
Loads this saved task.
If you use this function to load a task, you must use DAQmx Clear
Task to destroy it.
Returns:
nidaqmx.task.Task: Indicates the loaded Task object.
"""
task_handle, close_on_exit = self._interpreter.load_task(self._name)
return task._TaskAlternateConstructor(task_handle, self._interpreter, close_on_exit)
class _PersistedTaskAlternateConstructor(PersistedTask):
"""
Provide an alternate constructor for the PersistedTask object.
This is a private API used to instantiate a PersistedTask with an existing interpreter.
"""
# Setting __slots__ avoids TypeError: __class__ assignment: 'Base' object layout differs from 'Derived'.
__slots__ = ()
def __init__(self, name, interpreter):
"""
Args:
name: Specifies the name of the PersistedTask.
interpreter: Specifies the interpreter instance.
"""
self._name = name
self._interpreter = interpreter
# Use meta-programming to change the type of this object to Scale,
# so the user isn't confused when doing introspection.
self.__class__ = PersistedTask # type: ignore[assignment]