- Custom Development
At this time, OCTAVE does not support the loadlibrary function. This information presented here is only applicable to MATLAB.
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.
On the Dephy, Inc. systems, the MinGW 64-bit compiler is installed at: C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin The 32-bit compiler is installed at: C:\mingw-w64\i686-7.3.0-posix-dwarf-rt_v5-rev0\mingw32\bin If you are using scripts for other languages besides MATLAB and SIMULINK, you may need to change between these.
MATLAB and SIMULINK require and add-on to utilize the MinGW compiler.
Once this is done you will have to configure MATLAB to use the MinGW compiler. Perform the following steps
MATLAB has now been configured to use the MinGW compiler.
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
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') end ... Your code here unloadlibrary 'libfx_plan_stack'
This adds to the search path to allow you to find the DLL and the header files.
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) fxCleanup fxClose(uint16) 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) fxSetup 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)
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);
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: