0% found this document useful (0 votes)
104 views6 pages

Ins and Outs of Oscilloscope Programming: Examples in C and Microsoft Visual Basic

This document discusses programming digitizing oscilloscopes using C and Visual Basic. It provides examples to illustrate how to open an instrument session, configure settings, trigger and acquire waveforms, query preamble and waveform data, and close the session. The examples are designed to work with Agilent Infiniium and DSO1000 series oscilloscopes using the Agilent IO Libraries SICL and VISA interfaces. Key points like data formats, scaling factors, and byte ordering are discussed.

Uploaded by

parisalitopan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views6 pages

Ins and Outs of Oscilloscope Programming: Examples in C and Microsoft Visual Basic

This document discusses programming digitizing oscilloscopes using C and Visual Basic. It provides examples to illustrate how to open an instrument session, configure settings, trigger and acquire waveforms, query preamble and waveform data, and close the session. The examples are designed to work with Agilent Infiniium and DSO1000 series oscilloscopes using the Agilent IO Libraries SICL and VISA interfaces. Key points like data formats, scaling factors, and byte ordering are discussed.

Uploaded by

parisalitopan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Ins and Outs of Oscilloscope Programming

Examples in C and Microsoft Visual Basic


At the heart of a digitizing oscilloscope is an analog to digital converter (A/D) !he A/D samples the signal at the oscilloscope"s input millions# or in some cases# $illions of times per second %or ever& sample a $inar& pattern representing a voltage is output from the A/D and stored in memor& 'scilloscopes use the data points stored in memor& to produce a plot of the signal"s voltage over time !his functionalit& ma(es a digitizing oscilloscope one of the most popular pieces of general)purpose test and measurement e*uipment !o ma(e oscilloscopes even more valua$le# programming offers a means of automating the process of oscilloscope configuration and +aveform ac*uisition ,hether the need is to export +aveform data to a -C for further anal&sis or to automate the configuration and ta(e a fe+ *uic( measurements# most modern oscilloscopes provide flexi$le remote programming capa$ilities !his article +ill illustrate ho+ to +rite oscilloscope programs in general +ith a fe+ examples for oscilloscopes from Agilent !echnologies also given for reference .nterfacing the 'scilloscope and -C !he first decision that needs to $e made is +hat interface to use /ome possi$ilities include 0/)121# 3-.B# and the 4A5 to 3-.B gate+a& !his choice depends on +hat interfaces are availa$le on the oscilloscope and the -C !he choice of interface also dictates +hat drivers +ill $e re*uired to send commands to the oscilloscope !he examples contained later in this article rel& on the /.C4 ./' soft+are la&er included in the Agilent !echnologies IO Libraries !he examples ma(e use of the /.C4 ./' la&er to send commands such as 6,AVeform6%'0Mat ,'0D and *ueries li(e 6,AVeform6DA!A7 to the oscilloscope and then capture an& replies 8sing a standard ./' la&er li(e /.C4 removes the difficult tas( of tr&ing to communicate directl& to the computer"s hard+are /.C4 includes all of the functionalit& needed to transmit commands and *ueries/replies $et+een the oscilloscope and -C through an& of the previousl& mentioned ./' interfaces !he Agilent !echnologies IO Libraries also include a soft+are ./' la&er called V./A V./A is a standard that several manufacturers have adopted to allo+ interchangea$le $ehavior across several different $rands of interfaces# most nota$l& $rands of 3-.B interfaces .n Agilent"s case# V./A commands are actuall& translated to /.C4 and then /.C4 controls the hard+are B& +riting programs that use functions from the /.C4 li$rar& directl&# the programmer can eliminate need for the computer to translate the V./A commands to /.C4# ho+ever sacrifices some code porta$ilit& due to the proprietar& nature of /.C4

%or further information on /.C4 or V./A# perform a *uic( search at the Agilent !echnologies !est and Measurement +e$ page for 9/.C4: or 9V./A: (+++ tm agilent com) -rogram %lo+ Most oscilloscope programs follo+ a standard model !his model is closel& related to ho+ an oscilloscope operates and resem$les the steps ta(en $& someone operating the oscilloscope from the front panel !o illustrate# this flo+chart sho+s a simplified programming model for oscilloscopes +hen data +ill $e do+nloaded to a computer for anal&sis6

Open Instrument Session to Oscilloscope

Reset Oscilloscope to Factory Defaults

$onfigure Oscilloscope Settings

Digitize Waveform

Oscilloscope Fills Pre-trigger Memory

TRIGG R! # S Oscilloscope Fills Post-trigger Memory

"O

$onfigure Oscilloscope Data Format for %port

&uery Pream'le (scaling factors) an* Waveform Data

$onvert Waveform Data to +oltage, Time Pairs

$lose Instrument Session an* Release Memory

!his model is not +ritten in concrete and can var& if the programmer doesn"t need to do+nload the +aveform data# for instance .n that case# less +or( is re*uired $ecause some steps can $e eliminated As &ou can see from the a$ove flo+ chart# this oscilloscope model is centered on the trigger event !he first part of an oscilloscope program is dedicated to preparing for the trigger# +hereas the second part is dedicated to utilizing the data captured in the oscilloscope"s memor& .t is important that there is some s&nchronization in place so that the program is a+are of +hen the oscilloscope has triggered and ac*uisition is complete !his is performed in the example programs $& means of the 6D.3itize command !he digitize command is designed to tell the oscilloscope to perform a single)shot ac*uisition But more than ;ust performing a single)shot ac*uisition +hich could have $een performed +ith a 6/.53le command# the 6D.3itize command prevents the oscilloscope from accepting further commands until the oscilloscope has triggered and filled memor& Careful planning is re*uired to ensure that the interface does not time out if a trigger is not found immediatel& /everal means exist for handling this situation li(e use of /0<s or increasing the interface"s timeout setting =o+ever# since handling timing events li(e this re*uires a length& explanation# it is $etter left to descriptions in the oscilloscope"s manual and the documentation on the interface/driver $eing used As previousl& stated# the a$ove model is $ased on a single)shot ac*uisition !his means the oscilloscope +ill simpl& stop after filling memor& .f the oscilloscope is given a 6085 command rather than a 6/.53le command or 6D.3itize command# the oscilloscope continuousl& updates =o+ever# unless the user +ants to vie+ the results on the oscilloscope"s displa&# it is not a trivial matter to (eep the program s&nchronized +ith a continuousl& changing data set !herefore# all examples included rel& on the single)shot ac*uisition mode At this ;uncture# it is pro$a$l& $est to start dealing +ith real examples to illustrate the principles mentioned a$ove !here are four oscilloscope program examples $elo+ !+o examples are in C and t+o are in Microsoft Visual Basic (VB) !he programs +ere developed to +or( +ith the .nfiniium and the >?@1A famil& of oscilloscopes from Agilent !echnologies /everal differences exist $et+een these oscilloscopes !here is also a significant difference $et+een ho+ C and VB deal +ith varia$le t&pes A discussion of these differences and hints on ho+ to +rite &our o+n customized program can $e found follo+ing the code Examples !he follo+ing examples are do+nloada$le in zip format %or the C programming examples# onl& the source code is included (console applications) %or the VB examples# the pro;ect +or(space is included and $est vie+ed $& opening it in Microsoft Visual Basic .f Microsoft VB is not loaded on the computer &ou are currentl& using# a text editor can $e used to loo( at the source code minus the 38. (contained in the formB frm form file and the ModuleB $as file) -roper configuration of the environment varia$les is

