GPIB编程的资料不过NI的列子是最简单明了的:
********************************************************************* Refer to the language interface documentation for details on * which header and .obj files to include in your project.
********************************************************************/ #include
void GpibError(char *msg); /* Error function declaration */ int Device = 0; /* Device unit descriptor */
int BoardIndex = 0; /* Interface Index (GPIB0=0,GPIB1=1,etc.) */ void main() {
int PrimaryAddress = 2; /* Primary address of the device */ int SecondaryAddress = 0; /* Secondary address of the device */ char Buffer[101]; /* Read buffer */
/******************************************************************* Initialization - Done only once at the beginning of your application.
*******************************************************************/
Device = ibdev( /* Create a unit descriptor handle */ BoardIndex, /* Board Index (GPIB0 = 0, GPIB1 = 1, ...) */ PrimaryAddress, / * Device primary address */ SecondaryAddress, /* Device secondary address */
T10s, /* Timeout setting (T10s = 10 seconds) */ 1, /* Assert EOI line at end of write */ 0); /* EOS termination mode */ if (ibsta & ERR) {
/* Check for GPIB Error */ GpibError(\ }
ibclr(Device); /* Clear the device */ if (ibsta & ERR) {
GpibError(\ }
/******************************************************************** Main Application Body - Write the majority of your GPIB code here.
********************************************************************/
ibwrt(Device, \ /* Send the identification query command */ if (ibsta & ERR) {
GpibError(\ }
ibrd(Device, Buffer, 100); /* Read up to 100 bytes from the device */ if (ibsta & ERR) {
GpibError(\ }
Buffer[ibcntl] = '\\0'; /* Null terminate the ASCII string */
printf(\ /* Print the device identification */
/*********************************************************** * Uninitialization - Done only once at the end of your application.
***************************************************************/ ibonl(Device, 0); /* Take the device offline */ if (ibsta & ERR) {
GpibError(\ }
ibonl(BoardIndex, 0); /* Take the interface offline */ if (ibsta & ERR)
{
GpibError(\ } }
/***************************************************************** * Function GPIBERROR * This function will notify you that a NI-488 function failed by * printing an error message. The status variable IBSTA will also be * printed in hexadecimal along with the mnemonic meaning of the bit * position. The status
variable IBERR will be printed in decimal * along with the mnemonic meaning of the decimal value. The status * variable IBCNTL will be printed in decimal. * * The NI-488 function IBONL is called to disable the hardware and * software. * * The EXIT function will terminate this program.
******************************************************************/ void GpibError(char *msg) {
printf (\
printf (\ if (ibsta & ERR ) printf (\ if (ibsta & TIMO) printf (\ if (ibsta & END ) printf (\ if (ibsta & SRQI) printf (\ if (ibsta & RQS ) printf (\ if (ibsta & CMPL) printf (\ if (ibsta & LOK ) printf (\ if (ibsta & REM ) printf (\ if (ibsta & CIC ) printf (\ if (ibsta & ATN ) printf (\
if (ibsta & TACS) printf (\ if (ibsta & LACS) printf (\ if (ibsta & DTAS) printf (\ if (ibsta & DCAS) printf (\ printf (\
printf (\ if (iberr == EDVR)
printf (\ if (iberr == ECIC)
printf (\ if (iberr == ENOL)
printf (\ if (iberr == EADR)
printf (\ if (iberr == EARG)
printf (\ if (iberr == ESAC)
printf (\ if (iberr == EABO)
printf (\ if (iberr == ENEB)
printf (\ if (iberr == EOIP)
printf (\ if (iberr == ECAP)
printf (\ if (iberr == EFSO)
printf (\ if (iberr == EBUS)
printf (\
if (iberr == ESTB)
printf (\ if (iberr == ESRQ)
printf (\ if (iberr == ETAB)
printf (\printf (\ printf (\
/* Call ibonl to take the device and interface offline */ ibonl (Device,0); ibonl (BoardIndex,0); exit(1); }