Writing Your Own Driver Programs to Control Instruments

Tags

Writing Your Own Driver Programs to Control Instruments

Driver Manual

Writing Your Own "Driver" Programs to Control Instruments

Ralph and Rachel Rosenbaum and Avraham Semenkee, TAU, Physics

Refer to the LabVIEW Manual where we learned to communicate between the Hewlett Packard programmable Digital Multimeter and our PC using the GPIB. We used three icons to communicate with programmable instruments, the "Initialize” Icon, the "Application” Icon and the "Close” Icon. National Instruments has written these three drivers using the SCPI commands (Standard Commands for Programmable Instruments). The SCPI commands are “invisible” to us in these three “Initialize”, “Application” and “Close” Icons.

However, if we want complete control over the instrument and want complete independence from National Instrument's driver programs, then we must write our own set of SCPI commands, namely we write our own driver program! This task requires that you are familiar with the fine details of the instrument's operations and you are very familiar with its set of SCPI commands. Thus, you must read and understand the instruction manual of the instrument very well. We will use two new icons for writing our own driver program, namely the "VISA WRITE” Icon and the "VISA READ” Icon. VISA stands for "Virtual Instrument Software Architecture". We wish to write the following program:

“Front Panel”

“Block Diagram”

To begin to write our “driver” program, go back to the LabVIEW Manual and repeat steps 1 through 9 to get the following dialog box again:

10.Now click on the “VISA” icon to get a new dialog box that contains several new icons. Choose the following two icons:

and drag these two icons onto the “Block Diagram”. Note that “W” stands for writing data to the instrument from our PC; and “R” refers to the instrument sending back measured data to our PC or equivalently that the PC reads the data from the instrument.

“Block Diagram”

11. / Take the “Connect Wire Spool” tool and go to the left hand border of the “VISA abc W” Icon, to display its various terminals. Select the terminal with the name “VISA Resource” and click on the right button of your mouse to get the following two dialog boxes: /

Select the “Control” by first clicking on the “Create” and on the “Control” buttons for importing an ASCII string of letters. Now go over to the “Front Panel” and by using the edit tool, write the following string into the small “VISA resource name” window: “GPIB::12::INSTR”. Remember that we programmed the address number #12 into the HP 34401a DMM earlier.

12. / Now return to the “Block Diagram” window. We now connect up two different wires between the two VISA icons. Again, using the “Connect Wire Spool” tool, go to the right hand border of the “VISA abc W” Icon, and find the terminal labelled: “dupVISA resource name”. Drag the wire now to the second icon, the “VISA abc R” and find the terminal on its left border with the name “VISA resource name”. Connect these two terminals together.
Repeating the same procedure, connect a wire between the “error” terminals: namely connect the wire to the “Error Out” terminal on the “VISA abc W” Icon and to the “Error In” terminal on the “VISA abc R” Icon. /


13.Finally we would like to read out the actual DMM readings. To do this, go to the right hand side or border of the “VISA abc R” Icon and find the terminal with the name “read buffer terminal”. Click on this terminal using the right hand mouse button, again to get the two dialog boxes we have used earlier. Namely, choose the “Create” button in the first box and then choose and click on the “Indicator” button.

But we also have to reserve RAM memory for these data readings from the DMM! Depending upon the number of readings you choose to measure, we will need a minimum of 100 bytes up to about 1000 bytes of RAM. To reserve RAM memory space, go to the left hand side of the “VISA abc R” icon and find the terminal with the name “Byte Count”. Again using the right button on the mouse, display the two dialog boxes and choose “Create” followed by “Control”. Now on the “Front Panel” write into the Byte Count little window a reasonable number of RAM bytes, say 200 to 400 bytes of RAM memory.

  1. Now the BIG MONENT has come for us to write our own “Driver Program”. We will have our HP 34401a DMM make five (5) dc voltage readings. We will use the SCPI command language. Recall that we set the I/O menu to respond to the SCPI language on the DMM. Go to the “Front Panel” and activate the little “write buffer” window with the following SCPI commands using the “edit” tool . Note that you will have to enlarge the “write buffer” window using the pointer tool. You can make this window as large as you wish. Now write into it the following SCPI commands:

CommandOperationCommentsKey Operation

*RSTReset DMMIEEE 488 commandhit “enter” key

*CLSClear DMM Status RegisterIEEE 488 commandhit “enter” key

CONF;VOLT:DC 10,.01

choose dc Volts, 10 volt range, and accuracy to 0.01 volt

SCPI commandhit “enter” key

TRIG:COUN 5

make 5 measurementsSCPI commandhit “enter” key

TRIG:SOUR IMM

use the DMM’s internal triggeringSCPI commandhit “enter” key

READ?DMM now makes 5 readingsSCPI commandhit “enter” key

15. Your final program should look like the “Block Diagram” that appears on page 2. Run the program, using the "run" key on the tool bar.

16. Read out the five voltage readings that should appear in the "read buffer" window on the “Front Panel”. You will probably have to enlarge this window to see all five readings.

If you succeeded, CONGRATULATIONS! You have written a successful "driver program". Note the similarity of this program and the "driver program" you wrote using Visual Basic and the RS232 serial interface bus. The driver programs are the same - it is only the different ways that you transfer the SCPI commands to the instrument. The fast but expensive way is using the GPIB bus or the cheap slow way is using the serial RS232 bus!

Here is a data acquisition LabVIEW program that has the DMM take five dc voltage readings, displays the five readings in an “array”, then converts the five ASCII readings to numerical notation so that the “Average” icon can find the magnitude of the average of these five numbers. Finally the five numbers are stored in a file that can be exported to a floppy disk “a” or to your hard disk “c”. The program uses an iteration loop that operates 5 times; only one data measurement is made in each iteration loop:

“Block Diagram”

Driver Manual.doc1Version, Feb. 2002

“Front Panel”

17.Repeat all the steps on pages 1 through 4 that include steps 9) through step 16). But make one change in step 14). Instead of making five (5) readings, we want only one (1) reading; change the SCPI to this command: TRIG:COUN 1

18.We will now use a "For Loop" Icon that executes a sub-diagram, a set number of iteration times, given by N, which we must define. In our case we will make five iterations, and hence we set N = 5. The "For Loop" Icon is located in the Function  Structures palette. On the left hand border or frame of the "For Loop" Icon, we must add a "Control" data input window to fix the number of iterations we want. Using the right hand mouse button, proceed to "Create" and then to "Control " to create this window on the Front Panel. On the “Front Panel”, set the number of iterations to 5 in the "little Numeric Window". Connect a "string wire" from the “VISA R” Icon to the output terminal of the right hand side of the border of the "For Loop" frame. Run the program to confirm that the DMM takes five voltage readings.

19.Outside the "For Loop" frame, attach an "Indicator" reading device to the output terminal of the "For Loop" This indicator automatically becomes a one-dimensional array that reads the five readings in ASCII code! Run the program and observe the five readings in the "Array" window of the “Front Panel”. These numbers are in ASCII representation and include an integer, a decimal point, a fractional contribution and finally a "power of ten's" contribution. In order to use the "Average" Icon and to export data from a file to the outside world, we have to convert the ASCII representation to numeric representation. This job is done using the famous (but almost impossible to find) icon named "Fract/Exp String to Number" Icon. To find this icon, first go to the “String” Palette. Find the second icon on the right hand side. It should be labelled by the name "String/Number Conversion". Click on it. A new dialog box opens up. Look for the fourth (4th) icon on the second row of this dialog box. It should be labelled with the name "Fract/Exp String to Number".

Drag this icon onto the Block Diagram. Wee, what hard work!

20.Use the "Wiring spool" tool to connect up a wire between the "String" terminal of this “Fract/Exp String to Number” Icon and the output terminal of the "For Loop" frame.

21.Now we must find the icon that does the "averaging", namely the "Mean" Icon. It too is hidden incredibly well and is almost impossible to find! First go to the Functions Palette again and locate the “Mathematics” icon. You can identify this “Mathematics” icon by the “summation symbol ”, by the “integral symbol §” and by a Gaussian curve that appears inside it! Click on the “Mathematic” icon to open up a new “Mathematics” dialog box that includes many icons. Choose the icon located on the second row of the left hand side. It should have the name "Probability and Statistics." This will still open up a second new dialog box that contains three rows of different icons. The first icon on your top left hand side is the famous “Average or MEAN” Icon. Drag this "MEAN" icon

onto the “Block Diagram”. Using the Wiring tool, connect its input terminal, labelled by the name "x" to the output terminal of the "Fract/Exp String to Number" icon, labelled by the name "number". To the output of the "MEAN" Icon, connect up an "Indicator" to the terminal with the name “mean” in order to be able to read the average value from the “Front Panel”.

22.And finally, lets save our five readings on the floppy disk or hard disk. Perhaps we wish to export the results to Excel or the MathLab or some other useful software data analysis program. To do this, we will use the icon designed just for this job, the "Write to Spreadsheet File.vi" Icon. To find this icon, return to the “Functions Palette” and go to the icon located on the right hand side on the third row. This icon is labelled by the name "File I/0" and has a picture of a floppy disk on it. Click on it. Now a dialog box opens up with the title "File I/0”. The very first icon that appears on the left top row is your "Write to Spreadsheet File.vi" Icon. Drag it onto the “Block Diagram” and connect it up to the output terminal of the "Fract/Exp String to Number" Icon. Your “Block Diagram” and “Front Panel” should look like the figures on pages 5 and 6.

23.Run the program. The DMM should take five readings - it will take some time, maybe one minute for the program to run. At completion, a new window will open up asking you for a "file name" and where you wish to store the data - in a floppy disk or a hard disk c or on the scratch pad.

24.Note the value of the "average" of the five readings. If you don't like the accuracy of two numbers after the decimal point, you can display more numbers of this fractional part by this clever procedure (discovered by Avraham). Go to the “Front Panel” and place the Pointer tool on top of the "little mean" window. Now click with the right mouse button to open up a surprisingly cute dialog box. Find the button with the name "Format and Precision" and click on it. A new dialog box will open up with the title "Format and Precision". In this dialog box, you choose the "Digit of Precision" you wish for the mean value of the five readings.

This is the basic and hardest part of extracting data from an instrument. Now it is your challenge to explore and learn more about the functions and features of LabVIEW. It won't be an easy task - you'll need lots and lots of time and patience. But with persistence, you will succeed! Also refer to several new books in the library on LabVIEW.

Good luck.

Ralph and Rachel Rosenbaum and Avraham Semenkee

Reference book: Learning with LabVIEW 6i by Robert H. Bishop, Prentice Hall,

ISBN number: 0-13-032559-7 .

(On reserve in the Physics Section of the Science Library)

Driver Manual.doc1Version, Feb. 2002