Thread Subject: How to do NI-488.2 programming using GPIB Matlab Toolbox

Subject: How to do NI-488.2 programming using GPIB Matlab Toolbox

From: Chun-Yen Cheng

Date: 11 Jan, 2007 03:50:52

Message: 1 of 7

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

Subject: How to do NI-488.2 programming using GPIB Matlab Toolbox

From: RF

Date: 11 Jan, 2007 10:21:15

Message: 2 of 7

Chun-Yen Cheng wrote:
>
>
> 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
  
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

Subject: How to do NI-488.2 programming using GPIB Matlab Toolbox

From: RF

Date: 11 Jan, 2007 10:34:49

Message: 3 of 7

RF wrote:
>
>
> Chun-Yen Cheng wrote:
>>
>>
>> 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
>
> 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

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

Subject: How to do NI-488.2 programming using GPIB Matlab Toolbox

From: Chun-Yen Cheng

Date: 15 Jan, 2007 04:41:06

Message: 4 of 7

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

Subject: How to do NI-488.2 programming using GPIB Matl

From: Rafal

Date: 3 Mar, 2007 09:46:23

Message: 5 of 7

I have similar communication problem via NI GPIB-USB-HS with GPIB
devices...
Can anybody help?

Rafal

 Chun-Yen Cheng wrote:
>
>
> 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

Subject: How to do NI-488.2 programming using GPIB Matl

From: Ankit Desai

Date: 3 Mar, 2007 09:08:43

Message: 6 of 7

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>.
> > 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); % clearGPIBinterface
> > ibclr(Device); ibtmo(gpibBd,12); % clearGPIBdevice
>
> > 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

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

Subject: How to do NI-488.2 programming using GPIB Matl

From: Rafal

Date: 7 Mar, 2007 08:40:30

Message: 7 of 7

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

 Rafal wrote:
>
>
> I have similar communication problem via NI GPIB-USB-HS with GPIB
> devices...
> Can anybody help?
>
> Rafal
>
> Chun-Yen Cheng wrote:
>>
>>
>> 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 ...
>>
>>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com