FlexSEA Wiki


User Tools

Site Tools



At this time, OCTAVE does not support the loadlibrary function. This information presented here is only applicable to MATLAB.

MinGW Compiler Requirement

The MATLAB environment requires the MinGW64 compiler to supply some required DLLs. You can download the compiler from https://osdn.net/projects/mingw/releases/. In addition, the system PATH environment variable must be pointing to the 64-bit version of the compiler. If not, you will get the following errors:

On the Dephy, Inc. systems, the MinGW 64-bit compiler is installed at:


The 32-bit compiler is installed at:


If you are using scripts for other languages besides MATLAB and SIMULINK, you may 
need to change between these.
Configure MATLAB Compiler

MATLAB and SIMULINK require and add-on to utilize the MinGW compiler.

  • Go to MATLAB Home → Add-Ons and select “Get Add-ons”.
  • Search for MinGW and click on the MATLAB Support for MinGW-w64 C/C++ Compiler link.
  • Click the Add button to install this package.

Once this is done you will have to configure MATLAB to use the MinGW compiler. Perform the following steps

  • In the MATLAB command window, enter: mex -setup
  • Click on the MinGW64 Compiler (C) link.

MATLAB has now been configured to use the MinGW compiler.

Using a DLL with MATLAB

When using the fx_plan_stack library with MATLAB, you must first load the library. The Library must be compiled as a 64-bit DLL. The library and a header file describing the functions is required. In the Actuator package environment, the library is libfx_plan_stack.dll and the header file is com_wrapper.h.

The code to do this is:

addpath( '..\fx_plan_stack\lib64');
addpath( '..\fx_plan_stack\include\flexseastack');
loadlibrary('libfx_plan_stack', 'com_wrapper');

if libisloaded( 'libfx_plan_stack' );
    disp('FlexSEA DLL is loaded')
...  Your code here
unloadlibrary 'libfx_plan_stack' 

This adds to the search path to allow you to find the DLL and the header files.

Determining Library Contents

With the library loaded, you can list the functions provided by the library using the libfunctions function. By adding -full parameter the function prototypes and returned information will be displayed as well. This is useful to do from the MATLAB command window to make sure you are calling the functions properly. It is especially important to get the output from the functions correctly.

>> loadlibrary('libfx_plan_stack', 'com_wrapper');
>> libfunctions('libfx_plan_stack', '-full');
Functions in library libfx_plan_stack:

actPackFSM2(int32, int32)
findPoles(int32, int32)
int32Ptr fxGetDeviceIds(int32Ptr, int32)
uint8 fxIsOpen(int32)
cstring fxOpen(cstring, int32)
[lib.pointer, int32Ptr, uint8Ptr] fxReadDevice(int32, int32Ptr, uint8Ptr, int32)
[uint8, int32Ptr] fxSetStreamVariables(int32, int32Ptr, int32)
uint8 fxStartStreaming(int32, int32, bool, int32)
uint8 fxStopStreaming(int32)
setControlMode(int32, int32)
setMotorCurrent(int32, int32)
setMotorVoltage(int32, int32)
setPosition(int32, int32)
setZGains(int32, int32, int32, int32, int32)
Handling returned arrays of data

Functions that return an array of values require special handling to obtain the return values. MATLAB returns a lib.pointer from these functions (see fxReadDevice above). The lib.pointer can be used to initialize a variable of the correct type as follows:

[ ptr, retData, success] = calllib(libHandle, 'fxReadDevice', devId, vars, success, 10);
ptrindex = libpointer('int32Ptr', zeros(1:10, 'int32'));
ptrindex = ptr;
setdatatype(ptrindex, 'int32Ptr', 1, 10);
fprintf(" Return value = %d\n", ptrindex.value(1);
fxCleanup for premature termination

If your script fails and you do not call fxCleanup, you will not be able to communicate with the fLexSEA device when running the script again. MATLAB itself may crash.

If your program terminates before fxCleanup is called, type the following in the MATLAB command window:

calllib('libfx_plan_stack', 'fxCleanup');
matlabhints.txt · Last modified: 2019/01/31 18:55 by flabelle