Register-Based Programming 49
Appendix B
Register Programming Example
This example program reads the ID and Device Type registers and then
reads the Status register. Next, the program closes a signal path from
channel CH031 to COM 05, writes the value 20480 (5000 hexadecimal) to
register 20
h
and then writes the value 38 (26 hexadecimal) to register 28
h
.
Then, the program resets the module to open all channels. A typical printout
for the program is:
ID register = 0xFFFF
Device Type register = 0x 218
Status register = 0xFFBE
Left-hand Assembly Register 20h = 0x5000
Left-hand Assembly Register 22h = 0x 0
Right-hand Assembly Register 24h = 0x 0
Right-hand Assembly Register 26h = 0x 0
Register 28h for Both Assemblies = 0x 26
#include <visa.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
ViSession defaultRM,rf_mux;
void err_handler();
void wait();
void main(void)
{
unsigned short reg_20h, reg_22h;
/* Registers for Left-hand assembly*/
unsigned short reg_24h, reg_26h;
/* Registers for Right-hand assy*/
unsigned short reg_28h;
/* Register for both assemblies */
unsigned short id_reg, dt_reg;
/* ID and device type registers */
unsigned short stat_reg;
/* status register */
/* create and open a device session */
ViStatus err;
viOpenDefaultRM (&defaultRM);
viOpen (defaultRM,"GPIB-VXI0::9::120",VI_NULL,VI_NULL,&rf_mux);
/* reset the module */
err = viOut16(rf_mux,VI_A16_SPACE,0x04,1);
if(err < VI_SUCCESS)err_handler(rf_mux,err);
/* wait 1 second (must wait at least 100 usec before writing a "0") */
wait(1);
err = viOut16(rf_mux,VI_A16_SPACE,0x04,0);
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com