pylablib.devices.utils package

Submodules

pylablib.devices.utils.color module

pylablib.devices.utils.color.bayer_interpolate(src, off=(0, 0))[source]

Interpolate Bayer-filtered source image.

The algorithm is the straightforward linear nearest neighbor interpolation. The Bayer pattern is assume to be [RG|GB], and off specifies the red pixel position with respect to the image origin.

pylablib.devices.utils.color.linear_to_sRGB(v, base=1, A=2.4, P=0.055)[source]

Convert the linear sRGB color space to the sRGB.

base specifies the full color range (e.g., 65535 for 16-bit color values), and A and P are the two conversion parameters.

pylablib.devices.utils.color.sRGB_to_linear(v, base=1, A=2.4, P=0.055)[source]

Convert the sRGB color space to the linear sRGB.

base specifies the full color range (e.g., 65535 for 16-bit color values), and A and P are the two conversion parameters.

pylablib.devices.utils.load_lib module

pylablib.devices.utils.load_lib.get_os_lib_folder()[source]

Get default Windows DLL folder (System32 or SysWOW64, depending on Python and Windows bitness)

pylablib.devices.utils.load_lib.get_program_files_folder(subfolder='', arch=None)[source]

Get default Windows Program Files folder or a subfolder within it.

If arch is None, use the current Python architecture to determine the folder; otherwise, it specifies the architecture ("32bit" for Program Files (x86), "64bit" for Program Files)

pylablib.devices.utils.load_lib.get_appdata_folder(subfolder='', kind='roaming')[source]

Get user AppData folder (used to install software only for specific users).

kind can be "roaming" (return Roaming AppData folder) or "local" (return Local AppData folder).

pylablib.devices.utils.load_lib.get_environ_folder(var, subfolder='', error_missing=False)[source]

Get subfolder of a folder based on the environment variable.

If the environment variable is missing and error_missing==True, raise an error; otherwise, return None.

pylablib.devices.utils.load_lib.load_lib(name, locations=('global',), call_conv='cdecl', locally=False, depends=None, depends_required=True, error_message=None, check_order='location', return_location=False)[source]

Load DLL.

Parameters:
  • name – name or path of the library (can also be a list or a tuple with several names, which are tried in that order).

  • locations – list or tuple of locations to search for a library; the function tries locations in order and returns the first successfully loaded library a location is a string which can be a path to the containing folder, "parameter/*" (the remaining part is a subpath inside "devices/dlls" library parameters; if this parameter is defined, it names folder or file for the dll), or "global" (load path as is; also searches in the standard OS specified locations determined by PATH variable, e.g., System32 folder).

  • depends – if specified, it is a list of dependency libraries which need to be loaded first before the main DLL; they are assumed to be in the same location as the main file

  • depends_required – if False, ignore errors during dependency loads

  • locally (bool) – if True, prepend path to the DLL containing folder to the environment PATH folders; this is usually required, if the loaded DLL imports other DLLs in the same folder

  • call_conv (str) – DLL call convention; can be either "cdecl" (corresponds to ctypes.cdll) or "stdcall" (corresponds to ctypes.windll)

  • error_message (str) – error message to add in addition to the default error message shown when the DLL is not found

  • check_order (str) – determines the order in which possible combinations of names and locations are looped over; can be "location" (loop over locations, and for each location loop over names), "name" (loop over names, and for each name loop over locations), or a list of tuples [(loc,name)] specifying order of checking (in the latter case, name and location arguments are ignored, except for generating error message).

  • return_location (bool) – if True, return a tuple (dll, location, folder) instead of a single dll.

class pylablib.devices.utils.load_lib.TLibraryOpenResult(init_result, open_result, opid)

Bases: tuple

init_result
open_result
opid
class pylablib.devices.utils.load_lib.TLibraryCloseResult(close_result, uninit_result)

Bases: tuple

close_result
uninit_result
class pylablib.devices.utils.load_lib.LibraryController(lib)[source]

Bases: object

Simple wrapper to control libraries which require initialization when a new device is opened or shutdown when all devices are closed.

Parameters:

lib – controlled library

preinit()[source]

Pre-initialize the library, if it hasn’t been done already

open()[source]

Mark device opening.

Return tuple (init_result, open_result, opid) with the results of the initialization and the opening, and the opening ID which should afterwards be used for closing. If library is already initialized, set init_result=None

close(opid)[source]

Mark device closing.

Return tuple (close_result, uninit_result) with the results of the closing and the shutdown. If library does not need to be shut down yet, set uninit_result=None

temp_open()[source]

Context for temporarily opening a new device connection

shutdown()[source]

Close all opened connections and shutdown the library

get_opened_num()[source]

Get number of opened devices

Module contents