2.9 - GetFirstResult() and GetNextResult() | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


2.9 - GetFirstResult() and GetNextResult()

Calling either Go function creates a list of results that matches the list of requests. Use GetFirstResult() and GetNextResult() to step through the list of results in order. When either function returns LJE_NO_MORE_DATA_AVAILABLE, there are no more items in the list of results. Items can be read more than once by calling GetFirstResult() to move back to the beginning of the list.

UserData is provided for tracking information, or whatever else the user might need.

None of the Get functions clear results from the list. The first AddRequest() call subsequent to a Go call will clear the internal lists of requests and results for a particular device.

When processing raw in/out or stream data requests, the call to a Get function does not actually cause the data arrays to be filled. The arrays are filled during the Go call (if data is available), and the Get call is used to find out many elements were placed in the array.

It is acceptable to pass NULL (or 0) for any pointer that is not required.

The parameter lists are the same for the GetFirstResult() and GetNextResult() declarations.


LJ_ERROR _stdcall GetFirstResult (  LJ_HANDLE Handle,
                                    long *pIOType,
                                    long *pChannel,
                                    double *pValue,
                                    long *px1,
                                    double *pUserData)

Parameter Description:
Returns: LabJack errorcodes or 0 for no error.

  • Handle – Handle returned by OpenLabJack().


  • pIOType – A pointer to the IOType of this item in the list.
  • pChannel – A pointer to the channel number of this item in the list.
  • pValue – A pointer to the result value.
  • px1 – A pointer to the x1 parameter of this item in the list.
  • pUserData – A pointer to data that is simply passed along with the request, and returned unmodified. Can be used to store any sort of information with the request, to allow a generic parser to determine what should be done when the results are received.


Hello, I am trying to get a special range (0 to 3.6 volt) using the following code: I got a Labjack U3-LV but my program stop responding when either using GetFirstResult or GetNextResult and GetResult only gives me a zero. Wr is the channel. Written in C. 


Sleep(100); //Give time to Analog Input to read the valu




resultArray[ctrlinput] = dblValue7;


You should check the returns of your calls like in the C examples to see if an error code was returned, but my guess is that channel "wr" is not configured as an analog input. There is some pseudocode in the user's guide demonstrating how to configure lines to analog input:


Your AddRequest call looks fine, but I would recommend something like this for your GetFirstRequest for pointer safety:

GetFirstResult(lngHandle, &lngIOType, &lngChannel, &dblValue7, &px1, &pUserData);

If that doesn't help, check the returns of your calls for a clue on what is going on and so we can help further.

The problem is that I can't see what value is returning since the program stop responding completely. It was working correctly when reading voltages from 0 to 2.4 V (single-ended) but when I tried to use this special voltage reading, it stops working. Since I read from an excel file which establishes the pin configuration, wr stands for the pin I am configuring in that certain loop. I don't know if explain myself, is there any other way I can do a reading between 0 - 3.6 V. 

Did you try theGetFirstResult call I suggested where lngIOType, lngChannel, px1, and pUserData variables are declared and passed to prevent memory errors which could be the cause of your program. In my tests passing zeros was crashing my application as they are pass by reference.

You can try eAIN or eGet to read the analog input in one call:

eAIN(lngHandle, wr, 32, &dblValue7, 0, 0, 0, 0, 0, 0);

Also, for testing try commenting out your LabJack calls to make sure other parts of your code aren't causing your program to stop responding unexpectedly.

When using eAIN is working almost perfect, the only problem I am having is that when I declare two or more AIN, when getting the result, the first AIN gets the correct the voltages but the other gets incorrect voltages reading.



Real Input: 3.4, 2.8, 1.5, 1.1, 


First, lets try analog input testing using the test panel in LJControlPanel? Try connecting one of the U3's DACs to one if its analog inputs and change the DAC value to see the changes. Then try your signal that was producing the 3.4, 2.8, 1.5 and 1.1 voltages with the analog inputs and see if they look correct in the test panel.

Next, in your code what analog inputs are you trying to read from and what does your eAIN calls look like. Double check that you are setting the positive channel to the correct AIN and that you have a good connection to it.

Last, what is the source of your voltages?

georgsoerensen@gmail.com's picture

I'm trying to catch when their are no more results available by checking LJErr but it doesn't seem to work. (UD vers 3.50)

I program the ports and read them in something like:

For i = 0 to 15 

   if PortEnabled(i) then       LJErr = LJUD.AddRequest(handle, LJUD.IO.Get_AIN,i,0,0,0)

next i

LJUD.GoOne(handle)                  ' execute Port command

LJErr = LJUD.GetFirstResult(handle, iotype, channel, val, intval, dVal)


    LJErr = LJUD.GetNextResult(handle, iotype, channel, val, intval, dVal)

While End


' But, say I only program 1 port, when I read in that port (GetFirstResult...) my LJErr variable is NOERROR {0} and not LJE_NO_MORE_DATA_AVAILABLE.

If I then try to read GetNextResult a LabJackUDException is thrown.

I have been currently catching this exception and carrying on but I'd rather not have the exception thrown in the first place and actually use the LJE_NO_MORE_DATA_AVAILABLE.

I suppose I could just count how many results to expect and loop through that number, but I think I would rather get whats available and compare to what is expected and avoid the exception.

Have I missed something?  This looks to be the way to do it.


labjack support's picture

The UD .NET interface and its functions will throw an exception when there is an error instead of returning it. Exceptions cannot be turned off in its interface. When using a GetNextResult loop, if there is a LJE_NO_MORE_DATA_AVAILABLE error you will need to catch and handle its exception. In the VB .NET examples, the U3_AllIO demonstrates handling that exception to end a GetNextResult loop.

Alternatively, to avoid the LJE_NO_MORE_DATA_AVAILABLE error, as you mentioned you can count the number of requests and only do the needed amount of GetFirstResult/GetNextResult calls, or based on your provided request loop you can use GetResult like so to get the AIN results:

For i = 0 to 15 
    if PortEnabled(i) then
        LJUD.LJUD.GetResult(handle, LJUD.IO.GET_AIN, i, val)
        ' Do something with the AINi voltage val
    End If
next i