VISA (GPIB) connection - syntax correct but instrument not understanding commands

8 vues (au cours des 30 derniers jours)
Darin
Darin le 31 Jan 2012
Hi All! A bit of a problem getting an instrument to understand what I am passing it, any advice would be very much appreciated!
Background:
  • I am sending commands to a semiconductor analyzer from Agilent
  • I am connecting via a USB-to-GPIB interface
Symptoms:
  • A connection tool verifies that I have a successful connection
  • a connection tool also provides a console in which I can enter texts commands (the same as the ones I pass through matlab), and this works perfectly.
  • when I connect to the instrument via matlab with the Instrument Control Toolbox, using code like the below, the connection seems to be successful (see next bullet), but the commands that I deliver are not.
  • When I send a command (via fprintf()), I get no immediate error in the matlab window, but using the console I can query the instrument for errors, and I get a "command not understood" error. So the instrument is receiving something, but it isnt understanding it
  • When I query the instrument (via fscanf()), I get a VISA timeout error in the matlab window, and the same error as usual from the instrument.
An example of the code that I use is the following; I believe it is correct syntax because this code and others have been provided by the manufacturer, and because similar code that I have written based on these examples and those in the instrument control API have been verified to be correct syntax by the manufacturer:
%Test code to verify instrument and Matlab connectivity
%Close any old instrument connections
newobjs = instrfind; %Find all previously connected instruments
if (length(newobjs)~=0)
fclose(newobjs);
delete(newobjs);
end
instrument = visa('agilent', 'GPIB0::17::INSTR'); %set variable to instrument
fopen(instrument); %connect to the instrument
fprintf(instrument,'*IDN?'); %query instrument
idn = fscanf(instrument) %read from instrument
fclose(instrument); %disconnect from instrument
delete(instrument); %remove instrument from memory
clear instrument idn newobjs A %remove variable from memory

Réponses (2)

Darin
Darin le 1 Fév 2012
Problem solved. By default (I don't know why), EOSMode is set to 'none', i.e. no terminator string is sent with commands to the instrument, so it just sees a long string. Setting EOSMode to 'read&write' worked perfectly.
code:
instrument=VISA('agilent','GPIB0::17::INSTR')
instrument.EOSMode='read&write'
or
set(instrument, 'EOSMode','read&write')
  1 commentaire
Walter Roberson
Walter Roberson le 1 Fév 2012
Huh, so I had the right basic cause but it was implemented a quite different way!

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 31 Jan 2012
Before you fopen(instrument), get(instrument,'Terminator') and see what that says, and see if it matches the end-of-line sequence that the device is expecting.
  3 commentaires
Walter Roberson
Walter Roberson le 31 Jan 2012
Okay, that turned out to be a false lead on my part.
fprintf() for devices turns out to use %s\n as the default format, with the \n meaning newline. This differs from fprintf() for serial ports, which also use %s\n as the default format, but for those the \n means the Terminator string of the device.
488.2 compatible instruments use \n (meaning newline) as their line terminator, I see now.
Sorry, I do not have any further ideas at this time.
Walter Roberson
Walter Roberson le 1 Fév 2012
Ah: the \n for fprintf() for an instrument turns out to mean send the EOS character, http://www.mathworks.com/help/toolbox/instrument/eoscharcode.html . Same basic issue as with serial ports. Except, as Darin located, there is an EOSMode that determines whether the EOS is sent or not; http://www.mathworks.com/help/toolbox/instrument/eosmode.html
Sigh.
Join my Facebook "One World, One Newline" campaign!

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by