Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to do NI-488.2 programming using GPIB Matlab Toolbox

510 views
Skip to first unread message

Chun-Yen Cheng

unread,
Jan 11, 2007, 3:50:52 AM1/11/07
to
Hello,

We'd like to control CAMAC via a GPIB/CAMAC interface module (LeCroy
8901a). We use NI GPIB-USB-HS as the interface to 8901a.

We also download GPIB Matlab Toolbox from <http://www.alamath.com/gpib.html>,
nd try to make it work with the example (in C) given in 8901A manual.

However, the 8901a does not response correctly. For example, with a
GPIB address of 3, i did the following (Matlab R14) to make 8901a to
listen ---

g = visa('ni', 'GPIB0::3::0::INSTR');

fopen(g);
ibsic(0)
ibtmo(0,12)
ibcmd(0,'0x23',2)
fclose(g);
delete(g);
clear g;

Well, it is NOT OK.

Can anybody tell me what went wrong ?
Wrong driver (gpib53.dll) ? or, wrong syntax ? ...

Thanks !

CY Cheng

RF

unread,
Jan 11, 2007, 10:21:15 AM1/11/07
to
So what is not ok?

From your first line of code it appears you are trying communicate
with your instrument using visa. However, since you are using the NI
gpib-usb-hs it is most likely easier to use the NI driver that is
supplied with the gpib-usb-hs interface. For the latter, follow the
NI driver installation instructions and then take a look at the
Matlab documentation under the heading "Controlling Instruments Using
the GPIB". Next look at the example under the sub-heading "Creating a
GPIB Object".

Just yesterday I set up an instrument as mentioned above with no
problems.

HTH
RF

RF

unread,
Jan 11, 2007, 10:34:49 AM1/11/07
to

Sorry, I didn't quite finish my first reply.

