| Message | Cause | What to do |
ExternalModelDeviceDriver: Failed to load ExternalModelDeviceAPI. <reason> (error) | The API library (MatlabDeviceAPI / PythonDeviceAPI) could not be loaded. Reasons: API library not found, ...; Dependency DLL missing (for MATLAB: the MATLAB Engine DLLs are not found; for Python: python3xx.dll is not found); Exported function missing; Wrong architecture (32/64 mismatch); DLL Initialization failed; on Linux Failed to load library: .... | Copy the library next to the executable (Linux: working directory, libPythonDeviceAPI.so / libMatlabDeviceAPI.so). Put the folder of the MATLAB Engine DLLs (<matlabroot>\extern\bin\win64 and <matlabroot>\bin\win64) or of the Python DLL on PATH of the process. Match 64-bit. Note: after this message the driver has no engine; later steps in OnInit can crash the engine instead of printing a further message, so fix this first. |
ExternalModelDeviceStream: stream '<name>', Function '<function>' not found in module (error) | The block's function is not an attribute of the Python module (or, for MATLAB, the engine reports that it cannot be found). The function name of that block is cleared, so the block is not called any more. The check stops at the first missing function: the blocks listed after it are not checked. | See section 6. Fix the name, or the module, then restart the engine (a reset does not re-run the check; the check is made at OnInit). |
ExternalModelDeviceStream: stream '<name>', Bad LRU name '<lru>' not in database (error) | The LRU in rawout does not exist. (The name in the printed text may be garbled in some builds; check the rawout value.) | Use the form "rawout": "LRU.Block" with names from the ICD. |
ExternalModelDeviceStream: stream '<name>', Bad block name '<block>' not in LRU '<lru>' (error) | The block in rawout does not exist in that LRU. | Check the spelling against the ICD. |
Stream: '<name>': block '<block>': timing <N>us > system minor frame <M>us; data may be lost. (warning) | An input block has a numeric framePerMS longer than the minor frame. (Message text as printed by the serial stream; the same framePerMS rule applies to every input block.) | Use "framePerMS": -1. See the note on framePerMS and section 8. |
| Message (console) | Cause | What to do |
MatlabRunner: failed to start MATLAB | The Engine API returned no session. | See section 4. |
MatlabRunner: MATLAB is already open | Information: Open was called after Init had already started the session. Normal. | None. |
MatlabRunner: MATLAB execution error: <text> / MATLAB error: <text> / C++ error: <text> (in Open) | The engine could not be started (exception from startMATLAB). | See section 4. |
CallFunction: MATLAB is not initialized (error, engine log) | The function was called but there is no MATLAB session. | Fix the start error. Check that Init / Open succeeded. |
CallFunction: function name is empty | The block has no function. | Add "function": "name" to the block. |
MATLAB execution error in '<function>': <text> | MATLAB raised an error while running the function (for example Undefined function or variable when the function is not on the MATLAB path, Too many output arguments, Index exceeds array bounds). | Take the MATLAB text literally and run the call by hand in MATLAB. See section 6 and section 7. |
MATLAB error in '<function>': <text> / C++ error in '<function>': <text> | Engine API error (for example the session was lost or a data conversion failed). | Restart the engine; check that MATLAB itself is still running. |
CallFunction: MATLAB function '<function>' returned no output | The function has no output value. | Declare the function with one output: function out = name(rawIn, rawInSize). |
CallFunction: MATLAB function '<function>' returned type <n>, expected uint8 | The function returned another class (double, single, struct, char, logical...). n is the Engine API type number. | Convert the result: out = uint8(...) or out = typecast(single(x), 'uint8') or typecast(...) of a packed struct. A double array is NOT converted automatically. |
CallFunction: MATLAB output too large. Output=<n> bytes, buffer=<m> bytes | The returned array has more elements than the rawout block size in bytes. Nothing is copied. | Return exactly the output block size (or less). Compare with the block size in the ICD. |
CallFunction: '<function>' returned <n> bytes | Information printed on every successful call. | It is a console print on each call, so it costs time. Redirect or hide the console if you need the best speed. |
| Message (engine log) | Cause | What to do |
PythonDeviceAPI: Error loading module <module> (error) | The import of moduleName failed (the Python traceback is printed on the console just before this line): module file not found, a syntax error or exception in the module, or a module imported by it that is not installed. | See section 5. After this error the interpreter is shut down; fix and restart the engine. |
PythonDeviceAPI: Loaded Python module: <file> (info) | The module was imported from that file. | Check that it is the file you expect (a different copy earlier on sys.path would win). |
PythonDeviceAPI: Python module is not loaded (error) | A call was made but the import had failed. | Fix the import error first. |
PythonDeviceAPI: Invalid input buffer (error) | The input block has size 0 or no raw memory. | Check that raw names an existing block with elements. |
PythonDeviceAPI: Function <function> not found in module <module> (error) | At call time the function is not an attribute of the module. | See section 6. |
PythonDeviceAPI: <function> is not callable (error) | The name exists in the module but is a variable or class instance, not a function. | Use the name of a function (def) or callable. |
PythonDeviceAPI: Failed to create Python input / Failed to create input size | Out of memory while building the call arguments. | Check memory; unusual. |
PythonDeviceAPI: Error calling <function> in module <module> (error) | The function raised an exception (the traceback is printed on the console). Typical: wrong number of arguments (the function must accept (rawIn, rawInSize)), struct.error from unpacking a wrong size, NameError, ImportError inside the function. | Read the traceback. Call the function by hand with bytes(N), N. |
PythonDeviceAPI: GetReturnValue: output buffer too small. Required=<n>, Available=<m> (error) | The returned value (int, float, bytes, bytearray, str, or a list item) is larger than the space left in the rawout block. Nothing is copied. | Return no more bytes than the output block size. See section 7. |
PythonDeviceAPI: GetReturnValue: unsupported Python return type: <type> (error) | The function returned an object type that is not handled, for example a NumPy array, None, dict or a ctypes structure. | Return bytes (for NumPy: arr.tobytes(); for struct: struct.pack(...)). A function that returns None is an error when there is a rawout block. |
PythonDeviceAPI: GetReturnValue: failed to convert Python integer / ... failed to get integer bit length / ... failed to convert Python float / ... failed to get bytes size / ... failed to get bytearray size / ... failed to convert Python string to UTF-8 / ... failed to get array element <i> / ... failed processing array element <i> | The returned value could not be converted. A Python int must be non-negative and fit 64 bits (a negative or very large int fails). | Return bytes packed with struct.pack and an explicit format (for example '<d' or '<i'). |
| Problem | Cause | Fix |
The MatlabDeviceAPI library does not exist in the build | The library is built only when CMake is configured with INCLUDE_MATLAB=ON (default OFF). The build needs the MATLAB Engine API for C++ headers (MatlabEngine.hpp, MatlabDataArray.hpp) in its include path. | Configure the build with -DINCLUDE_MATLAB=ON and add the MATLAB extern/include directory and the engine libraries to the build of that target. |
| Dependency DLL missing / the library does not load | MATLAB is not installed on this machine, or its engine DLLs are not on PATH of the engine process. | Install MATLAB (a full install, not the Runtime) and add <matlabroot>\extern\bin\win64 and <matlabroot>\bin\win64 to PATH before starting the engine. The build and the machine must have the same MATLAB release. |
MatlabRunner: failed to start MATLAB or MATLAB execution error at start | MATLAB cannot start: no valid license (expired, license server not reachable, license in use by another user, not activated for this user), or the first start of MATLAB needs an interactive sign-in. | Start MATLAB once by hand as the same user and check that it opens. Check the license server / network. A start can also take tens of seconds; the engine waits. |
| The engine starts MATLAB but the function is never found | The driver starts its own MATLAB session with the default path; moduleName is not used for MATLAB. The folder of your .m files is not on that session's path. | Put the .m files in the working directory of the engine process (the MATLAB session starts in it), or add them to the MATLAB path permanently (savepath / startup.m in the MATLAB startup folder). |
| MATLAB window flashes or an engine process stays after the stop | The session is closed with clear when the driver closes; an engine killed from the task manager leaves MATLAB.exe behind. | End the leftover MATLAB.exe process before the next start. |
| Problem | Cause | Fix |
The PythonDeviceAPI library does not exist in the build, or fails to load | It is built only with INCLUDE_PYTHON=ON (default OFF). In the supplied project it is compiled and linked against a fixed Python installation (C:/Python313, python313.lib). It needs the matching python313.dll at run time. | Install the same Python version (64-bit) and make sure its folder (or the DLL) is on PATH or next to the executable. To use another version, change the include and library paths in the library's CMakeLists.txt and rebuild. |
Error loading module <module> with ModuleNotFoundError in the console | The module is not on sys.path. The library inserts the current working directory of the process at the front of sys.path (the Streams manual calls it the executable directory; they are the same when the engine is started from its own folder). Other folders come from the Python installation. | Put the .py file in the working directory of the engine, or install it into the Python used by the engine (site-packages), or set PYTHONPATH in the environment before starting. moduleName is the module name without .py and without a path. |
| Import works from a command prompt, fails in the engine | The engine uses the embedded interpreter of the DLL it was built with, not the python on your PATH; packages installed with another Python (or a virtual environment) are not visible. | Install the needed packages (pip) with the same Python version that the library was built against, in its global site-packages. |
Console shows SyntaxError / an exception from your module, then Error loading module | The module raises while being imported (code at module level, missing import, bad indentation). | Run python -c "import yourmodule" in the working directory. |
You changed the .py file and nothing changed | The module is imported once when the engine starts (OnInit). A reset does not re-import it. | Restart the engine after editing the module. |
| Python state (global variables) persists between calls | The module stays loaded, so globals keep their values for the whole run. | Use this on purpose for state (filters, integrators); initialize it at module level. |
Engine crashes when the function raises an exception and the block has no rawout | In the current library the failed call result is released without a check when there is no output block. | Give the block a rawout so that the exception is reported, and catch exceptions inside your function (try / except, return the previous bytes). |
| Item | MATLAB | Python |
| Call | out = fn(rawIn, rawInSize) | result = fn(rawIn, rawInSize) |
| Input | rawIn: 1×N uint8 row vector; rawInSize: uint64 scalar. | rawIn: bytes (read only); rawInSize: int. |
| Return type | Must be uint8. Anything else is rejected with returned type ..., expected uint8. | More tolerant: bytes, bytearray, str (UTF-8), non-negative int (stored as the shortest little-endian byte count that holds the value, zero needs one byte), float (8-byte double), or a list / tuple of these (concatenated). Others are rejected. |
| Maximum size | Number of elements ≤ rawout block size in bytes, else MATLAB output too large and nothing is copied. | Each returned piece must fit the space that is left in the block, else output buffer too small and nothing from that call is guaranteed to be complete. |
| Smaller than the block | Only the returned bytes are written, the rest of the block keeps its old content. | Same. An empty bytes object counts as a failure (no bytes). |
| Byte layout | The bytes are the raw block layout (packed, little-endian as in the ICD), not engineering values. Unpack with typecast (MATLAB) or struct.unpack (Python); pack the result the same way. A wrong offset gives wrong values and no message. See the function contract. |
| Symptom | Cause | Fix |
| Minor frame overruns / frame time warnings once the stream runs; engine slower than real time | The MATLAB engine call (data copy between processes, interpreter) typically takes milliseconds and varies; a Python call takes microseconds to milliseconds depending on the work. MATLAB prints one console line per call as well. | Use a longer minor frame for these streams, or call less often with a numeric framePerMS (see below). For real-time rates generate C++ from MATLAB (MATLAB Coder) and run it as a model: Integrate a MATLAB Algorithm as a CoreEngine Model. |
| Values are late or jump | The call blocks the frame, then catches up. | Reduce the work in the function (pre-allocate, avoid file reads, disp / print, plotting, tic/toc printing). |
| Nothing is called | framePerMS: 0 disables the block. | Use -1. |
| Function is called less often than expected | A numeric framePerMS was set on the input block. | Direction in: -1 = check every minor frame (the function is called every minor frame), 0 = disabled, a number = checked only at that rate; if that is slower than the data the source produces, data may be lost and a warning is shown. A numeric value is reasonable here only to lower the call rate on purpose, because the call is slow. See the note on framePerMS. |
| First frame is very slow | MATLAB start-up and Python module import happen at OnInit, before the run; the first call can still warm up caches (JIT). | Expect the first calls to be slower; do not judge timing from them. |
| Symptom | Cause | Fix |
| No error, output block never changes | The function returns the same bytes each time; or the block has no rawout (return value not used); or the function was disabled at OnInit (see the error at start); or function is missing in the block. | Check rawout and the start-up log. Print inside the function to see that it is called. |
| Output block receives data but a model that reads it never runs | The External Model stream does not trigger models or update block counters when it writes the output block. | Read the output block in a periodic model, or trigger your model on the input block's own source. |
| Block is called even if the input did not change | The function is called on every read of the stream, not when the input changes. | Detect changes inside the function (compare with the previous bytes) if needed. |
| Output is shifted or values are garbage | The ICD raw layout (bit packing, padding, byte order) is different from your typecast / struct format. | Compare with the block definition (Raw ↔ Eng convention). Test with known bytes outside the engine. |
| Several streams with the same module or function | Each stream loads its own driver and engine session (a separate MATLAB session per stream; a Python interpreter per stream library load). | Prefer one stream with several blocks. Each additional MATLAB session adds start-up time and memory; check the license seat count. |
Linux: libPythonDeviceAPI.so / libMatlabDeviceAPI.so fails to load | The Python development package or the MATLAB runtime libraries are missing from the library path (LD_LIBRARY_PATH). | Install python3-dev for the build; add the MATLAB engine library folder to LD_LIBRARY_PATH. The error text after Failed to load library: names the missing file. |
| Messages from MATLAB are not in the log | The MATLAB library prints with printf to the console. | Look at the console / standard output of the engine process. |