« Close

Datasheets and User Guides

App Notes

Software & Driver

 

MATLAB for U12 - Windows

MATLAB .NET examples for R2009a (7.8) and later

The recommended MATLAB examples that requires R2009a (7.8) and later. The "MATLAB_LJDotNET" attachment below provides examples that use the MATLAB .NET interface and the U12 .NET assembly (LJDotNet.dll). Tested on 32-bit MATLAB 2013a (8.1). Refer to the README.txt in the download for details. 4/11/2013, 6 KB.

Old MATLAB examples for R2008b (7.7) and earlier

Old LabJack U12 drivers for MATLAB. Developed and tested on MATLAB 6.1. The LJMATLAB archive ("Old LJMATLAB" attachment) allows data acquisition and control in MATLAB using the LabJack U12. Requires the normal LabJack U12 Legacy DLL which is installed by the main U12 installer. 4/22/2004, 750 KB.

For MATLAB 5, replace the DLLs from the "Old MATLAB" download (LJMATLAB), with "Old LJMATLAB5" (LJMATLAB5). 4/6/2004, 554 KB.

NOTE: MATLAB 6.5 and higher supports direct DLL calls, so special drivers are not required, but a special header is needed to use some functions (more info).

17 comments

Hello, I'm trying to control a U12 by Matlab, but I'm having trouble at the beginning. After pressing the Add Folder button in the Set Path window and selecting the folder which contains the LabJack files, I write the following sentence in Matlab:

[a b c d] = eanalogin(-1,0,1,0)

This error message appears: Undefined function 'eanalogin' for input arguments of type 'double'. 

I don't know what I'm doing wrong. Do I have to do anything before in order to recognise the programs contained in the library?

If it's important, I have a windows 7 64 bits system, and a Matlab2011b.

I'm looking forward to your reply.

Best Regards

I've realised that the function should be written as "EAnalogIn", so I wrote it in a wrong way. But I have the same error, even if I try other functions from the library. I don't know what to do.
Best regards.

Does LJtest.exe run fine?

I see you are on a 64-bit PC.  Use 32-bit matlab if possible, but if you have to use 64-bit matlab, make sure you have taken the extra step to install the 64-bit U12 driver.

LJtest.exe is OK, and I've already download the 64-bit U12 driver, but I don't exactly know where I have to put the .dll and .lib documents. Do I have to put both of them in the folder \windows\system32? I've tried everything, and I'm not able to make Matlab to recognise the libraries.

Best regards.

The 64-bit driver (just the .dll) should go in system32 on a 64-bit system.  The 32-bit driver (which the installer automatically does) goes into SysWOW64.  It seems backwards but that's how it works.

For 64-bit versions of MatLab you might also need this file, which contains some 64-bit compilations of some of the Mex files.

Thank you very much. I've just solved the problem. Eventually, I didn't need this file. What I needed was the header file ljackuw_Mat.h, and now it's working.

Best regards.

Hello, I had the same problem, and with the file you gave us (called as this file) it works, but I can run only these 4 functions. Could you please provide the rest of the library in this kind of format (Mex)?

Regards.

Those functions were provided by another user.  Unfortunately our version of Matlab doesn't compile the 64-bit versions of the Mex files.  It is however not too difficult if you have a 64-bit compiler set up on the system.  Our normal Matlab download contains the .cpp files needed.  You can learn more about which compilers are supported here: http://www.mathworks.com/support/compilers/R2010a/win64.html .  That is for R2010a but other versions are accessible from that page.  Some versions have a free compiler that can be used.

With the .h and .lib files in the directory with everything else and the compiler set up you can build mex files which will work for your version by using:
 
mex EDigitalIn.cpp ljackuw.lib


Hello,

Has anyone used the function Asynch in U12? it does not work and just let matlab crash. Matlab actually does not accept "data" in the function

[data errorcode idnum] = Asynch(idnum, demo, portB, enableTE, enableTO, enableDel, baudrate, numWrite, numRead, data)

