qass.tools.analyzer.virtual_devices
Virtual devices
This module provides a simplified interface for the virtual devices of the Analyzer4D software. The Analyzer4D software provides an interface that allows to add customized devices that are not handled by the measurement hardware. But the data coming from those virtual devices will be handled in the same way like the time domain signal from the measurement hardware. The data is stored in a so called "Buffer" that works based on equally distanced data. The resulting data streams are completely compatible to other data streams in the software.
Data channels from a virtual device have to be configured in the Analyzer4D software in the multiplexer settings (Configuration->Multiplexer->Virtual input configuration). There the devices can be assigned to measurement ports.
Classes:
| Name | Description |
|---|---|
DeviceTypeCollection |
DeviceClass implements the interface VirtDeviceInterface from the Analyzer4D software. |
MultiStreamVirtualInputDevice |
|
VirtualInputDevice |
VirtualInputDevice is a simplified interface for custom virtual devices in the Analyzer4D software. |
DeviceTypeCollection
Bases: VirtDeviceInterface
DeviceClass implements the interface VirtDeviceInterface from the Analyzer4D software. The functions of this interface are called by the Analyzer4D software. This class is a plugin implementation of the interface.
A DeviceClass is a class of hardware devices. Usually all devices handled by this class work similar to each other and support the same features.
Methods:
| Name | Description |
|---|---|
__init__ |
The constructor expects a . |
applyConfig |
applyConfig is called by the Analyzer4D software to request the device to apply the config. |
capabilities |
capabilites is called by the Analyzer4D software to get information about available devices and their configuration. |
closeInput |
closeInput requests to stop the data collection for the given device. |
createConfigDialog |
createConfigDialog is called by the Analyzer4D software to allow the user to configurate the device. |
createPluginDialog |
createPluginDialog allows to implement a custom dialog for this device type. |
getConfig |
The Analyzer4D software calls this function to make settings persistent in the database. |
init |
This function is called by the Analyzer4D software. |
inputCount |
|
isInputAvailable |
isInputAvailable requests to check whether the given device is available and ready for measurements. |
name |
name |
openInput |
openInput starts the communication and the data fetching for the given device. |
readInput |
readInput fetches and returns the currently available data from the given device's thread. |
setConfig |
setConfig is called after the device initialization to propagate saved settings from the database to the devices themselves. |
versionString |
versionString |
Source code in src/qass/tools/analyzer/virtual_devices.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 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 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
__init__
__init__(devices: List[VirtualInputDevice], name: str = '', version: str = '')
The constructor expects a . The devices are expected to be of the type VirtualInputDevice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
devices
|
list[VirtualInputDevice]
|
List of the device. Their names are used as identifiers and have to be unique inside this DeviceTypeCollection. |
required |
name
|
str
|
The name of this device class, defaults to '' |
''
|
version
|
str
|
The version string of this device class implementation, defaults to '' |
''
|
Source code in src/qass/tools/analyzer/virtual_devices.py
applyConfig
applyConfig is called by the Analyzer4D software to request the device to apply the config. This might include to communicate settings to a device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The device's identifier string |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True on success, False otherwise (if an exception has been raised) |
Source code in src/qass/tools/analyzer/virtual_devices.py
capabilities
capabilites is called by the Analyzer4D software to get information about available devices and their configuration. Especially the sample rate and the capability of configuration dialogs is queried here. The config dict consists of two main keys (inputs, configdialog) The 'inputs' key contains an interface config with the keys (ifaceName : str, sampleRate: float, normalAmplitude: float) The 'configdialog' is a boolean indicating whether a QDialog will be displayed Missing keys in the config will
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing information about this device class and the devices themselves. |
Source code in src/qass/tools/analyzer/virtual_devices.py
closeInput
closeInput requests to stop the data collection for the given device. In this implementation this causes the device's thread to terminate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The device's identifier string |
required |
prepareRestart
|
bool
|
defaults to False |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True on success, False otherwise |
Source code in src/qass/tools/analyzer/virtual_devices.py
createConfigDialog
createConfigDialog is called by the Analyzer4D software to allow the user to configurate the device. This mitght include file paths, IP addresses, Ports, sample rates or other device specific parameters. If the device implementation supports this feature it must return a QDialog instance in its implementation of config_dialog(). This dialog is just forwarded here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The device's identifier string |
required |
Returns:
| Type | Description |
|---|---|
QDialog
|
The configuration QDialog instance. |
Source code in src/qass/tools/analyzer/virtual_devices.py
createPluginDialog
createPluginDialog allows to implement a custom dialog for this device type. This implementation does not use this feature. But you can override this function by subclassing this class...
Returns:
| Type | Description |
|---|---|
QDialog
|
A QDialog instance. |
Source code in src/qass/tools/analyzer/virtual_devices.py
getConfig
The Analyzer4D software calls this function to make settings persistent in the database. This implementation converts a dictionary based configuration from the device to the QByteArray that is expected by the Analyzer4D software.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The device's identifier string |
required |
Returns:
| Type | Description |
|---|---|
QByteArray
|
The byte array - the configuration's textual representation |
Source code in src/qass/tools/analyzer/virtual_devices.py
init
This function is called by the Analyzer4D software. Usually device detection takes part here. We assume in this implementatoin that available devices have been passed in the constructor.
Source code in src/qass/tools/analyzer/virtual_devices.py
inputCount
isInputAvailable
isInputAvailable requests to check whether the given device is available and ready for measurements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The device's identifier string |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the device is available and ready. False otherwise. |
Source code in src/qass/tools/analyzer/virtual_devices.py
name
openInput
openInput starts the communication and the data fetching for the given device. This function starts the device's thread. All communication to the device and the data collection is done inside this thread.
name : str The device's identifier string
Returns:
| Type | Description |
|---|---|
bool
|
True on success, False otherwise |
Source code in src/qass/tools/analyzer/virtual_devices.py
readInput
readInput fetches and returns the currently available data from the given device's thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The device's identifier string |
required |
stream
|
int
|
|
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of available new values. |
Source code in src/qass/tools/analyzer/virtual_devices.py
setConfig
setConfig is called after the device initialization to propagate saved settings from the database to the devices themselves. This function translates the settings from a QByteArray representation to a json dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The device's identifier string |
required |
data
|
QByteArray
|
The byte array containing the textual representation of the device. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True on success, False otherwise (if an exception has been raised) |
Source code in src/qass/tools/analyzer/virtual_devices.py
versionString
versionString
Returns:
| Type | Description |
|---|---|
str
|
The version of this device class implementation. |
MultiStreamVirtualInputDevice
Bases: VirtualInputDevice
Methods:
| Name | Description |
|---|---|
__init__ |
instantiate a MultiStreamVirtualInputDevice. |
apply_config |
|
close_connection |
close_connection() will be called to close the connection to the device (usually at the end of a measurement). |
config_dialog |
If this function returns a QDialog this will be displayed in the Analyzer4D software to setup the device. |
get_config |
|
get_data |
Fetch the data for all streams and convert them to a Tuple of List of floats. |
init_device |
|
is_available |
is_available should indicate whether its possible to establish a connection to the device. |
open_connection |
open_connection() will be called before a measurement. |
set_config |
|
Attributes:
| Name | Type | Description |
|---|---|---|
dont_close |
|
|
name |
|
|
normal_amplitude |
|
|
requests_per_sec |
|
|
sample_rate |
|
|
stream_configs |
|
|
stream_count |
|
Source code in src/qass/tools/analyzer/virtual_devices.py
__init__
__init__(name: str, stream_configs: Tuple[Dict[str, int]], request_rate: float = 100, dont_close: bool = False)
instantiate a MultiStreamVirtualInputDevice. This class is an abstract base class and inherits from VirtualInputDevice. You must derive from this class and implement the abstract funtions to create a custom device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
This is the name of the device that will also be displayed in the GUI. The name is used as an identifier and thus it must be unique inside one DeviceTypeCollection. |
required |
stream_configs
|
tuple[dict[str, int]]
|
This is a list of configs for each stream. The list's length defines the number of streams provided by this device. The config must include at least the following keywords: "stream_name": A string to identify the stream (displayed) "sample_rate": float: The streams sample rate in Hz "normal_amp": The maximum expected value (used for display scaling) |
required |
request_rate
|
float
|
How often the get_data() should be called?, defaults to 100 - meaning 100 calls of get_data() in a second. If zero or None the device communication thread will not sleep but only yieldCurrentThread. This might cause issues since the python interpreter is heavily used by this interface. |
100
|
dont_close
|
bool
|
If True the function open_connection() will be called as early as possible and close_connection() will be called as late as possible. The device connection will not be closed between different processes. If False the method open_connection() will be called at the beginning of each measurement and close_connection() will be called at the end of each measurement. Defaults to False. |
False
|
Source code in src/qass/tools/analyzer/virtual_devices.py
apply_config
close_connection
abstractmethod
close_connection() will be called to close the connection to the device (usually at the end of a measurement). The communication to the device should be completely cleaned up in this function. It is assumed that its save to call open_connection() again after this function returned without error.
raise an exception if needed. It will be handled by the wrapping class DeviceHandler.
Source code in src/qass/tools/analyzer/virtual_devices.py
config_dialog
If this function returns a QDialog this will be displayed in the Analyzer4D software to setup the device. The settings button will only be available in the software if at least one device provides a QDialog and not None in this funciton.
:return: your custom config dialog. Defaults to None. :rtype: type
Source code in src/qass/tools/analyzer/virtual_devices.py
get_config
get_data
abstractmethod
Fetch the data for all streams and convert them to a Tuple of List of floats. The tuple is expected to have stream_count elements. Note: Ensure that the data type is float and not np.float or anything else! This method should always clear the device's buffer containing the data when it's called. This is to prevent old data from persisting.
Returns:
| Type | Description |
|---|---|
tuple[list[float]]
|
The lists of new values for all streams, packed into one tuple. The list must not contain old values! |
Source code in src/qass/tools/analyzer/virtual_devices.py
init_device
is_available
abstractmethod
is_available should indicate whether its possible to establish a connection to the device.
Returns:
| Type | Description |
|---|---|
bool
|
True if the device is available and ready for measurements, False otherwise. |
Source code in src/qass/tools/analyzer/virtual_devices.py
open_connection
abstractmethod
open_connection() will be called before a measurement. The communication to the device should be setup in this function. It is assumed that its save to call get_data after this function returned without error. This function is called at each begin of a measurement. It is called even when the flag "dont_stop" is True. Thus you can reestablish a damaged connection if needed.
raise an exception if needed. It will be handled by the wrapping class DeviceHandler.
Source code in src/qass/tools/analyzer/virtual_devices.py
set_config
Source code in src/qass/tools/analyzer/virtual_devices.py
VirtualInputDevice
Bases: ABC
VirtualInputDevice is a simplified interface for custom virtual devices in the Analyzer4D software. The methods marked with "abstractmethod" must be implemented. The other methods can be overridden if needed.
This class is meant to be used by DeviceHandler (see below). The device handler implements the actual Analyzer4D interface class while using instances of this class for the communication.
Methods:
| Name | Description |
|---|---|
__init__ |
instantiate a VirtualInputDevice. |
apply_config |
|
close_connection |
close_connection() will be called to close the connection to the device (usually at the end of a measurement). |
config_dialog |
If this function returns a QDialog this will be displayed in the Analyzer4D software to setup the device. |
get_config |
|
get_data |
Fetch the data from the device and convert it to a List of floats. |
init_device |
|
is_available |
is_available should indicate whether its possible to establish a connection to the device. |
open_connection |
open_connection() will be called before a measurement. |
set_config |
|
Attributes:
| Name | Type | Description |
|---|---|---|
dont_close |
|
|
name |
|
|
normal_amplitude |
|
|
requests_per_sec |
|
|
sample_rate |
|
|
stream_configs |
|
|
stream_count |
|
Source code in src/qass/tools/analyzer/virtual_devices.py
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 | |
__init__
__init__(name: str, sample_rate: float, normal_amp: float, request_rate: float = 100, dont_close: bool = False)
instantiate a VirtualInputDevice. This class is an abstract base class. You must derive from this class and implement the abstract funtions to create a custom device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
This is the name of the device that will also be displayed in the GUI. The name is used as an identifier and thus it must be unique inside one DeviceTypeCollection. |
required |
sample_rate
|
float
|
This is the sample rate that is used by the Analyzer4D software to build the Data signal stream. All values are assumed to have the same distance in time. |
required |
normal_amp
|
float
|
This is the maximum value that this device will provide. This is used by the Analyzer4D software for the correct scaling. |
required |
request_rate
|
float
|
How often the get_data() should be called?, defaults to 100 - meaning 100 calls of get_data() in a second. If zero or None the device communication thread will not sleep but only yieldCurrentThread. This might cause issues since the python interpreter is heavily used by this interface. |
100
|
dont_close
|
bool
|
If True the function open_connection() will be called as early as possible and close_connection() will be called as late as possible. The device connection will not be closed between different processes. If False the method open_connection() will be called at the beginning of each measurement and close_connection() will be called at the end of each measurement. Defaults to False. |
False
|
Source code in src/qass/tools/analyzer/virtual_devices.py
apply_config
close_connection
abstractmethod
close_connection() will be called to close the connection to the device (usually at the end of a measurement). The communication to the device should be completely cleaned up in this function. It is assumed that its save to call open_connection() again after this function returned without error.
raise an exception if needed. It will be handled by the wrapping class DeviceHandler.
Source code in src/qass/tools/analyzer/virtual_devices.py
config_dialog
If this function returns a QDialog this will be displayed in the Analyzer4D software to setup the device. The settings button will only be available in the software if at least one device provides a QDialog and not None in this funciton.
:return: your custom config dialog. Defaults to None. :rtype: type
Source code in src/qass/tools/analyzer/virtual_devices.py
get_config
get_data
abstractmethod
Fetch the data from the device and convert it to a List of floats. Note: Ensure that the data type is float and not np.float or anything else! This method should always clear the device's buffer containing the data when it's called. This is to prevent old data from persisting.
:return: The list of new values. The list must not contain old values! :rtype: List[float]
Source code in src/qass/tools/analyzer/virtual_devices.py
init_device
is_available
abstractmethod
is_available should indicate whether its possible to establish a connection to the device.
Returns:
| Type | Description |
|---|---|
bool
|
True if the device is available and ready for measurements, False otherwise. |
Source code in src/qass/tools/analyzer/virtual_devices.py
open_connection
abstractmethod
open_connection() will be called before a measurement. The communication to the device should be setup in this function. It is assumed that its save to call get_data after this function returned without error. This function is called at each begin of a measurement. It is called even when the flag "dont_stop" is True. Thus you can reestablish a damaged connection if needed.
raise an exception if needed. It will be handled by the wrapping class DeviceHandler.