function [I] = LabInst_IvsV(lab_bench_nr,V,gpp_channel, current_limit)
% function [I] = LabInst_IvsV(lab_bench_nr,V,gpp_channel, current_limit)
%  sources V on gpp channel 'gpp_channel' and measures I on gdm on lab
%  bench number 'lab_bench_nr'.
% V can be a vector in which case a sweep is performed and I will be the
% corresponding vector of output values. Be sure to connect the current
% measurement ports on gdm! current_limit needs to be sufficiently high to
% allow V to be sourced.
% Author: Philipp Häfliger, 31-Jan-2025


hgpp=LabInst_GetHandle("gpp",lab_bench_nr)
hgdm=LabInst_GetHandle("gdm",lab_bench_nr)

I=zeros(1,length(V));
for s=1:length(V)
    GPP_SetVoltage(hgpp,gpp_channel,V(s),current_limit)
    pause(2);
    I(s)=GDM_GetCurrent(hgdm);
end; %for

LabInst_CloseHandle(hgpp);
LabInst_CloseHandle(hgdm);

plot(V,I)

end