It looks like there is a bug in the Matlab function.  The function crashes MatLab if you read data, but don't write any data.  Setting numWrite equal to numRead seems to work OK (doesn't crash).  I could get the function to work with the following syntax:

[data err id]=Asynch(-1,0,0,0,0,0,1200,18,18,0);

The problem looks like it has to do with the way the return data array is initialized when the function is called.  Matlab would also generate warnings if the numWrite parameter was less than numRead. Again an initialization problem (at a quick glance).  I think the work-around at this point is to always write the same number of bytes if performing a read.  This isn't the case when writing data though. Sending a zero in the numRead parameter doesn't cause the same problem.

[data err id]=Asynch(-1,0,0,0,0,0,1200,18,0,0);  Works OK.

Hello,

I see that the LabJack U12 is compatible with Mac OS and with Matlab, but is it possible to run Matlab (R2012) on my Mac and read data from the LabJack at the same time?

Thank you very much.

Scott

Hello,

can anyone explain why my LabJack will not give an output from this:

 

clear %Clear the MATLAB variables

ljAsm = ('G:\MATLAB\MATLAB_LJDotNET'); %C:\Program Files (x86)\LabJackU12Legacy\drivers\MATLAB_LJDotNET

idnum = -1;  %Using first found U12

demo = 0;  %Normal operations

lj.LabJack.GetDriverVersion = 12.0;

 

errorString = (['System.Char', 50]); %Empty string for error message

 

disp(['Driver version: ', num2str(lj.LabJack.GetDriverVersion())]);

 

%Setting analog outputs AO0 and AO1

analogOut0 = 3.2;

analogOut1 = 2.0;

disp(['Setting AO0 to ' num2str(analogOut0) ' V and AO1 to ' num2str(analogOut1) ' V.'])

 

 

there are no errors however neither analog output gives any output.

Did you call the EAnalogOut function like in the easyFunctions.m example to set the analog outputs? It should look something like this:

%Setting analog outputs AO0 and AO1
analogOut0 = 3.2;
analogOut1 = 2.0;
disp(['Setting AO0 to ' num2str(analogOut0) ' V and AO1 to ' num2str(analogOut1) ' V.'])
[errorCode, idnum] = lj.LabJack.EAnalogOut(idnum, demo, analogOut0, analogOut1);
if(errorCode ~= 0)
    lj.LabJack.GetErrorString(errorCode, errorString);
    disp(['EAnalogOut error ' num2str(errorCode) ' : ' char(System.String(errorString))])
    return
end

I'm using a MATLAB R2013b and MATLAB R2012a on Windows 7 32bit with a LabJack U3. After starting the program u3_simple I get the following error message:

UD Driver Version = 3.43
UD Error: Invalid channel number
Error using u3_simple (line 30)
Message: Fehler in der Anwendung.
Source: LJUDDotNet
HelpLink:

 

The message is German and means: Application error

The error is in the following line: ljudObj.ePut(ljhandle, LabJack.LabJackUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16);

All provided applications seem to work fine. The program LJ Control Panel is able to find the connected U3 and lists the firmware and hardware version. Any help is appreciated!

Tobias

We updated the examples to fix this problem:

http://labjack.com/support/ud/examples/matlab

For other users reading this, note the issue was in regards to the UD MATLAB examples in the link and not the the U12 examples on this page.

bagayby's picture

Hello, i am getting started with using U12 with matlab but i can't seem to find the LJDotNet.dll file. Does anybody know how or where i can find that file?

I am using Windows 10 x64 and Matlab R2015 x64 as well

LabJack Support's picture

The LJDotNet.dll file can be found in the U12 .NET download here:

http://labjack.com/support/u12/examples/dotnet

This is mentioned in the requirements in the README.txt. On this page, I added a link to the U12 .NET download page when the "U12 .NET assembly" is mentioned.