Device & Property objects#
pymmcore-plus
offers two classes that provide a more object-oriented interface
to common operations and queries performed on devices and their properties.
In the original CMMCore
API, there are a lot of methods that accept a
deviceLabel
string as the first argument (and perhaps additional arguments)
and query something about that device (e.g.
getDeviceLibrary
,
getDeviceType
,
waitForDevice
, etc...). In pymmcore-plus
, the
Device
class acts as a "view" onto a specific device, and
these methods are implemented as methods (that no longer require the deviceLabel
argument),
and the deviceLabel
is passed to the constructor.
Similarly, there are many methods in the CMMCore
API that require both a
device label and a device property name, and modify that specific property (e.g.
isPropertySequenceable
,
getProperty
,
isPropertyReadOnly
, etc...). Here, the
DeviceProperty
class acts as a "view" onto a specific
device property, with an object-oriented interface to these methods.
pymmcore_plus.DeviceAdapter
#
Convenience view onto a device-adapter library.
This is the type of object that is returned by
pymmcore_plus.CMMCorePlus.getAdapterObject
Parameters:
Name | Type | Description | Default |
---|---|---|---|
library_name |
str
|
Device this property belongs to |
required |
mmcore |
CMMCorePlus
|
CMMCorePlus instance |
required |
Source code in pymmcore_plus/core/_adapter.py
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 |
|
available_devices() -> tuple[Device, ...]
property
#
Get available devices offered by this device adapter.
Returns:
Type | Description |
---|---|
tuple[Device, ...]
|
Tuple of |
Source code in pymmcore_plus/core/_adapter.py
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 |
|
core() -> CMMCorePlus
property
#
Return the CMMCorePlus
instance to which this Device is bound.
Source code in pymmcore_plus/core/_adapter.py
36 37 38 39 |
|
loaded_devices() -> tuple[Device, ...]
property
#
Get currently loaded devices controlled this adapter.
Returns:
Type | Description |
---|---|
tuple[Device, ...]
|
Tuple of loaded |
Source code in pymmcore_plus/core/_adapter.py
70 71 72 73 74 75 76 77 78 79 |
|
name() -> str
property
#
Return the short name of this device adapter library.
Source code in pymmcore_plus/core/_adapter.py
31 32 33 34 |
|
unload() -> None
#
Forcefully unload this library.
Source code in pymmcore_plus/core/_adapter.py
81 82 83 |
|
pymmcore_plus.Device
#
Convenience object-oriented device API.
This is the type of object that is returned by
pymmcore_plus.CMMCorePlus.getDeviceObject
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_label |
str
|
Device label assigned to this device. |
UNASSIGNED
|
mmcore |
CMMCorePlus
|
CMMCorePlus instance that owns this device. |
None
|
Examples:
>>> core = CMMCorePlus()
>>> device = Device("Camera", core)
>>> device.isLoaded()
>>> device.load("NotALib", "DCam") # useful error
>>> device.load("DemoCamera", "DCam")
>>> device.initialize()
>>> device.load("DemoCamera", "DCam") # no-op w/ useful warning
>>> device.properties # tuple of DeviceProperty objects
>>> device.description()
>>> device.isBusy()
>>> device.wait()
>>> device.type()
>>> device.schema() # JSON schema of device properties
Source code in pymmcore_plus/core/_device.py
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
UNASSIGNED = '__UNASSIGNED__'
class-attribute
#
propertyChanged = _DevicePropValueSignal(device_label, None, mmcore)
instance-attribute
#
core() -> CMMCorePlus
property
#
Return the CMMCorePlus
instance to which this Device is bound.
Source code in pymmcore_plus/core/_device.py
134 135 136 137 |
|
create(device_label: str, mmcore: CMMCorePlus) -> Self
classmethod
#
Source code in pymmcore_plus/core/_device.py
59 60 61 62 63 64 65 66 67 |
|
delayMs() -> float
#
Return action delay in ms for this device.
Source code in pymmcore_plus/core/_device.py
143 144 145 |
|
description() -> str
#
Return device description.
Source code in pymmcore_plus/core/_device.py
155 156 157 |
|
detect() -> DeviceDetectionStatus
#
Tries to communicate to device through a given serial port.
Used to automate discovery of correct serial port. Also configures the serial port correctly.
Source code in pymmcore_plus/core/_device.py
257 258 259 260 261 262 263 |
|
getParentLabel() -> str
#
Return the parent device label of this device.
Source code in pymmcore_plus/core/_device.py
287 288 289 |
|
getProperty(property_name: str) -> str
#
Get a device property value.
Source code in pymmcore_plus/core/_device.py
200 201 202 |
|
getPropertyObject(property_name: str) -> DeviceProperty
#
Return a DeviceProperty
object bound to this device on this core.
Source code in pymmcore_plus/core/_device.py
176 177 178 179 180 |
|
get_subclass(device_label: str, mmcore: CMMCorePlus) -> type[Device]
classmethod
#
Source code in pymmcore_plus/core/_device.py
69 70 71 72 |
|
initialize() -> None
#
Initialize device.
Source code in pymmcore_plus/core/_device.py
204 205 206 |
|
isBusy() -> bool
#
Return busy status for this device.
Source code in pymmcore_plus/core/_device.py
139 140 141 |
|
isLoaded() -> bool
#
Return True
if device is loaded.
Source code in pymmcore_plus/core/_device.py
212 213 214 |
|
label() -> str
property
writable
#
Return the assigned label of this device.
Source code in pymmcore_plus/core/_device.py
121 122 123 124 |
|
library() -> str
#
Return device library (aka module, device adapter) name.
Source code in pymmcore_plus/core/_device.py
159 160 161 |
|
load(adapter_name: str = '', device_name: str = '', device_label: str = '') -> Device
#
Load device from the plugin library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adapter_name |
str
|
The name of the device adapter module (short name, not full file name).
(This is what is returned by |
''
|
device_name |
str
|
The name of the device. The name must correspond to one of the names
recognized by the specific plugin library. (This is what is returned by
|
''
|
device_label |
str
|
The name to assign to the device. If not specified, the device will be
assigned a default name: |
''
|
Source code in pymmcore_plus/core/_device.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
name() -> str
#
Return the device name (this is not the same as the assigned label).
Source code in pymmcore_plus/core/_device.py
163 164 165 |
|
properties() -> tuple[DeviceProperty, ...]
property
#
Get all properties supported by device as DeviceProperty objects.
Source code in pymmcore_plus/core/_device.py
171 172 173 174 |
|
propertyNames() -> tuple[str, ...]
#
Return all property names supported by this device.
Source code in pymmcore_plus/core/_device.py
167 168 169 |
|
schema() -> DeviceSchema
#
Return dict in JSON-schema format for properties of device_label
.
Source code in pymmcore_plus/core/_device.py
279 280 281 |
|
setDelayMs(delayMs: float) -> None
#
Override the built-in value for the action delay.
Source code in pymmcore_plus/core/_device.py
147 148 149 |
|
setParentLabel(parent_label: str) -> None
#
Set the parent device label of this device.
Source code in pymmcore_plus/core/_device.py
291 292 293 |
|
setProperty(property_name: str, value: bool | float | int | str) -> None
#
Set a device property value.
See also,
Device.getPropertyObject
.
Examples:
>>> camera = Device("Camera")
>>> camera.setProperty("Exposure", 100)
>>> print(camera.getProperty("Exposure"))
# or
>>> exposure = camera.getPropertyObject("Exposure")
>>> exposure.value = 100
>>> print(exposure.value)
Source code in pymmcore_plus/core/_device.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
supportsDetection() -> bool
#
Return whether or not the device supports automatic device detection.
(i.e. whether or not detectDevice() may be safely called).
Source code in pymmcore_plus/core/_device.py
265 266 267 268 269 270 271 272 273 |
|
type() -> DeviceType
#
Return device type.
Source code in pymmcore_plus/core/_device.py
275 276 277 |
|
unload() -> None
#
Unload device from the core and adjust all configuration data.
Source code in pymmcore_plus/core/_device.py
208 209 210 |
|
usesDelay() -> bool
#
Return True
if the device will use the delay setting or not.
Source code in pymmcore_plus/core/_device.py
151 152 153 |
|
wait() -> None
#
Block the calling thread until device becomes non-busy.
Source code in pymmcore_plus/core/_device.py
283 284 285 |
|
pymmcore_plus.DeviceProperty
#
Convenience view onto a device property.
This is the type of object that is returned by
pymmcore_plus.CMMCorePlus.getPropertyObject
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_label |
str
|
Device this property belongs to |
required |
property_name |
str
|
Name of this property |
required |
mmcore |
CMMCorePlus
|
CMMCorePlus instance |
required |
Examples:
>>> core = CMMCorePlus()
>>> prop = DeviceProperty("Objective", "Label", core)
>>> prop.isValid() # points to a loaded device property in core
>>> prop.value
>>> prop.value = "Objective-2" # setter
>>> prop.isReadOnly()
>>> prop.hasLimits()
>>> prop.range()
>>> prop.dict() # all the info in one dict.
Source code in pymmcore_plus/core/_property.py
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
InfoDict = InfoDict
class-attribute
#
device = device_label
instance-attribute
#
name = property_name
instance-attribute
#
allowedValues() -> tuple[str, ...]
#
Return allowed values for this property, if contstrained.
Source code in pymmcore_plus/core/_property.py
151 152 153 154 155 156 157 158 159 160 161 |
|
core() -> CMMCorePlus
property
#
Return the CMMCorePlus
instance to which this Property is bound.
Source code in pymmcore_plus/core/_property.py
64 65 66 67 68 69 70 71 72 |
|
deviceType() -> DeviceType
#
Return DeviceType
of the device owning this property.
Source code in pymmcore_plus/core/_property.py
147 148 149 |
|
dict() -> InfoDict
#
Return dict of info about this Property.
Returns an InfoDict
with the
following keys: "valid", "value", "type", "device_type", "read_only",
"pre_init", "range", "allowed"
.
If the device is invalid or not loaded, the "valid"
key will be False
and the rest of the keys will be None
.
Source code in pymmcore_plus/core/_property.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
fromCache() -> Any
#
Return cached property value.
Source code in pymmcore_plus/core/_property.py
99 100 101 |
|
hasLimits() -> bool
#
Return True
if property has limits.
Source code in pymmcore_plus/core/_property.py
127 128 129 |
|
isLoaded() -> bool
#
Return true if the device name is loaded.
Source code in pymmcore_plus/core/_property.py
82 83 84 |
|
isPreInit() -> bool
#
Return True
if property must be defined prior to initialization.
Source code in pymmcore_plus/core/_property.py
123 124 125 |
|
isReadOnly() -> bool
#
Return True
if property is read only.
Source code in pymmcore_plus/core/_property.py
119 120 121 |
|
isSequenceable() -> bool
#
Return True
if property can be used in a sequence.
Source code in pymmcore_plus/core/_property.py
163 164 165 |
|
isValid() -> bool
#
Return True
if device is loaded and has a property by this name.
Source code in pymmcore_plus/core/_property.py
78 79 80 |
|
loadSequence(eventSequence: Sequence[str]) -> None
#
Transfer a sequence of events/states/whatever to the device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eventSequence |
Sequence[str]
|
The sequence of events/states that the device will execute in response to external triggers |
required |
Source code in pymmcore_plus/core/_property.py
171 172 173 174 175 176 177 178 179 180 |
|
lowerLimit() -> float
#
Return lower limit if property has limits, or 0 otherwise.
Source code in pymmcore_plus/core/_property.py
131 132 133 |
|
range() -> tuple[float, float]
#
Return (lowerLimit, upperLimit) range tuple.
Source code in pymmcore_plus/core/_property.py
139 140 141 |
|
sequenceMaxLength() -> int
#
Return maximum number of property events that can be put in a sequence.
Source code in pymmcore_plus/core/_property.py
167 168 169 |
|
setValue(val: Any) -> None
#
Functional alternate to property setter.
Source code in pymmcore_plus/core/_property.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
startSequence() -> None
#
Start an ongoing sequence of triggered events in a property.
Source code in pymmcore_plus/core/_property.py
182 183 184 |
|
stopSequence() -> None
#
Stop an ongoing sequence of triggered events in a property.
Source code in pymmcore_plus/core/_property.py
186 187 188 |
|
type() -> PropertyType
#
Return PropertyType
of this property.
Source code in pymmcore_plus/core/_property.py
143 144 145 |
|
upperLimit() -> float
#
Return upper limit if property has limits, or 0 otherwise.
Source code in pymmcore_plus/core/_property.py
135 136 137 |
|
value() -> Any
property
writable
#
Return current property value, cast to appropriate type if applicable.
Source code in pymmcore_plus/core/_property.py
86 87 88 89 90 91 92 |
|
valueChanged() -> _DevicePropValueSignal
property
cached
#
Source code in pymmcore_plus/core/_property.py
74 75 76 |
|