%Create an instance of the MATLAB riDevice and open it.
device = riDevice();

%To specify which device is opened specify your serial number:
%device = riDevice('FXXXX-BXXXX-XX')
highgain = true;
device.set_antialias(true);
device.set_highgain(highgain);

%Capture 1000 samples from your instrument.
nsamples = 1e3;
data_ADC_bits = device.get_raw_data(nsamples);

%Convert to uW. A and B are found on your calibration sheet.
if (highgain == true)
    A =  4.62e-03;
    B = -2.48e-00;
else
    A =  1.84e-02;
    B = -1.04e+01;
end

%Get the resposivity at the wavelength of interest
R = device.get_relative_responsivity(800);

data_micro_watts = double(data_ADC_bits) * A * R + B;

%Plot the data
time_ms = linspace(0, nsamples / 80e3, nsamples);
plot(time_ms, data_micro_watts);
xlabel('Time (ms)');
ylabel('Power (\muW)');

%close the connection to your device
device.close();