In my response above I assumed you are using the Matlab Instrument
Control Toolbox. As far as the download you mentioned (We also
download GPIB Matlab Toolbox from <http://www.alamath.com/gpib.html,)>.
I haven't heard of it and thus have no clue about it.

RF

Chun-Yen Cheng

unread,
Jan 15, 2007, 4:41:06 AM1/15/07
to
After some trial & error, we found:

(1) LeCroy 8901a can reponse to the GPIB Matlab Toolbox from <http://www.alamath.com/gpib.html>.
nd, using NI-488.2 utility program --- NI spy, we can monitor the
response of 488.2's commands.

However, it has some bug somehow ! By the following program, we can
successfully open, initialize, set transfer mode, and write command
word to LeCroy 8901a.

But, whenever, any of the 8-bit bytes of 24-bit word exceed 126 (d1,
or d2, or d3), CAMAC response went wrong !!

% --- Sample Code to initiate & write --- %
global gpibBd Device;
global pcTalk pcListen pcStandby;
global qx_Return; qx_Return = 0;

gpibBd = 0; addr = 3; sub_addr = 0; % LeCroy 8901a
pcTalk = char([64, 32 + addr]);
pcListen = char([32, 64 + addr]);
pcStandby = char([63, 95]);

Device = ibdev(gpibBd,addr,sub_addr,7,0,0); % open 8901a
ibrsc(gpibBd, 1); ibtmo(gpibBd,12);
ibsic(gpibBd); ibtmo(gpibBd,12); % clear GPIB interface
ibclr(Device); ibtmo(gpibBd,12); % clear GPIB device

ibcmd(gpibBd, pcTalk, 2);
ibwrt(Device, char(100), 1); % 24 bit normal mode
ibcmd(gpibBd, pcStandby, 2);

ibcmd(gpibBd, pcTalk, 2);
ibwrt(Device, char(33), 1); % initialize CAMAC
ibcmd(gpibBd, pcListen, 2);

ibcmd(gpibBd, pcTalk, 2);
ibwrt(gpibBd, char(72), 1); % inhibit CAMAC
ibcmd(gpibBd, pcListen, 2);

ibcmd(gpibBd, pcTalk, 2);
ibwrt(Device, char(100), 1); % 24 bit normal mode
ibcmd(gpibBd, pcStandby, 2);

d1 = 1; % first byte of data (24-bit word)
d2 = 1; % second byte of data (24-bit word)
d3 = 1; % third byte of data (24-bit word)
rw = char( [16 0 16 d1 d2 d3] ); % data for test
ibcmd(gpibBd, pcTalk, 2);
ibwrt(gpibBd, rw, 6) % write command & data
ibcmd(gpibBd, pcListen, 2);

ibonl(Device,0); % close 8901a
% --- End of Sample Code --- %

It seems we have to find some other way to send data byte by byte,
because the ascii has range of about 126 ?
How can we send them in binary way ?

(2) On the other way to talk to 8901a, we try the followig:

%% ------------------------------------ %%

gpibBd = 0; addr = 3; sub_addr = 0; % LeCroy 8901a
pcTalk = char([64, 32 + addr]);
pcListen = char([32, 64 + addr]);
pcStandby = char([63, 95]);

g = visa('ni', 'GPIB0::3::0::INSTR');
fopen(g);

fprintf(g,pcTalk)
fprintf(g,char(100))
fprintf(g,pcListen)

fprintf(g,pcTalk)
fprintf(g,char(33))
fprintf(g,pcListen)

fclose(g);
delete(g);

%% ------------------------------------ %%

However, nothing happen ....

So, we post the issue here, and wish some help ...

CY Cheng

Rafal

unread,
Mar 3, 2007, 9:46:23 AM3/3/07
to
I have similar communication problem via NI GPIB-USB-HS with GPIB
devices...
Can anybody help?

Rafal

Ankit Desai

unread,
Mar 3, 2007, 12:08:43 PM3/3/07
to
On Mar 3, 9:46 am, Rafal <rszu...@ire.pw.edu.pl> wrote:
> I have similar communication problem via NIGPIB-USB-HS withGPIB
> devices...
> Can anybody help?
>
> Rafal
>
> Chun-Yen Cheng wrote:
>
> > After some trial & error, we found:
>
> > (1) LeCroy 8901a can reponse to theGPIBMatlab Toolbox from <http://www.alamath.com/gpib.html>.
> > g =visa('ni', 'GPIB0::3::0::INSTR');

> > fopen(g);
>
> > fprintf(g,pcTalk)
> > fprintf(g,char(100))
> > fprintf(g,pcListen)
>
> > fprintf(g,pcTalk)
> > fprintf(g,char(33))
> > fprintf(g,pcListen)
>
> > fclose(g);
> > delete(g);
>
> > %% ------------------------------------ %%
>
> > However, nothing happen ....
>
> > So, we post the issue here, and wish some help ...
>
> > CY Cheng

I would recommend Instrument Control Toolbox for the task.

For controlling the instrument using GPIB object, check the following
link:
http://www.mathworks.com/access/helpdesk/help/toolbox/instrument/f13-5310.html

You can also try to communicate using device object.
http://www.mathworks.com/access/helpdesk/help/toolbox/instrument/f6-1007240.html

Instrument Control Toolbox provides driver for LeCroy 8600a that can
be used to communicate via TCPIP. You can try using that driver for
this instrument or modify the driver using 'midedit' function to suite
the needs.

Hope this helps,

-Ankit

Rafal

unread,
Mar 7, 2007, 8:40:30 AM3/7/07
to
ok,
finally I solved the problem.
There is no problem with using GPIB-USB-HS NI interface with Matlab.
In my case:
- It was need to install WinXP SP2 on my laptop (this SP include some
supprt for HS USB),
- There is no problem with Matlab 6.5 (but I had problems with Matlab
7 - there was some info about problems with drivers)
- standard commands (like for PCI GPIB cards) a=gpib('ni',0,20);
(where: 0 - board index - you can see it in the included software by
NI; 20 - address of my VNA), next like in Matlab manual:
g = gpib('ni',0,20);
fopen(g);
fprintf(g,'*IDN?');
idn = fscanf(g);
fclose(g);
You do not need any additional packages.
So,... 'NI GPIB-USB-HS' + notebook + Matlab = very nice and powerful
tool for mobile measurements.

Rafal

0 new messages