Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

U6 Digital IO Using Matlab on Windows

Matlab

  • Please log in to reply
5 replies to this topic

#1 barry

barry
  • Members
  • 5 posts

Posted 16 July 2013 - 03:33 PM

Hi, 

 

I have a U6 that I use to send 8-bit "pulses" to an EEG amplifier via Matlab on OSX. When using matlab, I have been using labJack.m ([color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;]https://github.com/i.../communication/[/color]labJack[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;].[/color]m) to set up the initial handle and works beautifully. I am now trying to use my U6 on a windows 7 machine to do the same function. The labjack.m function that I have been using is designed for OSX/Linux and I've been running into issues getting the device setup appropriate so that I can see the pulses coming through. I have been able to use the MATLAB_LJUD to open the device, but that is about it. I'm wondering if someone can point me in the direction of other examples or matlab code that sets up the device in a manner similar to the function that I have been using on OSX.

 

Thanks in advance, 

barry

 



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 16 July 2013 - 03:54 PM

The LabJackUD implimentation in Windows as more funcationality than the Mac/Linux version.  It basically removes the need to build the commands yourself, and just tell the driver what you want the LabJack to do.  If you were interested in doing things that way, I would look at the .NET Matlab examples here.  Using the .NET library in Matlab removes the need for the LoadLibrary() calls which can sometimes be tricky to get working because Matlab's need for a compiler, which can vary based on which version of Matlab and if you are using a 32-bit or 64-bit version.  Though, the other method does work if you have things configured properly.

 

However, looking at your code it looks like you already create all the low level commands, so if you wanted to change your code as little as possible you could use the raw output/input functionality of the LabJackUD driver, which you can read about here.  Those commands will read/write the command you create to the LabJack directly.  That is supported with both interfaces for Matlab (in the standard one it would be LJ_ioRAW_OUT to send the command and LJ_ioRAW_IN to get the response.  In the .NET version it is LJUD.IO.RAW_OUT and LJUD.IO.RAW_IN).  Typically when working with raw commands I prefer the AddRequest() function instead of eGet/ePut since that way I can process the LJ_ioRAW_OUT and LJ_ioRAW_IN in the same driver call (GoOne()) so that I don't have to worry about timeout issues.  The raw In/Out support in the LabJackUD driver is by design a low level interface, so can be confusing in some cases.  If you run into anything you can't figure out feel free to post here or email us at [email protected]



#3 barry

barry
  • Members
  • 5 posts

Posted 17 July 2013 - 12:09 PM

Hi, 

 

Thanks very much for your response. It has been very helpful. Because I use both OSX and Windows, I'd basically like to change my code as little as possible. The code works well on OSX, however, the labJack.m function is not something that I wrote. I get the basic idea of what is going on, but it's unclear to me how best to add the raw input/output functionality so that once I make the call to labJack.m it works the same on both platforms. This largely reflects my ignorance about the coding. 

 

best, 

barry

 



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 18 July 2013 - 11:24 AM

MATLAB provides the "ispc" and "isunix" functions to determine if your script is running on Windows or Mac OS X. You can try using this in your code to determine what OS you are running, and then run the appropriate Windows or OS X code in labjack.m.

 

You use LJ_ioRAW_OUT/LJ_ioRAW_IN on Windows similar to the to the way you use LJUSB_Write/LJUSB_Read on OS X. Using both methods you send/read the same command/response byte array.



#5 barry

barry
  • Members
  • 5 posts

Posted 18 July 2013 - 11:40 AM

Hi,

 

Thanks for your response. I've tried this approach, but have been issues with the library. I have been loading labjackud, but when I try to calllibrary('labjackud','LJ_ioRAW_out') or even calllibrary('labjackud','LJud_...); Matlab returns an error saying the method is not found. Perhaps I'm not loading the appropriate library.

Do you have suggestions?



#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 18 July 2013 - 11:51 AM

LJ_ioRAW_OUT/IN are the IOType constants that you pass to functions. You will want to use the eGet or AddRequest/Go/GetResult functions and pass the LJ_ioRAW_OUT/IN to the IOType parameter. The raw output/input pseudocode page demonstrates this using the UD driver:

 

http://labjack.com/s...ers-guide/4.3.8

 

The MATLAB examples will demonstrate using the UD driver in MATLAB.

 

For the UD driver function reference look here:

 

http://labjack.com/s...users-guide/4.2





Also tagged with one or more of these keywords: Matlab

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users