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

Matlab AIStreamRead


  • Please log in to reply
6 replies to this topic

#1 julius

julius
  • Members
  • 2 posts

Posted 11 November 2004 - 04:06 PM

Hi All, I am having difficulty getting matlab to call the .dll in Matlab v.7. I am hoping someone can give me a hand. I think I have AIStreamStart working: header='C:\Program Files\LabJack\drivers\ljackuw_Mat.h'; loadlibrary('ljackuw',header) idnum = int32(-1); pid = libpointer('int32Ptr', idnum); demo = 0; sioin = 0; upio = 0; ledon = 1; numc = 4; c(1:4) = int32([0 1 2 3]); pc = libpointer('int32Ptr',c); g(1:4) = int32(0); pg = libpointer('int32Ptr',g); sr = single(300); psr = libpointer('singlePtr',sr); discal = 0; r1 = 0; rc = 0; [err] = calllib('ljackuw','AIStreamStart',pid,demo,sioin,upio,ledon,numc,pc,pg,psr,discal,r1,rc) This returns err = 0; but the following doesn't seem to work for the AIStreamRead: lid = get(pid,'Value'); numscans = 1; timeout = 5; % this is to create an array of 4 single precision locations v(1:4096,1:4) = single(0); pv = libpointer('singlePtr',v); sio(1:4096) = int32(0); psio = libpointer('int32Ptr', sio); r = 0; pr = libpointer('int32Ptr',r); sb = 0; psb = libpointer('int32Ptr',sb); ov = int32(0); pov = libpointer('int32Ptr',ov); [err] = calllib('ljackuw','AIStreamRead',lid,numscans,timeout,pv,psio,pr,psb,pov); I can get errors of 1, 8, 30 and 32 depending how I adjust the input variables. I imagine the problem is with my pointers as this is the first time I have tried to use them. Two other less important questions: 1. Is there a downside to using the matlab functions available on your website rather than writing my own .dll calls? (e.g. speed). 2. When I use libfunctionsview('ljackuw'), how should I interpret the resulting string? More specifically, there appears to be many more inputs to each function than the user guide indicates there should be. Thanks very much.

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 15 November 2004 - 09:24 PM

No progress on your pointer/array issues yet, but for question #1 I can say you should not see any performance difference. If the special matlab driver layer works better for you go with it. I am not sure what you mean for question #2, so maybe you could post an example.

#3 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 16 November 2004 - 11:04 AM

We heard from a Matlab person about this issue. They provided the attached stream example (tested on 6.5.1), which I believe uses our special matlab drivers rather than direct DLL calls. They also mentioned that in your question 2 you might have been noticing that wht the direct DLL calls matlab displays all function parameters for inputs, and displays the return value (errorcode) followed by all pointer type parameters for outputs.

Attached Files



#4 julius

julius
  • Members
  • 2 posts

Posted 16 November 2004 - 02:26 PM

First off, thanks to you and the anonymous matlab person for your help. The attached file works well. It appears to call the .dll files directly and not the matlab functions that you can download from your site. Also, I believe you are right about the format of the function parameters. I am still having a few problems. I would like to modify the contributed code for a single differential channel. I managed to change AIStreamStart to get it to work by increasing the ScanRate to 200. I also have the following: Channels = int32([8]); Gains = int32([5]); Voltages = single(zeros(4096,1)'); IOOut = int32(zeros(4096,1)); ScanRate = 200; [a1 id c d e] = calllib('ljackuw','AIStreamStart',-1,0,0,0,1,1,Channels,Gains,ScanRate,0,0,0); numScans= 200; [a2 Voltages c d e f] = calllib('ljackuw','AIStreamRead',id,numScans,10,Voltages,IOOut,0,0,0); AIStreamRead does not work and returns the errorcode 8 which is "Invalid Array Size of Value". I think the problem is likely in my understanding of numScans. I would love some help. I also don't understand where the 4096 size of the voltage array comes from. What would be really great is if all the parameters could be put in terms of a subset of the parameters (eg. channel Sampling Frequency, the number of channels, etc..). For example, the original submission could be rewritten as (I think): Channels = int32([1 4 2 3]); Gains = int32(zeros(size(Channels))); SampleFreq = 50; numChan = length(Channels); numScans= 200; ScanRate = SampleFreq*numChan; Voltages = single(zeros(4096,numChan)'); Voltages = single(zeros(4096,1)'); IOOut = int32(zeros(4096,1)); [a1 id c d e] = calllib('ljackuw','AIStreamStart',-1,0,0,0,1,4,Channels,Gains,ScanRate,0,0,0); [a2 Voltages c d e f] = calllib('ljackuw','AIStreamRead',id,200,10,Voltages,IOOut,0,0,0); One last question: Am I on the right track in using AIStream to collect and display data continuously? Thanks!

#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 16 November 2004 - 03:20 PM

Now that the DLL call is working in Matlab, we can refer to Section 4.9 of the U12 User's Guide. You need to pass a 4096x4 buffer, filled with zeros, regardless of how much data you are actually reading, so change the array declaration back to: Voltages = single(zeros(4096,4)'); Also note that if you make multiple calls to AIStreamRead (as is typically done in stream mode), you need to set every element of both arrays to zero before each call. Looking at the example, the comment should say 50 scans/second (not 50 samples/second). Also, when I stream I typically set numScans = scanRate such that you get 1 read per second. If you need continuous data at 50-1200 samples/second, then stream is the way to go. For slower data, you can just use AISample with software timing. Check out the following about U12 data rates:

#6 pierre

pierre
  • Members
  • 4 posts

Posted 18 April 2013 - 09:39 AM

Hi, I try t use the functions AIStream and I get Retval=27 for the AIStreamStart and Retval=7 for the AIStreamRead. This is my program: % unload of the library ljAsm = NET.addAssembly('c:\Program Files\LabJackU12Legacy\drivers\LJDotNet.dll'); %initialisation AIStreamStart idnum=-1; demo=0; stateIOin=0; updateIO=0; ledOn=1; numChannels=2; channels=[0 1]; %Read from AIN0 and AIN1 gains=[0 0]; %Gain index set to 0 scanRate=150; disableCal=0; reserved1=0; readCount=0; [RetVal,idnum,scanRate] = lj.LabJack.AIStreamStart(idnum,demo,stateIOin,updateIO,ledOn,numChannels,channel s,gains,scanRate,disableCal,reserved1,readCount) %initialisation AIStreamRead localID=idnum; numScans=2048; timeout=1; voltages=single(zeros(4096,4)); stateIOout=zeros(4096,1); reserved=0; ljScanBacklog=0; overVoltage=0; %Plot Voltages [RetVal,reserved,ljScanBacklog,overVoltage]=lj.LabJack.AIStreamRead(localID,numS cans,timeout,voltages,stateIOout,reserved,ljScanBacklog,overVoltage) I have been looking for a while so I would be glad if someone can help me.

#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 18 April 2013 - 11:17 AM

U12 errorcode 27 is "maximum number of streams"

http://labjack.com/s...sers-guide/4.40

Sounds to me like the stream is already running? Perhaps close all software and power cycle the U12? Perhaps add a call to AIStreamClear at the beginning of your program?


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users