necessar& in $oth C and VB %or more information# see chapter 1 of the Agilent /.C4 8ser"s 3uide for ,indo+s titled 93etting /tarted +ith /.C4: >?@1A /eries 'scilloscope -rogram in C version @ C (generates scdata txt output) >?@1A /eries 'scilloscope -rogram in VB version @ C .nfiniium /eries 'scilloscope -rogram in C version @ C (generates scdata txt output) .nfiniium /eries 'scilloscope -rogram in VB version @ C De& -oints B !he .nfiniium oscilloscope supports a command for setting the memor& depth prior to capturing a +aveform (96AC<uire6-'.5ts EnF:) ,ith the .nfiniium# this is actuall& the num$er of points that +ill $e ac*uired !he >?@1A series also can accept a command re*uesting a certain num$er of +aveform points prior/after the 6D.3itize command# $ut +hat this does is compress the +aveform after it has $een ac*uired (96,AVeform6-'.5ts EnF:) !he .nfiniium saves the +aveform points in a signed integer format !he >?@1A series stores the +aveform points in unsigned or signed format !his is an important piece of information +hen programming in Visual Basic Visual Basic does not support an integer varia$le t&pe that is unsigned and B@ $its +ide /ince these examples utilize the ,'0D data format and the default is to store the data in unsigned format# the data from the >?@1A +as read into a $&te arra& in VB .t could $e argued that it +ould have $een easier to ;ust use the signed format from the oscilloscope# $ut since these examples are meant to illustrate concepts# unsigned +as used Calculating the voltage values is a $it more complicated since the +ords are stored as pairs of $&tes ,hen the oscilloscope digitizes a +aveform# t+o things are stored !hese are the pream$le and +aveform data !he pream$le has the scaling factors to translate the integers in the +aveform data to floating point voltage values !hese can $e *ueried individuall& or as an arra& Both methods are demonstrated in the examples ,hen using ,'0D format for the +aveform data# care has to $e ta(en to ensure that the data is stored in the correct $&te order !he 96,AVeform6BG!eorder E4/B%irst H M/B%irstF: command tells the oscilloscope ho+ &ou expect to receive the data /ome pointer t&pe casting is used in the C examples to allo+ the iread function to fill B@)$it +ide elements of an arra& =o+ever# great care should $e ta(en +hen performing an operation li(e pointer t&pe casting to ensure that ever& $it is dealt +ith correctl& /ee the program comments for more explanation

