In order to allows direct communication between MATLAB and EPICS, we used the epics-labca from GitHub. 
While the library building in a Linux system is quite simple and works fine,  the building into a Windows System needs some particular attention to be achieved.


Prerequisites:

  • the epics-labca source files downloaded from GitHub
  • Epics installed on your device
  • Matlab installed on your device

The present guide describes an installation based on: epics7.0 version and Matlab R2022
In Windows environment  it would be preferred that those program were installed in a path without blank spaces. Maybe is not necessary, but I did.

EDITING RELEASE FILE

Once downloaded the library source code, open the ./configure/RELEASE file and change / uncomment and change the following MACRO.

For Windows Users..
Use the /  into the PATH just like it is a LINUX PATH:
c:/mypath/mysubpath 

EPICS_BASE

##########################################
## Tell us where EPICS base is installed
BASE_SUBDIR=/base/
EPICS_BASE=$(EPICS_SITE_TOP)$(BASE_SUBDIR)$(BASE_MODULE_VERSION)
-include $(TOP)/RELEASE_SITE
-include $(TOP)/configure/RELEASE.local 

##########################################

Change the EPICS_BASE value with the installation path of your EPICS, at the base level
No need for  EPICS_BASE to be compounded by a  BASE_SUBDIR.

I also set EPICS_HOST_ARCH=windows-x64
But could not be necessary.

MATLABDIR

##########################################
# Tell us where MATLAB is installed (only
# needed if MAKEFOR=MATLAB [in CONFIG])


#MATLABDIR=/afs/slac/package/matlab/2010a

Uncomment and set the MATLABDIR  variable with the path of you matlab installation
The MAKEFOR variable in CONFIG is MATLAB as DEFAULT so we don't need to change it.

MATLIB_SUBDIR

####################################################################################
# Finally, we need to know what compiler
# you use to get the correct matlab libmx and
# libmex versions. This points to the compiler
# specific subdir (example for MS visual C / matlab R2006b)
# ONLY NEEDED ON WINDOZE (setting is ignored on
# other platforms) where the 'libmex.lib' and
# 'libmx.lib' are found.


# older matlab needed 'msvcXY' subdir
#
#MATLIB_SUBDIR=win32/microsoft/msvc70 

If you're compiling for Windows, uncomment and change the value of MATLIB_SUBDIR with the RELATIVE path between your ${MATLABDIR}/lib and the directory where is located the library 'libmex.lib'



BUILDING THE LIBRARY

In a Linux system, just run the make command and the building procedure should be completed without errors.


In a Windows System, you should before have a compiling environment.
For this purpose we used Microsoft Visual Studio Community Edition 2022 

Then, you have to install a make tool, because is not already present in Windows.
For this purpose we used Gnu Make 4.3 installed by Chocolatey

Now Visual Studio 2022 and Make are not so pretty integrated, for this reason you could have some bad behaviour using the make from the IDE depending on the host architecture of the EPICS library that you have installed.
It could happens (and happened to me) that you have the 64 bit library from EPICS, but your Visual Studio will continue to use a 32 bit cl compiler for building your library even if you try to define the compilation target inside the IDE. This will brought you to fail your build.
So instead of Launching the Visual studio IDE, launch the:


X64 Native Tools Command Prompt For VS 2022  if you're compiling a 64-bit library    or
X86 Native Tools Command Prompt For VS 2022 if you're compliling a 32-bit library 

You will find both of those tools in Start → Visual Studio 2022 folder in the start menu.
Before you launch the build inside this command prompt, you have to change another point of the code.

THE mglue.h FILE

Open the glue/mglue.h file and edit the line 91 that was
void lcaMexGblInit();

trasforming it in:
epicsShareFunc void epicsShareAPI  lcaMexGblInit();

This is necessary because Windows for default doesn't export functions into library. It must be explicitly declared, differently from Linux.


Now, launching a MAKE command in the Prompt for VS should run correctly and creating a subfolder of the matlab library folder, in which you will have all the .mexw64 that you need to put into your matlab.
You will need also the dll created in the folders ezca (ezcamt.dll) and in the folders glue (mezcaglue.dll)  


Precompiled Build for Windows



Win10-64bit-labca.zip

Using LABCA within MATLAB

Extract the precompiled build for Windows (Win10-64bit-labca.zip) in any folder. Set a new path within MATLAB to this folder. By doing this it is possible to use all the LABCA functions through the MATLAB console and within any script.

A list of all the functions and how to use them is present in the LABCA-manual, downloaded from https://till-s.github.io/epics-labca/:


IMPORTANT NOTE:

In order to find an EPICS device through TCP/IP, it is needed to create a new system variable with the list of the devices IP.

In order to do so:

  • Click on the search button of the WINDOWS task bar
  • Search for "Visualizza Impostazioni di sistema Avanzate"
  • In "Avanzate" tab, click "Variabili d'Ambiente"
  • Create a new "System Vatiable" named EPICS_CA_ADDR_LIST
  • Insert the device IP. To insert multiple devices, insert multiple IP's, separated by black space.
  • No labels