help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

testing octave-instrument-control-toolbox using usbtmc to communicate wi


From: Jean Dubois
Subject: testing octave-instrument-control-toolbox using usbtmc to communicate with Keithley 2200
Date: Wed, 19 Dec 2012 13:06:38 +0100

2012/11/29, Hugo Coolens <address@hidden>:
> 2012/11/29 Stefan Mahr <address@hidden>
>
>>
>>
>> Hugo Coolens wrote:
>> > I'm trying out the octave-instrument-control-toolbox. I guess it
>> > installed fine, but as you can see below, running the sample program
>> > pops up a "sorry, printing char matrices not implemented yet", is
>> > there a workaround for this in Octave 3.2.4 or how should the code be
>> > adapted to get the text identification string which is (hopefully)
>> > sent back?
>> >
>> > thanks
>> > hugo
>> >
>> >
>> > octave:10> readbytes = 10000;
>> > octave:11> fd = usbtmc_open("/dev/usbtmc1")
>> > fd =  4
>> > octave:12> usbtmc_write(fd,"*IDN?");
>> > octave:13> result = usbtmc_read(fd,readbytes)
>> > result =
>> >
>> > sorry, printing char matrices not implemented yet
>> >
>> >
>> > octave:14> usbtmc_close(fd);
>>
>> I have answered Hugo already, but I forgot to include the mailing list.
>>
>> For the actual master branch at github use
>>    result = char(usbtmc_read(fd,readbytes))
>> to get the text string.
>>
>> Meanwhile I ported usbtmc to be included to OF instrument control within
>> the port2forge branch. The syntax will change a little bit, but you
>> still have to use char(usbtmc_read(obj,readbytes)) to get the result as
>> a string.
>>
>> BR,
>> Stefan
>>
> I finally got the first answer string coming back from my Keithley. Thank
> you very much Stefan for all your patience and the
> help offered
>
> Hugo
>
I now have a working script, many thanks to Stefan voor the
usbtmc-stuff. I'm sure it can be improved so suggestions are welcome
but don't shoot me:

clear
readbytes = 10000;
fd = usbtmc_open("/dev/usbtmc1");
usbtmc_write(fd,"SYST:REM");
usbtmc_write(fd,"*RST");
usbtmc_write(fd,"*IDN?");
identification = char(usbtmc_read(fd,readbytes));
disp('Found device: '),disp(identification)
timesleepdefault=input('Enter delay between measurements in seconds
(watch on display whether voltage has enough time to stabilize): ')
filename=input('Enter data file name: ','s')
file_id = fopen(filename, 'w')
startvalue=input('Enter current start value as a float (e.g. 0.001) or
in scientific notation (e.g. 1e-3): ')
endvalue=input('Enter current end value as a float (e.g. 0.001) or in
scientific notation (e.g. 1e-3): ')
nom=input('Enter number of measurements: ');
yesno=input('Do you want a linear sweep (y or n)? ','s')
switch yesno
 case{"Yes" "yes" "YES" "y" "Y"}
  value=1;
 case {"No" "no" "NO" "n" "N"}
  value=0;
 otherwise
  error("invalid value");
endswitch
if value==1
  disp('You have chosen a linear sweep')
  array=linspace(startvalue, endvalue, nom);
else
  disp('You have chosen a logarithmic sweep')
  array=logspace(log10(startvalue), log10(endvalue), nom);
end
disp('Array of current values which will be applied: '),disp(array)
maxvolt=input('Enter maximum voltage allowed over terminals: ')
#We want the results also to be available in a matrix y
y=[];
compliancestring=["SOUR:VOLT:PROT " num2str(maxvolt)];
#Put beeper on, beeps when protection limit is activated or when
something goes wrong
usbtmc_write(fd,"CONF:SOUN:STAT ON");
usbtmc_write(fd,"VOLT:RANG DEF");
#Next line is important if you want protection to work as expected,
#otherwise level will be limited to default value of 1V!!!
usbtmc_write(fd,"SOUR:VOLT:LEVEL 72");
usbtmc_write(fd,"SOUR:VOLT:PROT:STAT ON");
pause (timesleepdefault)
usbtmc_write(fd,compliancestring);
pause (timesleepdefault)
usbtmc_write(fd,"SOUR:OUTP:STAT ON");
#start measurements
for k=array
currentstring=["SOUR:CURR " num2str(k)];
usbtmc_write(fd,currentstring);
pause (timesleepdefault)
usbtmc_write(fd,"MEAS:CURR?");
pause (timesleepdefault)
resultcurr = char(usbtmc_read(fd,readbytes));
#strip line termination
resultcurr = resultcurr(1:end-1);
usbtmc_write(fd,"MEAS:VOLT?");
pause (timesleepdefault)
resultvolt = char(usbtmc_read(fd,readbytes));
y=[y; str2num(resultcurr) ,str2num(resultvolt)];
fprintf(file_id,'%s',resultcurr,' ',resultvolt);
end
usbtmc_write(fd,"OUTP:STAT OFF");
figure
plot(y(:,2),y(:,1),'b*',y(:,2),y(:,1),'m-')
xlabel('U [V]')
ylabel('I [A]')
disp('Goodbye, data logged in file: '),disp(filename)
usbtmc_close(fd);
fclose(file_id);

regards,
Hugo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]