function [ ljudObj, ljhandle ] = SetUp_LJ()

%THis sets up the labjack and specifies what i/o is to be read.  The setup
%here and the reads in GetLJ.m and teh writes in SetLJ.m are related and must match
%
%AIO0 - 16bit Analog input, 
%AIO1 - 16bit Analog input
%DAC0 - analog output
%DAC1 - analog output
%FIO0 - digital output
%FIO1 - digital output

ljudObj = LabJack.LabJackUD.LJUD;

try
    %Read and display the UD version.
    disp(['UD Driver Version = ' num2str(ljudObj.GetDriverVersion())])
    %Open the first found LabJack UE9.
    [ljerror, ljhandle] = ljudObj.OpenLabJack(LabJack.LabJackUD.DEVICE.UE9, LabJack.LabJackUD.CONNECTION.USB, '0', true, 0); 
    
    %Configure for 16-bit analog input measurements.
    ljudObj.ePut(ljhandle, LabJack.LabJackUD.IO.PUT_CONFIG, LabJack.LabJackUD.CHANNEL.AIN_RESOLUTION, 16, 0);
    %Configure the analog input range on channels 0 and 1 for bipolar gain=1 (LJ_rgBIP5V = 3).
    ljudObj.ePut(ljhandle, LabJack.LabJackUD.IO.PUT_AIN_RANGE, 0, 3, 0);
    ljudObj.ePut(ljhandle, LabJack.LabJackUD.IO.PUT_AIN_RANGE, 1, 3, 0);  
    
    %ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_DAC, 0, 2.5, 0, 0);
    
    %Set digital output FIO2 to output-low.
    %ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_BIT, 2, 0, 0, 0);

    %Now we add requests to write and read I/O.  These requests
    %will be processed repeatedly by go/get statements in every
    %iteration of the while loop below.    
    
    %Request AIN0 and AIN1.
    %ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.GET_AIN, 0, 0, 0, 0);
    %ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.GET_AIN, 1, 0, 0, 0);
         
    %Read digital inputs FIO3 through FIO7.
    %ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.GET_DIGITAL_PORT, 3, 0, 5, 0);
    %Request the value of Counter0.
    %ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.GET_COUNTER, 0, 0, 0, 0);   
catch e
    showErrorMessage(e)
end

end

