10.5. dataIO#
This section contains the script reference to the class dataIO, used to access any dataIO hardware in itom (e.g. cameras, AD-converters or further data communication plugins). Read the overview document for more details about the Python interface of the class dataIO.
- class itom.dataIO(name, *args, **kwds)#
Creates a new instance of the dataIO plugin
name.This is the constructor for an
dataIOplugin. It initialises an new instance of the plugin with the givenname. The initialisation parameters are parsed and unnamed parameters are used in their incoming order to fill first mandatory parameters and afterwards optional parameters. Parameters may be passed with their name as keyword, too. However, as usual, no positional parameters are allowed after a keyword-based one.See
pluginHelp()for detailed information about the specific initialisation parameters.- Parameters:
- name
str is the fullname (case sensitive) of an
dataIO-plugin.- *args
Any Every
actuatorplugin defines a list of mandatory and optional initialization parameters. Pass these arguments either as positional (*args) or keyword based (**kwds) arguments, where the mandatory parameters must be given first, followed by the optional ones. Not every optional initialization argument must be given, else its default value is used.- **kwds
Any Further keyword based parameters. See also
*args.
- name
- Returns:
actuatornew instance of the desired dataIO plugin.
- acquire(trigger=dataIO.TRIGGER_SOFTWARE)#
Triggers a new camera acquisition.
This method triggers a new data acquisition. This method immediately returns even if the acquisition is not finished yet. Use
getVal()orcopyVal()to get the acquired data. Both methods will then block until the data is available or a timeout occurred.Before calling
acquire(), the device must have been started usingstartDevice().- Parameters:
- trigger
int,optional Type of the trigger:
dataIO.TRIGGER_SOFTWARE = 0: a software trigger is started, hence, the acquisition is immediately started when calling this method.others : depending on your camera, this parameter can be used to set other triggers, like hardware trigger with raising or falling edges… Please consider the documentation of the specific device for possible values.
- trigger
- connect(signalSignature, callableMethod, minRepeatInterval=0)#
Connects a signal of this dataIO device with the given callable Python method.
Every
dataIOobject can emit different signals whenever a certain event occurs. Use the methodinfo()to get a print-out of a list of possible signals of the dataIO device. This method is used to connect a certain callable Python callback method or function to a specific signal. The callable function can be bounded as well as unbounded.The connection is described by the string signature of the signal (hence the source of the connection). Such a signature is the name of the signal, followed by the types of its arguments (the original C++ types). An example is
destroyed(), emitted if this device is internally deleted. This signal can be connected to a callback function with no arguments, since the signal has no arguments, too. In case of a bounded method, theselfargument must be given in any case.If the signal should have further arguments with specific datatypes, they are transformed into corresponding Python data types. A table of supported conversions is given in section Supported data types. In general, a
callableMethodmust be a method or function with the same number of parameters than the signal has (besides theselfargument).If a signal is emitted very often, it can be necessary to limit the call of the callback function to a certain minimum time interval. This can be given by the
minRepeatIntervalparameter.- Parameters:
- signalSignature
str This must be the valid signature, known from the Qt-method connect (e.g.
targetChanged(QVector<double>))- callableMethod
callable() valid method or function that is called if the signal is emitted.
- minRepeatInterval
int,optional If > 0, the same signal only invokes a slot once within the given interval (in ms). Default: 0 (all signals will invoke the callable python method.
- signalSignature
See also
- copyVal(destObject)#
Gets deep copy of data of this plugin, stored in the given data object.
Returns a deep copy of the recently acquired data (for grabber and ADDA only) of the camera or AD-converter device. The deep copy sometimes requires one copy operation more than the similar command
getVal(). However,getVal()only returns a reference to the plugin internal data structure whose values might be changed if another data acquisition is started.If no acquisition has been triggered, this method raises a RuntimeError. If the acquisition is not finished yet, this method blocks and waits until the end of the acquisition.
- Parameters:
- destObject
dataObject dataObjectwhere the plugin data is copied to. Either provide an emptydataObjector adataObjectwhose shape exactly fits to the shape of the available data of the plugin. Therefore you can allocate a 3D data object, set a region of interest to one plane such that the data from the plugin is copied into this plane.
- destObject
- Raises:
RuntimeErrorif the dataIO plugin is anything else than ADDA or grabber or if no acquisition has been triggered
See also
- disableAutoGrabbing()#
Disables auto grabbing for this grabber (camera…).
If the auto grabbing flag is set, the camera acquisition is continuously triggered if at least one live image is connected to the camera. The default and minimum interval between two grabs is 20 ms. It can be changed via
setAutoGrabbingInterval(). If the grabbing process is slower, the camera tries to acquire new images as fast as possible.Enabling this auto grabbing mechanism can be undesired behaviour for instance if a measurement is started where the acquisition should be controlled by a specific script or something similar. In this case, disable the auto grabbing property. All connected live images will then get new images only if
getVal()orcopyVal()is called.This method disables the auto grabbing timer.
- disconnect(signalSignature, callableMethod)#
Disconnects a connection which must have been established before with exactly the same parameters.
- Parameters:
- signalSignature
str This must be the valid signature, known from the Qt-method connect (e.g.
clicked(bool))- callableMethod
callable() valid method or function, that should not be called any more if the given signal is emitted.
- signalSignature
- enableAutoGrabbing()#
Enables auto grabbing for the grabber (camera…).
If the auto grabbing flag is set, the camera acquisition is continuously triggered if at least one live image is connected to the camera. The default and minimum interval between two grabs is 20 ms. It can be changed via
setAutoGrabbingInterval(). If the grabbing process is slower, the camera tries to acquire new images as fast as possible.Enabling this auto grabbing mechanism can be undesired behaviour for instance if a measurement is started where the acquisition should be controlled by a specific script or something similar. In this case, disable the auto grabbing property. All connected live images will then get new images only if
getVal()orcopyVal()is called.This method enables the auto grabbing timer.
- exec(funcName, *args, **kwds) Any | Tuple[Any]#
Calls the additional function
funcNameof this plugin.Every plugin can define special, additional functions (denoted as
exec functions) that can for instance be used in order to call specific calibration routines of cameras or actuators. This generic method is used to call one of these specific functions, that has to be registered in the plugin under the namefuncName.Every function can define a set of mandatory and / or optional parameters. See
getExecFuncsInfo()or the plugin help viewer of itom for more information. Pass the mandatory and optional parameters as argumentsparam1,param2… to this method.Additionally, every function can return one or multiple values. Either the single value or a tuple of all returned values is returned by this method.
- Parameters:
- funcName
str The name of the additional function.
- *args
Any Further positional arguments, that are assigned first to all mandatory parameters, followed by the optional ones. The mandatory or optional parameters of the called function can also given as keyword arguments (see
**kwds).- **kwds
Any,optional Keyword-based arguments, see
*argsabove.
- funcName
- Returns:
See also
- getAutoGrabbing() bool#
Returns if the auto grabbing property of this grabber device is enabled or disabled.
If the auto grabbing flag is set, the camera acquisition is continuously triggered if at least one live image is connected to the camera.
Enabling this auto grabbing mechanism can be undesired behaviour for instance if a measurement is started where the acquisition should be controlled by a specific script or something similar. In this case, disable the auto grabbing property. All connected live images will then get new images only if
getVal()orcopyVal()is called.- Returns:
- bool
Trueif the auto grabbing timer is currently active, otherwiseFalse.
See also
- getAutoGrabbingInterval() int#
Returns the current auto grabbing interval (in ms), even if auto grabbing is disabled.
If auto grabbing is enabled for a grabber device, a timer is set that continuously acquires data or images from the devices and sends it to all connected plots or other listeners. The timer event will occur with a certain interval (in ms). However, if the image acquisition requires more time than the interval, several timer events will be automatically omitted, such that the next image is only acquired if the grabber device is in an idle state again. Hence, the interval is considered to be a minimum value.
The default interval of newly started grabber devices in 20 ms.
- Returns:
intthe current auto grabbing timer interval in ms.
- getExecFuncsInfo(funcName='', detailLevel=0) dict | None#
Lists all available additional functions of this plugin or gives a detailed description of one specific
funcName.Every plugin can define further functions, that are called by the method
exec(). This can for instance be used in order to call specific calibration routines of cameras or actuators.This method either prints requested information in a readable form to the command line or returns this information as nested dictionary.
- Parameters:
- funcName
str,optional is the fullname or a part of any name of such an additional plugin function. If
funcNameis an empty string or does not match any plugin function (case sensitive), a list of all suitable additional plugin function names is given. Else, detailed information about the desiredfuncNameis given, like its description or (optional) arguments that are needed to execute this function.- detailLevel
dict,optional if
detailLevel == 1, this returns a nested dictionary with detailed information, else it is printed to the command line in a readable form (default).
- funcName
- Returns:
See also
- getExecFuncsList() List[str]#
Gets a list of the names of additional callable functions of this plugin.
Each plugin may define a set of functions, extending the standard interface. These functions are not common to plugins of the same type. They are executed using:
instance.exec("funcname", arg1, arg2, ...)
To get more information about one specific function, call
getExecFuncsInfo().
- getParam(name) int | float | str | Tuple[int] | Tuple[float] | dataObject | polygonMesh | pointCloud | dataIO | actuator#
Returns the current value of the plugin parameter
name.The type of the returned value depends on the real type of the internal plugin, which can be:
String ->
strChar, Integer ->
intDouble ->
floatDataObject ->
dataObjectPolygonMesh ->
polygonMeshPointCloud ->
pointCloud
The
nameof the parameter must have the following form:name
name:additionalTag (
additionalTagcan be a special feature of some plugins)name[index] (only possible if parameter is an array type and you only want to get one single value, specified by the integer index
[0, len(array) - 1])name[index]:additionalTag (a combination of the two possibilities above)
- Parameters:
- name
str Name of the requested parameter.
- name
- Returns:
intorfloatorstrortupleofintortupleoffloatordataObjectorpolygonMeshorpointCloudordataIOoractuatorCurrent value of the parameter
name.
- Raises:
ValueErrorif parameter does not exist
See also
- getParamInfo(name) dict#
Returns a nested dictionary with meta information of the desired parameter.
Plugin parameters in itom not only hold a value, but they can also be equipped with further meta information, like the minimum or maximum value range, a certain step size, allowed string values etc.
These values are returned as nested dictionary (if available, else the dict is more or less empty).
- getParamList() List[str]#
Returns a list of the names of all available parameters of this plugin object.
Each plugin defines a set of parameters. Each of these parameters maps its
nameto a certainvalue. The value is represented by the C++ classito::ParamBaseand can have one of the following types (Python equivalent in brackets):String (str)
Char (int, [-127, 128])
Integer, (int)
Double (float)
CharArray (sequence of int)
IntegerArray (sequence of int)
DoubleArray (sequence of float)
DataObject (
dataObject)PolygonMesh (
polygonMesh)PointCloud (
pointCloud)
Using one of the parameter names, its current value can be obtained by
getParam("name")and can be set bysetParam("name", newValue)(if not read-only).Usually, every plugin object can define its own set of parameters. However, there are conventions about certain parameters, that must be available and have a specific meaning for a type of plugin object.
See also
- getParamListInfo(detailLevel=1) dict | None#
Prints or returns detailed information about all parameters of this plugin object.
Each plugin defines a set of parameters. Each of these parameters maps its
nameto a certainvalue. The value is represented by the C++ classito::ParamBaseand can have one of the following types (Python equivalent in brackets):String (str)
Char (int, [-127, 128])
Integer, (int)
Double (float)
CharArray (sequence of int)
IntegerArray (sequence of int)
DoubleArray (sequence of float)
DataObject (
dataObject)PolygonMesh (
polygonMesh)PointCloud (
pointCloud)
Using one of the parameter names, its current value can be obtained by
getParam("name")and can be set bysetParam("name", newValue)(if not read-only).This method prints a detailed listing with the
name, current value, description string and further meta information of every plugin parameter. Additionally, the columnR/Windicates if this parameter is writable or read-only.Dependin`g on
detailLevel, this method will not print the listing to the command line but returns it using a nesteddict.- Parameters:
- detailLevel
dict,optional if
detailLevelis set to1, this method returns a nested dictionary with all information about all parameters of this plugin. OtherwiseNoneis returned and the listing is printed in a readable form to the command line (default).
- detailLevel
- Returns:
See also
- getType() int#
Returns the type value of this specific dataIO plugin.
Possible values are:
0x081: a camera or general grabber device0x101: a analog-digital converter device0x201: any other kind of device (e.g. data transfer, like serial ports, USB ports, … but also other devices like a power supply…).
- Returns:
intdataIO type identifier.
- getVal(dataObj) None#
- getVal(buffer, length=INT_MAX) int
Gets shallow copy of internal camera image if dataObj is provided. Else values from the plugins are copied to given buffer.
Returns a reference (shallow copy) of the recently acquired image (located in the internal memory if the plugin) if the plugin is a grabber or camera and the buffer is a
dataObject. Please consider that the values of thedataObjectmight change if a new image is acquired since it is only a reference. Therefore consider copying thedataObjector directly usecopyVal().If no acquisition has been triggered, this method raises a :obj`RuntimeError`. If the acquisition is not finished yet, this method blocks and waits until the end of the acquisition.
If the plugin is another type than a grabber or camera (e.g. serialIO), this method requires any
bufferobject that is preallocated with a reasonable size (e.g.bytearray,bytesor unicodestr. Then, the currently available data is copied into this buffer object and the size of the copied data is returned. If the buffer is too small, only the data that fits into the buffer is copied. Another call togetVal()will copy the rest.- Parameters:
- dataObj
dataObject Usually for cameras and grabber: A reference (shallow copy) to the internal memory of the camera plugin is set to the given data object. Therefore its content may change if a new image is being acquired by the camera. Consider taking a deep copy if the image (
dataObject.copy()) or use the methodcopyVal().- buffer
bytearrayorbytesorstr Usually for all other IO devices or AD-converters: The buffer must be an object of type
bytearray,bytesor unicodestr. Thelengthparameter is then set to the size of the allocated buffer. This buffer is then filled with data and the filled size is returned (max:length).- length
int,optional Size of the given buffer. This value is usually automatically determined and must not be given.
- dataObj
- Returns:
See also
- hideToolbox()#
Hides the visible toolbox of this plugin object.
- Raises:
RuntimeErrorif this plugin does not provide a toolbox.
See also
- info(verbose=0)#
Prints out information about signal and callable slots of this actuator.
- Parameters:
- verbose
int 0: only slots and signals from the plugin class are printed (default) 1: all slots and signals from all inherited classes are printed
- verbose
See also
- name() str#
Returns the name of this plugin object.
- Returns:
- name
str name of the plugin, which corresponds to
getParam("name")
- name
See also
- setAutoGrabbing(enable)#
Enables or disables the auto grabbing property of this grabber device.
If the auto grabbing flag is set, the camera acquisition is continuously triggered if at least one live image is connected to the camera.
Enabling this auto grabbing mechanism can be undesired behaviour for instance if a measurement is started where the acquisition should be controlled by a specific script or something similar. In this case, disable the auto grabbing property. All connected live images will then get new images only if
getVal()orcopyVal()is called.- Parameters:
- enablebool
Truewill enable the auto grabbing timer,Falsedisables it.
See also
- setAutoGrabbingInterval()#
Changes the minimum auto grabbing interval (in ms) between two auto-grabbed datasets.
If auto grabbing is enabled for a grabber device, a timer is set that continuously acquires data or images from the devices and sends it to all connected plots or other listeners. The timer event will occur with a certain interval (in ms). However, if the image acquisition requires more time than the interval, several timer events will be automatically omitted, such that the next image is only acquired if the grabber device is in an idle state again. Hence, the interval is considered to be a minimum value.
The default interval of newly started grabber devices in 20 ms. It is possible to change this interval even if auto grabbing is currently disabled. The new interval will be considered from the next activation on.
- Parameters:
- interval
int New minimum auto grabbing timer interval in ms.
- interval
- setParam(name, value)#
Sets a writeable parameter
nameof this plugin object tovalue.Sets the internal plugin parameter with ‘name’ to a new value. The plugin itself can decide whether the given value is accepted as new value. This may depend on the type of the given value, but also on the allowed value range indicated by further meta information of the internal parameter. Parameters that are (currently) set to read-only cannot be set.
The
nameof the parameter must have the following form:name
name:additionalTag (additionalTag can be a special feature of some plugins)
name[index] (only possible if parameter is an array type and you only want to get one single value, specified by the integer index [0,nrOfArrayItems-1])
name[index]:additionalTag (a combination of the two possibilities above)
- Parameters:
- name
str Name of the parameter.
- value
intorfloatorstrortupleofintortupleoffloatordataObjectorpolygonMeshorpointCloudordataIOoractuator The
valuethat will be set. The plugin will check if thisvaluefits to possible constraints, given by the parameters’s meta information or further limitations.
- name
- Raises:
RuntimeErrorif the new
valueis (currently) not accepted.
See also
- setVal(dataObj) None#
- setVal(buffer, length=1) None
Transfers a dataObject to an ADDA plugin for write, or a bytearray to other dataIO plugins for general purposes.
If the
dataIOplugin has the subtypeADDA(analog-digital converter), this method is used to send data to one or more analog outputs of the device. In this case adataObjectmust be given as first and only argument. and the second argumentlengthmust be 1.For other dataIO plugins, the first argument must be any buffer object, like a
bytearray,bytesor unicodestr. Thelengthis then extracted from this value. However it is also possible to define a user-defined size using thelengthargument.- Parameters:
- dataObj
dataObject The array, that should be transmitted to the output of an analog-digital converter. Usually, the shape of this array is
M x N, whereMchannels will obtain up toNnew values. This argument is used forADDAdataIOdevices.- buffer
bytearrayorbytesorstr Other
dataIOdevices thanADDAneed to pass a buffer object, like abytearray,bytesor unicodestr.- length
int,optional Usually, this value is not required, since the length of the
bufferis automatically extracted from the given object.
- dataObj
- showConfiguration()#
Shows the (optional) configuration dialog of this plugin as modal dialog.
- Raises:
RuntimeErrorif this plugin does not provide a configuration dialog.
- showToolbox()#
Opens the (optional) toolbox of this plugin object in the itom main window.
- Raises:
RuntimeErrorif this plugin does not provide a toolbox.
See also
- startDevice(count=1)#
Starts the given dataIO plugin object.
This command starts the dataIO plugin such that it is ready for data acquisition. Call this method before you start using commands like
acquire(),getVal()orcopyVal(). If the device already is started, an internal start-counter is incremented by the parametercount. The correspondingstopDevice()method then decrements this counter and finally stops the device once the counter drops to zero again.The counter is necessary, since every connected live image needs to start the device without knownledge about any previous start. No acquisition is possible, if the device has not been started, hence the counter is 0.
- Parameters:
- count
int,optional Number of increments to the internal start-counter (default: 1).
- count
See also
- stop()#
Stops a started, continuous acquisition.
This method stops a previously started, continuous data acquisition. This method is not implemented in every plugin. A common example for its implementation is to stop an infinite, continuous acquisition job of an AD-converter plugin.
See also
- stopDevice(count=1) int | None#
Stops the given dataIO plugin object.
If this method is called as many times as he corresponding
startDevice()method (or if thecountsare equal), thedataIOdevice is stopped (not deleted) and it is not possible to acquire further data.Once a live image is connected to a camera,
startDevice()is automatically called at start of the live acquisition andstopDevice()at shutdown.- Parameters:
- count
int,optional if
count> 1,stopDevice()is executedcounttimes, in order to decrement the grabber internal start counter. You can also setcount = -1, thenstopDevice()is called in a loop until the internal start counter drops to 0. The number of effective counts is then returned.
- count
- Returns:
See also
- userMutexTryLock()#
tryLock(timeout = 3000) -> bool
Tries to lock the user mutex of this plugin.
Every plugin contains a user mutex, that can be used for arbitrary purposes. It is not used for any official purposes. You can for instance use this mutex both from Python and other C++ threads to protect a series of calls to this plugin to not to be interrupted by other participants. However, it is the full responsibility of the programmer to carefully use this mutex.
Please be careful, that this method can lead to a deadlock if
timeoutis set to a negative value (infinite wait) and if the mutex is not released by any other thread. Hint: A Python thread is no real thread, it must be a real C++ thread. If you want to use the mutex within two or more Python threads, it is recommended, to call this method with a definedtimeoutwithin a loop and wait for this method to returnTrue. This allows unlocking the mutex by another thread.This method is new for plugins that implement the AddInInterface >= 4.2.
- Parameters:
- timeout
int This method will wait for at most
timeoutmilliseconds for the mutex to become available. If this value is negative, it will wait forever until the mutex become available.
- timeout
- Returns:
- bool
Trueif the user defined mutex could be locked, elseFalse.
See also
unlock
- userMutexUnlock()#
Tries to unlock the user mutex of this plugin.
Every plugin contains a user mutex, that can be used for arbitrary purposes. It is not used for any official purposes. You can for instance use this mutex both from Python and other C++ threads to protect a series of calls to this plugin to not to be interrupted by other participants. However, it is the full responsibility of the programmer to carefully use this mutex. fu This method is new for plugins that implement the AddInInterface >= 4.2.
See also
lock
- TRIGGER_SOFTWARE = 0#