Return Values using LJM in MATLAB under Linux? | LabJack
 

Return Values using LJM in MATLAB under Linux?

5 posts / 0 new
Last post
iandol
iandol's picture
Return Values using LJM in MATLAB under Linux?

This may well be my own ignorance, but in the exodriver, the methods directly returned values:

 

handle = calllib('liblabjackusb','LJUSB_OpenDevice',device,0,deviceID)

 

Making it easy to interface with MATLAB. But for LabJackM, only an error gets returned, and MATLAB doesn't modify the passed variables:

 

>> handle =  int32(0);

>> error = calllib('libLabJackM','LJM_Open',int32(4),int32(1),'ANY',handle)

error = 0

handle = 0

>> calllib('libLabJackM','LJM_GetHandleInfo',handle,a,b,c,d,e,f)

ans =

        1224

 

handle is not changed, although no error was found. Does anyone have an idea how to use the passed argument convention from MATLAB?

 

 

iandol
iandol's picture
Hm, OK, answering my own

Hm, OK, answering my own question and hopefully at least helpful to some other

 

https://www.mathworks.com/help/releases/R2019b/matlab/matlab_external/pa...

 

>> nDevices = libpointer('int32Ptr',0); devType = libpointer('int32Ptr',0)
>> error = calllib('libLabJackM','LJM_ListAll',int32(0),int32(0),nDevices,devType,[],[],[])

error =  0

>> nDevices.Value

ans =  int32  1

>> devType.Value

ans = int32  4

 

LabJack Support
labjack support's picture
When a parameter is passed by

When a parameter is passed by reference, such as the handle in LJM_Open, in MATLAB the input is in the function parameter and the output (updated value) is in the function return. For example:

[error, handle] = calllib('libLabJackM', 'LJM_Open', int32(4), int32(1), 'ANY', handle)

After loading the library, you can view functions with libfunctionsview which displays the arguments and returns of functions.

LabJack Support
labjack support's picture
Looks like you found an

Looks like you found an alternative solution with libpointer while I was typing my answer. Note with array parameters, their values get updated when passing the parameter, and not in the function return.

iandol
iandol's picture
OK, thanks for your promp

OK, thanks for your promp help, your support is excellent as always!