Skip to content

sdk

Modules:

Name Description
key_sdk
lcd_sdk
led_sdk

Functions:

Name Description
load_dll

Initialize and load of the C dynamic linking library.

load_dll

load_dll(lib_type: DllSdk) -> Lib | CDLL | None

Initialize and load of the C dynamic linking library.

Parameters:

Name Type Description Default

lib_type

DllSdk

Library to load: LCD, LED or Gkey

required

Returns:

Type Description
Lib | CDLL | None

C DLL instance

Source code in src/dcspy/sdk/__init__.py
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
def load_dll(lib_type: DllSdk) -> Lib | CDLL | None:
    """
    Initialize and load of the C dynamic linking library.

    :param lib_type: Library to load: LCD, LED or Gkey
    :return: C DLL instance
    """
    try:
        dll_path = lib_type.get_path()
        LOG.debug(f'Selected DLL: {dll_path}')

        if lib_type.name == 'Gkey':
            dll = CDLL(dll_path)
        else:
            ffi = FFI()
            ffi.cdef(lib_type.header)
            dll = ffi.dlopen(dll_path)  # type: ignore[assignment]

        LOG.info(f'Loading of {lib_type.name} SDK success')
        return dll
    except (KeyError, OSError, CDefError) as err:
        header = '*' * 44
        LOG.error(f'\n{header}\n*{type(err).__name__:^42}*\n{header}\nLoading of {lib_type.name} SDK failed !', exc_info=True)
        LOG.error(f'{header}')
        return None