>

%or trou$leshooting an oscilloscope program# it is good to have a $asic understanding of de$ug tools +ithin the compiler Most compilers allo+ stepping through individual lines of code ,atching the oscilloscope as each command is sent can give a clue to +here a pro$lem is hiding in the program !here are times +hen the onl& indication of a $ad command is a small pop)up message on the oscilloscope"s screen stating 9.nvalid =eader: or something similar !his message t&picall& is missed $ecause it disappears too *uic(l& +hen executing the program at full speed ,hen +riting an oscilloscope program# al+a&s read the header of the $inar& $loc( +hen *uer&ing the +aveform data /ometimes the scope returns a different num$er of $&tes than +hat is expected in the earl& stages of program development ($efore $ugs are all +or(ed out)# ho+ever the header al+a&s specifies ho+ man& $&tes are to follo+ in the $loc( At times it seems a $it of extra +or( tr&ing to properl& process the header# $ut it is +ell +orth it .f it is not done# some of the $&tes from the header +ill inevita$l& $e read as part of the +aveform data and cause a great deal of confusion %or more information on $inar& $loc( format# refer to the oscilloscope"s programming guide (specificall& the 96,AVeform6DA!A7: *uer&) !he example programs +ere tested +ith a BC6B passive pro$e on channel B connected to the oscilloscope"s front)panel cali$ration signal !his meant there +as al+a&s a trigger event availa$le almost immediatel& after the 6D.3itize command +as sent =o+ever# that is often not the case in real +orld applications ./' interfaces have timeouts to prevent individual commands from holding up the interface indefinitel& !herefore# either the timeout has to $e increased or interrupt handling should $e used !his is application)dependent and re*uires a long discussion involving specifics of the instrument"s service re*uest register structure -lease refer to the oscilloscope"s programming guide for further details

You might also like