Instrument management
Use the InstrumentManager() to start experiments and control your PalmSens instrument.
The most high-level way to start a measurement is to use the measure() function:
>>> import pypalmsens as ps
>>> method = ps.CyclicVoltammetry()
>>> ps.measure(method)
You can also manage the connection yourself, using connect(), for example:
>>> with ps.connect() as manager:
... method = ps.ChronoAmperometry()
... measurement = manager.measure(method)
Or using InstrumentManager() directly as a context manager:
>>> instruments = discover()
>>> with ps.InstrumentManager(instruments[0]) as manager:
... measurement = manager.measure(method)
Or managing the instrument connection yourself:
>>> instruments = discover()
>>> manager = ps.InstrumentManager(instruments[0])
>>> manager.connect()
>>> # ...
>>> manager.disconnect()
For more information, see the measurement documentation.
pypalmsens
Classes:
-
Instrument–Dataclass holding instrument info.
-
InstrumentManager–Instrument manager for PalmSens instruments.
-
InstrumentPool–Manages a set of instrument.
Functions:
-
connect–Connect to instrument and return InstrumentManager.
-
discover–Discover instruments.
-
measure–Run measurement.
Instrument
dataclass
Dataclass holding instrument info.
Methods:
Attributes:
-
id(str) –Device ID of the instrument.
-
name(str) –Name of the instrument.
-
channel(int) –Channel index if part of a multichannel device.
-
interface(str) –Type of the connection.
-
device(Device) –Device connection class.
-
baudrate(int) –Baud rate.
channel
class-attribute
instance-attribute
Channel index if part of a multichannel device.
Returns -1 if instrument is not part of a multichannel device.
device
class-attribute
instance-attribute
device: Device = field(repr=False)
Device connection class.
from_port
classmethod
from_port(port: str, *, baudrate: int | None = None) -> Instrument
Create serial port instrument class.
Parameters:
-
(portstr) –Name of the port to connect to.
-
(baudrateint, default:None) –Set the baudrate. If None, use the default baudrate.
Returns:
-
instrument(Instrument) –Instrument dataclass
Source code in src/pypalmsens/_instruments/instrument.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
from_ip
classmethod
from_ip(hostname: str, port: int = 49152) -> Instrument
Create TCP instrument class.
Use this method to connect to a device that is connected to the network, like a Nexus.
Parameters:
Returns:
-
instrument(Instrument) –Instrument dataclass
Source code in src/pypalmsens/_instruments/instrument.py
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 | |
InstrumentManager
InstrumentManager(instrument: Instrument)
Instrument manager for PalmSens instruments.
Parameters:
-
(instrumentInstrument) –Instrument to connect to, use
discover()to find connected instruments.
Methods:
-
supported_methods–List methods supported by this device.
-
supported_current_ranges–List current ranges supported by this device.
-
supported_applied_current_ranges–List applied current ranges supported by this device.
-
supported_bipot_ranges–List applied current ranges supported by this device.
-
supported_potential_ranges–List applied potential ranges supported by this device.
-
is_measuring–Return True if device is measuring.
-
is_connected–Return True if an instrument connection exists.
-
ensure_connection–Raises connection error if the instrument is not connected.
-
connect–Connect to instrument.
-
status–Get status.
-
set_cell–Turn the cell on or off.
-
read_current–Read the current in µA.
-
get_current_range–Get the current range for the cell.
-
set_current_range–Set the current range for the cell.
-
read_potential–Read the potential in V.
-
set_potential–Set the potential of the cell.
-
get_potential_range–Get the potential range for the cell.
-
set_potential_range–Set the potential range for the cell.
-
get_instrument_serial–Return instrument serial number.
-
validate_method–Validate method.
-
measure–Start measurement using given method parameters.
-
wait_digital_trigger–Wait for digital trigger.
-
abort–Abort measurement.
-
initialize_multiplexer–Initialize the multiplexer.
-
set_mux8r2_settings–Set the settings for the Mux8R2 multiplexer.
-
set_multiplexer_channel–Sets the multiplexer channel.
-
disconnect–Disconnect from the instrument.
Attributes:
-
instrument(Instrument) –Instrument to connect to.
Source code in src/pypalmsens/_instruments/instrument_manager.py
112 113 114 115 116 | |
supported_methods
supported_methods() -> list[AllowedMethods]
List methods supported by this device.
Returns:
-
methods(list[AllowedMethods]) –List of supported methods.
Source code in src/pypalmsens/_instruments/instrument_manager_async.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
supported_current_ranges
supported_current_ranges() -> list[AllowedCurrentRanges]
List current ranges supported by this device.
Returns:
-
current_ranges(list[AllowedCurrentRanges]) –List of supported current ranges.
Source code in src/pypalmsens/_instruments/instrument_manager_async.py
138 139 140 141 142 143 144 145 146 147 148 149 | |
supported_applied_current_ranges
supported_applied_current_ranges() -> list[AllowedCurrentRanges]
List applied current ranges supported by this device.
Returns:
-
current_ranges(list[AllowedCurrentRanges]) –List of supported current ranges.
Source code in src/pypalmsens/_instruments/instrument_manager_async.py
151 152 153 154 155 156 157 158 159 160 161 162 | |
supported_bipot_ranges
supported_bipot_ranges() -> list[AllowedCurrentRanges]
List applied current ranges supported by this device.
Returns:
-
current_ranges(list[AllowedCurrentRanges]) –List of supported current ranges.
Source code in src/pypalmsens/_instruments/instrument_manager_async.py
164 165 166 167 168 169 170 171 172 173 174 175 | |
supported_potential_ranges
supported_potential_ranges() -> list[AllowedPotentialRanges]
List applied potential ranges supported by this device.
Returns:
-
potential_ranges(list[AllowedPotentialRanges]) –List of supported potential ranges.
Source code in src/pypalmsens/_instruments/instrument_manager_async.py
177 178 179 180 181 182 183 184 185 186 187 188 | |
is_measuring
is_measuring() -> bool
Return True if device is measuring.
Source code in src/pypalmsens/_instruments/instrument_manager.py
132 133 134 | |
is_connected
is_connected() -> bool
Return True if an instrument connection exists.
Source code in src/pypalmsens/_instruments/instrument_manager.py
152 153 154 155 156 157 158 159 | |
ensure_connection
ensure_connection()
Raises connection error if the instrument is not connected.
Source code in src/pypalmsens/_instruments/instrument_manager.py
161 162 163 164 | |
connect
connect() -> None
Connect to instrument.
Source code in src/pypalmsens/_instruments/instrument_manager.py
166 167 168 169 170 171 172 173 174 175 176 177 | |
status
status() -> Status
Get status.
Source code in src/pypalmsens/_instruments/instrument_manager.py
179 180 181 182 183 184 | |
set_cell
Turn the cell on or off.
Parameters:
-
(cell_onbool) –If true, turn on the cell
Source code in src/pypalmsens/_instruments/instrument_manager.py
186 187 188 189 190 191 192 193 194 195 | |
read_current
read_current() -> float
Read the current in µA.
Returns:
-
current(float) –Current in µA.
Source code in src/pypalmsens/_instruments/instrument_manager.py
197 198 199 200 201 202 203 204 205 206 207 208 | |
get_current_range
get_current_range() -> AllowedCurrentRanges
Get the current range for the cell.
Returns:
-
current_range(AllowedCurrentRanges) –
Source code in src/pypalmsens/_instruments/instrument_manager.py
210 211 212 213 214 215 216 217 218 | |
set_current_range
set_current_range(current_range: AllowedCurrentRanges)
Set the current range for the cell.
Parameters:
-
(current_rangeAllowedCurrentRanges) –Set the current range as a string. See
pypalmsens.settings.AllowedCurrentRangesfor options.
Source code in src/pypalmsens/_instruments/instrument_manager.py
220 221 222 223 224 225 226 227 228 229 230 | |
read_potential
read_potential() -> float
Read the potential in V.
Returns:
-
potential(float) –Potential in V.
Source code in src/pypalmsens/_instruments/instrument_manager.py
232 233 234 235 236 237 238 239 240 241 242 243 244 | |
set_potential
Set the potential of the cell.
Parameters:
-
(potentialfloat) –Potential in V
Source code in src/pypalmsens/_instruments/instrument_manager.py
246 247 248 249 250 251 252 253 254 255 | |
get_potential_range
get_potential_range() -> AllowedPotentialRanges
Get the potential range for the cell.
Returns:
-
potential_range(AllowedPotentialRanges) –
Source code in src/pypalmsens/_instruments/instrument_manager.py
257 258 259 260 261 262 263 264 265 | |
set_potential_range
set_potential_range(potential_range: AllowedPotentialRanges)
Set the potential range for the cell.
Parameters:
-
(potential_rangeAllowedPotentialRanges) –Set the potential range as a string. See
pypalmsens.settings.AllowedPotentialRangesfor options.
Source code in src/pypalmsens/_instruments/instrument_manager.py
267 268 269 270 271 272 273 274 275 276 277 | |
get_instrument_serial
get_instrument_serial() -> str
Return instrument serial number.
Returns:
-
serial(str) –Instrument serial.
Source code in src/pypalmsens/_instruments/instrument_manager.py
279 280 281 282 283 284 285 286 287 288 289 290 | |
validate_method
validate_method(method: Method | BaseTechnique) -> None
Validate method.
Raise MethodIncompatibleError if the method cannot be validated.
Source code in src/pypalmsens/_instruments/instrument_manager.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
measure
measure(method: BaseTechnique, *, callback: Callback | CallbackEIS | None = None) -> Measurement
Start measurement using given method parameters.
Parameters:
-
(methodBaseTechnique) –Method parameters for measurement
-
(callbackCallback | CallbackEIS | None, default:None) –If specified, call this function on every new set of data points. New data points are batched, and contain all points since the last time it was called. Each point is an instance of
ps.data.CallbackDatafor non-impedimetric orps.data.CallbackDataEISfor impedimetric measurments.
Returns:
-
measurement(Measurement) –Finished measurement.
Source code in src/pypalmsens/_instruments/instrument_manager.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
wait_digital_trigger
wait_digital_trigger(wait_for_high: bool)
Wait for digital trigger.
Parameters:
-
(wait_for_highbool) –Wait for digital line high before starting
Source code in src/pypalmsens/_instruments/instrument_manager.py
343 344 345 346 347 348 349 350 351 352 353 354 355 | |
abort
abort() -> None
Abort measurement.
Source code in src/pypalmsens/_instruments/instrument_manager.py
357 358 359 360 | |
initialize_multiplexer
Initialize the multiplexer.
Parameters:
-
(mux_modelint) –The model of the multiplexer. - 0 = 8 channel - 1 = 16 channel - 2 = 32 channel
Returns:
-
channels(int) –Number of available multiplexes channels
Source code in src/pypalmsens/_instruments/instrument_manager.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
set_mux8r2_settings
set_mux8r2_settings(connect_sense_to_working_electrode: bool = False, combine_reference_and_counter_electrodes: bool = False, use_channel_1_reference_and_counter_electrodes: bool = False, set_unselected_channel_working_electrode: int = 0)
Set the settings for the Mux8R2 multiplexer.
Parameters:
-
(connect_sense_to_working_electrodebool, default:False) –Connect the sense electrode to the working electrode. Default is False.
-
(combine_reference_and_counter_electrodesbool, default:False) –Combine the reference and counter electrodes. Default is False.
-
(use_channel_1_reference_and_counter_electrodesbool, default:False) –Use channel 1 reference and counter electrodes for all working electrodes. Default is False.
-
(set_unselected_channel_working_electrodeint, default:0) –Set the unselected channel working electrode to disconnected/floating (0), ground (1), or standby potential (2). Default is 0.
Source code in src/pypalmsens/_instruments/instrument_manager.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
set_multiplexer_channel
Sets the multiplexer channel.
Parameters:
-
(channelint) –Index of the channel to set.
Source code in src/pypalmsens/_instruments/instrument_manager.py
441 442 443 444 445 446 447 448 449 450 | |
disconnect
disconnect()
Disconnect from the instrument.
Source code in src/pypalmsens/_instruments/instrument_manager.py
452 453 454 455 456 457 458 459 | |
InstrumentPool
InstrumentPool(devices_or_managers: Sequence[Instrument | InstrumentManagerAsync])
Manages a set of instrument.
Most calls are run asynchronously in the background, which means that measurements are running in parallel.
This is a thin wrapper around the InstrumentManagerAsync.
Parameters:
-
(devices_or_managerslist[Instrument | InstrumentManagerAsync]) –List of devices or managers.
Methods:
-
connect–Connect all instrument managers in the pool.
-
disconnect–Disconnect all instrument managers in the pool.
-
is_connected–Return true if all managers in the pool are connected.
-
is_disconnected–Return true if all managers in the pool are disconnected.
-
remove–Close and remove manager from pool.
-
add–Open and add manager to the pool.
-
measure–Concurrently run measurement on all managers in the pool.
Attributes:
-
managers(list[InstrumentManagerAsync]) –List of instruments managers in the pool.
Source code in src/pypalmsens/_instruments/instrument_pool.py
31 32 33 34 35 36 37 38 39 | |
managers
instance-attribute
managers: list[InstrumentManagerAsync] = managers
List of instruments managers in the pool.
connect
Connect all instrument managers in the pool.
Parameters:
-
(attemptsint, default:1) –Number of attempts to establish connection. Use this if you experience connection issues via USB.
Source code in src/pypalmsens/_instruments/instrument_pool.py
58 59 60 61 62 63 64 65 66 67 | |
disconnect
disconnect() -> None
Disconnect all instrument managers in the pool.
Source code in src/pypalmsens/_instruments/instrument_pool.py
69 70 71 | |
is_connected
is_connected() -> bool
Return true if all managers in the pool are connected.
Source code in src/pypalmsens/_instruments/instrument_pool.py
73 74 75 | |
is_disconnected
is_disconnected() -> bool
Return true if all managers in the pool are disconnected.
Source code in src/pypalmsens/_instruments/instrument_pool.py
77 78 79 | |
remove
remove(manager: InstrumentManagerAsync) -> None
Close and remove manager from pool.
Parameters:
-
(managerInstrumentManagerAsync) –Instance of an instrument manager.
Source code in src/pypalmsens/_instruments/instrument_pool.py
81 82 83 84 85 86 87 88 89 | |
add
add(manager: InstrumentManagerAsync) -> None
Open and add manager to the pool.
Parameters:
-
(managerInstrumentManagerAsync) –Instance of an instrument manager.
Source code in src/pypalmsens/_instruments/instrument_pool.py
91 92 93 94 95 96 97 98 99 | |
measure
measure(method: BaseTechnique, callback: Sequence[Callback | CallbackEIS] | Callback | CallbackEIS | None = None, **kwargs) -> list[Measurement]
Concurrently run measurement on all managers in the pool.
For hardware synchronization, set .general.use_hardware_sync on the method.
For MethodSCRIPT, use 'set_channel_sync 1'.
In addition, the pool must contain: - channels from a single multichannel instrument only - the first channel of the multichannel instrument - at least two channels
All instruments are prepared and put in a waiting state. The measurements are started via a hardware sync trigger on channel 1.
Parameters:
-
(methodMethodSettings) –Method parameters for measurement.
-
(callbacklist[Callback] | Callback | CallbackEIS | None, default:None) –If specified, call these functions/this function on every new set of data points. New data points are batched, and contain all points since the last time it was called.
Specify a sequence of callbacks to set a different function for every channel. The number of callbacks must match the number of channels.
Specify a single callback to set the same function to all channels.
-
–**kwargsThese keyword parameters are passed to the measure function.
Source code in src/pypalmsens/_instruments/instrument_pool.py
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 | |
connect
connect(instrument: None | Instrument = None) -> InstrumentManager
Connect to instrument and return InstrumentManager.
Connects to any plugged-in PalmSens USB device. Error if multiple devices are plugged-in.
Parameters:
-
(instrumentInstrument, default:None) –Connect to a specific instrument. Use
pypalmsens.discover()to discover instruments.
Returns:
-
manager(InstrumentManager) –Return instance of
InstrumentManagerconnected to the given instrument.
Source code in src/pypalmsens/_instruments/instrument_manager.py
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 | |
discover
discover(ftdi: bool = True, usbcdc: bool = True, winusb: bool = True, bluetooth: bool = False, serial: bool = True, ignore_errors: bool = False) -> list[Instrument]
Discover instruments.
For a list of device interfaces, see: https://dev.palmsens.com/python/latest/_attachments/installation/index.html#compatibility
Parameters:
-
(ftdibool, default:True) –If True, discover ftdi devices
-
(usbcdcbool, default:True) –If True, discover usbcdc devices (Windows only)
-
(winusbbool, default:True) –If True, discover winusb devices (Windows only)
-
(bluetoothbool, default:False) –If True, discover bluetooth devices (Windows only)
-
(serialbool, default:True) –If True, discover serial devices
-
(ignore_errorsFalse, default:False) –Ignores errors in device discovery
Returns:
-
discovered(list[Instrument]) –List of dataclasses with discovered instruments.
Source code in src/pypalmsens/_instruments/instrument.py
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 | |
measure
measure(method: BaseTechnique, instrument: None | Instrument = None, callback: Callback | CallbackEIS | None = None) -> Measurement
Run measurement.
Executes the given method on any plugged-in PalmSens USB device. Error if multiple devices are plugged-in.
Parameters:
-
(instrumentInstrument, default:None) –Connect to and meassure on a specific instrument. Use
pypalmsens.discover()to discover instruments. -
(callbackCallback | CallbackEIS | None, default:None) –If specified, call this function on every new set of data points. New data points are batched, and contain all points since the last time it was called. Each point is an instance of
ps.data.CallbackDatafor non-impedimetric orps.data.CallbackDataEISfor impedimetric measurments.
Returns:
-
measurement(Measurement) –Finished measurement.
Source code in src/pypalmsens/_instruments/instrument_manager.py
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 | |