Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

help understanding code

Hi
I want to use GPIB card to control a Bruel & Kjær multiplexer.
The example code I'm given is,

ATN True
ASCII charater '4'
ATN False
0-12 binary && selects channel
ATN True
ASCII character '?'

I've installed the Olecontrol from component works, and tried the following,

with thisform.IEEE && olecontrol
.ChangePrimaryAddress(20)
If .isonline()=.F.
&&error
Return .F.
Endif

.write("ATN True")
.write('4')
.write("ATN False")
.write("0001") && channel 1
.write("ATN True")
.write('?')

endwith

I'm confused about the ATN(attention line) call. I can see on the instrument
that it goes to remote as soon as the first write is executed. The multiplexer
is a listener device so the '?' is also confusing.

Anybody got any suggest
ions.
0 Kudos
Message 1 of 4
(3,966 Views)
ignore this posting.

"Denis" wrote:
>>Hi>I want to use GPIB card to control a Bruel & Kjær multiplexer.>The example
code I'm given is,>>ATN True>ASCII charater '4' >ATN False>0-12 binary &&
selects channel>ATN True>ASCII character '?'>>I've installed the Olecontrol
from component works, and tried the following,>>with thisform.IEEE && olecontrol>
.ChangePrimaryAddress(20)> If .isonline()=.F.> &&error> Return .F.> Endif>>.write("ATN
True")>.write('4')>.write("ATN False")>.write("0001") && channel 1>.write("ATN
True")>.write('?')>>endwith>>I'm confused about the ATN(attention line) call.
I can see on the instrument>that it goes to remote as soon as the first write
is executed. The multiplexer>is a listener device so the '?' is also confusing.>>A
nybody
got any suggestions.
0 Kudos
Message 2 of 4
(3,966 Views)
Denis,

The B&K example is way too detailed and confusing. Unless you know the
lower level details of IEEE488 you'd never sort this out. This example
would be like telling someone what internet data packets are needed to
go to a website, instead of just saying www.ni.com.

The ATN line is one of the IEEE control lines. The GPIB controller sets
ATN true when it transmits an address or bus management command.

ASCII "4" with ATN true is LA4, or listen address 4 (not 20). This is
automatically sent by the write command.

(You can read about this in the NI488.2 for Windows Online Help, IEEE488
Command Messages.)

So the example is assuming that the B&K is set for GPIB address 4.

Then the example says "0-12 binary && selects channel"

I can only guess that " binary && selects channel" is intended as a
comment to you, the reader of the example. My guess is that all you
send is a single byte, with a "binary value" of 0 to 12. Since 12 is
obviously NOT a binary number, I think they mean 0 to 12 decimal:

0000 0000 0
0000 0001 1
0000 0010 2
....
0000 1010 10
0000 1011 11
0000 1100 12

In BASIC, or any derivative like QuickBasic or VisualBasic, you can use
the function CHR$(x) to create a single character byte with decimal
value of x.

So if you want to select channel 1, then use CHR$(1) to generate the
character (byte).

Then the example says ATN true and "?" character. Well, that's the UNL,
or unlisten command. This is automatically sent by the write command.

So, the ONLY write you would need is

write (chr$(1))

Mike

p.s. the example does not show how to read the channel. maybe this
device is so simple that all you do is read and it replies with the data
for the selected channel. many GPIB devices can reply with various data
so they typical require that you first write a query, and then do a
read.



Denis wrote:
>
> Hi
> I want to use GPIB card to control a Bruel & Kj�r multiplexer.
> The example code I'm given is,
>
> ATN True
> ASCII charater '4'
> ATN False
> 0-12 binary && selects channel
> ATN True
> ASCII character '?'
>
> I've installed the Olecontrol from component works, and tried the following,
>
> with thisform.IEEE && olecontrol
> .ChangePrimaryAddress(20)
> If .isonline()=.F.
> &&error
> Return .F.
> Endif
>
> write("ATN True")
> write('4')
> write("ATN False")
> write("0001") && channel 1
> write("ATN True")
> write('?')
>
> endwith
>
> I'm confused about the ATN(attention line) call. I can see on the instrument
> that it goes to remote as soon as the first write is executed. The multiplexer
> is a listener device so the '?' is also confusing.
>
> Anybody got any suggestions.


--
Mike T
0 Kudos
Message 3 of 4
(3,966 Views)
Thanks for your reply. I did some research (trial and error) and realised
that the supplied code could not be correct. Writing a decimal or ascii 4
could not give the required addres of 20 (they must of got confused with
ascii DC4). I then tried the decimal values for 1 to 12 and hey presto!
I've written to B&K with the corrected code, see below. Hopefully they will
make the changes to their manuals. Sorry that you have wasted your time.

ATN True
decimal 20 ( default address of multiplexer )
ATN False
0-12 decimal
ATN True
ASCII character "?" ( or decimal 63 - UNL )

It is correct that the write command sets the ATN. Using the activex control
from component works reduces the code to,

MyIEEE.ChangePrimaryAddress(20)
MyIEEE.write(chr(12))&&ascii char for channel 12

thanks again for your help.



Mike T wrote:
>Denis,>>The B&K example is way too detailed and confusing. Unless you know
the>lower level details of IEEE488 you'd never sort this out. This example>would
be like telling someone what internet data packets are needed to>go to a
website, instead of just saying www.ni.com.>>The ATN line is one of the IEEE
control lines. The GPIB controller sets>ATN true when it transmits an address
or bus management command. >>ASCII "4" with ATN true is LA4, or listen address
4 (not 20). This is>automatically sent by the write command.>>(You can read
about this in the NI488.2 for Windows Online Help, IEEE488>Command Messages.)
>>So the example is assuming that the B&K is set for GPIB address 4.>>Then
the example says "0-12 binary && selects channel">>I can only guess that
" binary && selects channel" is intended as a>comment to you, the reader
of the example. My guess is that all you>send is a single byte, with a "binary
value" of 0 to 12. Since 12 is>obviously NOT a binary number, I think they
mean 0 to 12 decimal:>>0000 0000 0>0000 0001 1>0000 0010 2>....>0000 1010
10>0000 1011 11>0000 1100 12>>In BASIC, or any derivative like QuickBasic
or VisualBasic, you can use>the function CHR$(x) to create a single character
byte with decimal>value of x.>>So if you want to select channel 1, then use
CHR$(1) to generate the>character (byte).>>Then the example says ATN true
and "?" character. Well, that's the UNL,>or unlisten command. This is automatically
sent by the write command.>>So, the ONLY write you would need is>>write (chr$(1))>>Mike>>p.s.
the example does not show how to read the channel. maybe this>device is
so simple that all you do is read and it replies with the data>for the selected
channel. many GPIB devices can reply with various data>so they typical require
that you first write a query, and then do a>read.>>>>Denis wrote:>> >> Hi>>
I want to use GPIB card to control a Bruel & Kj�r multiplexer.>> The example
code I'm given is,>> >> ATN True>> ASCII charater '4'>> ATN False>> 0-12
binary && selects channel>> ATN True>> ASCII character '?'>> >> I've installed
the Olecontrol from component works, and tried the following,>> >> with thisform.IEEE
&& olecontrol>> .ChangePrimaryAddress(20)>> If .isonline()=.F.>> &&error>>
Return .F.>> Endif>> >> write("ATN True")>> write('4')>> write("ATN False")>>
write("0001") && channel 1>> write("ATN True")>> write('?')>> >> endwith>>
>> I'm confused about the ATN(attention line) call. I can see on the instrument>>
that it goes to remote as soon as the first write is executed. The multiplexer>>
is a listener device so the '?' is also confusing.>> >> Anybody got any suggestions.>>>--
>Mike T
0 Kudos
Message 4 of 4
(3,966 Views)