Commits

Richard Li committed 3dbccdd

first commit to Dropbox.

Comments (0)

Files changed (5)

+#GPIB_NI488_MAC_Cmdline
+NI-488.2 for Mac OS X
+Copyright National Instruments Corporation.
+All Rights Reserved.
+
+The C sample program illustrates how to use the NI-488.2 function
+calls to communicate with your instrument.
+
+Open up a Terminal window and navigate to the Sample directory 
+located at: Applications>>National Instruments>>NI-488.2>>Sample
+
+This sample application was written to query a device (PAD 2) for its ID.
+
+In the Terminal, type in:
+
+gcc Sample.c -m32 -framework NI488 -o samapp
+
+To compile the sample code.
+
+In the Terminal, type in:
+
+./samapp
+
+To run the compiled sample code.
+/*****************************************************************************
+ *
+ * This sample application was written to query a device (PAD 2) for its ID.
+ *
+ * Compiling and linking the sample application from command line:
+ *        gcc Sample.c -m32 -framework NI488 -o samapp
+ *
+ *****************************************************************************/
+
+#ifdef __MACH__
+#include <NI488/ni488.h>
+#else
+#include "ni488.h"
+#endif
+#include <stdio.h>
+
+void GpibError(char *msg);        /* Error function declaration              */
+
+int Device = 0;                   /* Device unit descriptor                  */
+int BoardIndex = 0;               /* Interface Index (GPIB0=0,GPIB1=1,etc.)  */
+	
+int main() {
+   int   PrimaryAddress = 22;      /* 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("ibdev Error"); 
+   }
+
+   ibclr(Device);                 /* Clear the device                        */
+   if (ibsta & ERR) {
+      GpibError("ibclr Error");
+   }
+
+/*****************************************************************************
+ * Main Application Body - Write the majority of your GPIB code here.
+ *****************************************************************************/
+
+   ibwrt(Device, "MEASure:CURRent:DC?", 19);     /* Send the identification query command   */
+   if (ibsta & ERR) {
+      GpibError("ibwrt Error");
+   }
+
+   ibrd(Device, Buffer, 100);     /* Read up to 100 bytes from the device    */
+   if (ibsta & ERR) {
+      GpibError("ibrd Error");	
+   }
+
+   Buffer[ibcntl] = '\0';         /* Null terminate the ASCII string         */
+
+   printf("%s\n", Buffer);        /* 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 Error");	
+   }
+
+   ibonl(BoardIndex, 0);          /* Take the interface offline              */
+   if (ibsta & ERR) {
+      GpibError("ibonl Error");	
+   }
+   
+   return 0;
+}
+
+
+/*****************************************************************************
+ *                      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 ("%s\n", msg);
+
+    printf ("ibsta = 0x%x  <", ibsta);
+    if (ibsta & ERR )  printf (" ERR");
+    if (ibsta & TIMO)  printf (" TIMO");
+    if (ibsta & END )  printf (" END");
+    if (ibsta & SRQI)  printf (" SRQI");
+    if (ibsta & RQS )  printf (" RQS");
+    if (ibsta & CMPL)  printf (" CMPL");
+    if (ibsta & LOK )  printf (" LOK");
+    if (ibsta & REM )  printf (" REM");
+    if (ibsta & CIC )  printf (" CIC");
+    if (ibsta & ATN )  printf (" ATN");
+    if (ibsta & TACS)  printf (" TACS");
+    if (ibsta & LACS)  printf (" LACS");
+    if (ibsta & DTAS)  printf (" DTAS");
+    if (ibsta & DCAS)  printf (" DCAS");
+    printf (" >\n");
+
+    printf ("iberr = %d", iberr);
+    if (iberr == EDVR) printf (" EDVR <System Error>\n");
+    if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n");
+    if (iberr == ENOL) printf (" ENOL <No Listener>\n");
+    if (iberr == EADR) printf (" EADR <Address error>\n");
+    if (iberr == EARG) printf (" EARG <Invalid argument>\n");
+    if (iberr == ESAC) printf (" ESAC <Not System Controller>\n");
+    if (iberr == EABO) printf (" EABO <Operation aborted>\n");
+    if (iberr == ENEB) printf (" ENEB <No GPIB board>\n");
+    if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n");
+    if (iberr == ECAP) printf (" ECAP <No capability>\n");
+    if (iberr == EFSO) printf (" EFSO <File system error>\n");
+    if (iberr == EBUS) printf (" EBUS <GPIB bus error>\n");
+    if (iberr == ESTB) printf (" ESTB <Status byte lost>\n");
+    if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n");
+    if (iberr == ETAB) printf (" ETAB <Table Overflow>\n");
+
+    printf ("\n");
+    printf ("ibcntl = %ld\n", ibcntl);
+    printf ("\n");
+
+    /* Call ibonl to take the device and interface offline */
+    ibonl (Device,0);
+    ibonl (BoardIndex,0);    
+}
+/*****************************************************************************
+ *
+ * This sample application was written to query a device (PAD 2) for its ID.
+ *
+ * Compiling and linking the sample application from command line:
+ *        gcc Sample.c -m32 -framework NI488 -o samapp
+ *
+ *****************************************************************************/
+
+#ifdef __MACH__
+#include <NI488/ni488.h>
+#else
+#include "ni488.h"
+#endif
+#include <stdio.h>
+
+void GpibError(char *msg);        /* Error function declaration              */
+
+int Device = 0;                   /* Device unit descriptor                  */
+int BoardIndex = 0;               /* Interface Index (GPIB0=0,GPIB1=1,etc.)  */
+	
+int main() {
+   int   PrimaryAddress = 22;      /* 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("ibdev Error"); 
+   }
+
+   ibclr(Device);                 /* Clear the device                        */
+   if (ibsta & ERR) {
+      GpibError("ibclr Error");
+   }
+
+/*****************************************************************************
+ * Main Application Body - Write the majority of your GPIB code here.
+ *****************************************************************************/
+
+   ibwrt(Device, "MEASure:RESistance?", 19);     /* Send the identification query command   */
+   if (ibsta & ERR) {
+      GpibError("ibwrt Error");
+   }
+
+   ibrd(Device, Buffer, 100);     /* Read up to 100 bytes from the device    */
+   if (ibsta & ERR) {
+      GpibError("ibrd Error");	
+   }
+
+   Buffer[ibcntl] = '\0';         /* Null terminate the ASCII string         */
+
+   printf("%s\n", Buffer);        /* 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 Error");	
+   }
+
+   ibonl(BoardIndex, 0);          /* Take the interface offline              */
+   if (ibsta & ERR) {
+      GpibError("ibonl Error");	
+   }
+   
+   return 0;
+}
+
+
+/*****************************************************************************
+ *                      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 ("%s\n", msg);
+
+    printf ("ibsta = 0x%x  <", ibsta);
+    if (ibsta & ERR )  printf (" ERR");
+    if (ibsta & TIMO)  printf (" TIMO");
+    if (ibsta & END )  printf (" END");
+    if (ibsta & SRQI)  printf (" SRQI");
+    if (ibsta & RQS )  printf (" RQS");
+    if (ibsta & CMPL)  printf (" CMPL");
+    if (ibsta & LOK )  printf (" LOK");
+    if (ibsta & REM )  printf (" REM");
+    if (ibsta & CIC )  printf (" CIC");
+    if (ibsta & ATN )  printf (" ATN");
+    if (ibsta & TACS)  printf (" TACS");
+    if (ibsta & LACS)  printf (" LACS");
+    if (ibsta & DTAS)  printf (" DTAS");
+    if (ibsta & DCAS)  printf (" DCAS");
+    printf (" >\n");
+
+    printf ("iberr = %d", iberr);
+    if (iberr == EDVR) printf (" EDVR <System Error>\n");
+    if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n");
+    if (iberr == ENOL) printf (" ENOL <No Listener>\n");
+    if (iberr == EADR) printf (" EADR <Address error>\n");
+    if (iberr == EARG) printf (" EARG <Invalid argument>\n");
+    if (iberr == ESAC) printf (" ESAC <Not System Controller>\n");
+    if (iberr == EABO) printf (" EABO <Operation aborted>\n");
+    if (iberr == ENEB) printf (" ENEB <No GPIB board>\n");
+    if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n");
+    if (iberr == ECAP) printf (" ECAP <No capability>\n");
+    if (iberr == EFSO) printf (" EFSO <File system error>\n");
+    if (iberr == EBUS) printf (" EBUS <GPIB bus error>\n");
+    if (iberr == ESTB) printf (" ESTB <Status byte lost>\n");
+    if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n");
+    if (iberr == ETAB) printf (" ETAB <Table Overflow>\n");
+
+    printf ("\n");
+    printf ("ibcntl = %ld\n", ibcntl);
+    printf ("\n");
+
+    /* Call ibonl to take the device and interface offline */
+    ibonl (Device,0);
+    ibonl (BoardIndex,0);    
+}
+/*****************************************************************************
+ *
+ * This sample application was written to query a device (PAD 2) for its ID.
+ *
+ * Compiling and linking the sample application from command line:
+ *        gcc Sample.c -m32 -framework NI488 -o samapp
+ *
+ *****************************************************************************/
+
+#ifdef __MACH__
+#include <NI488/ni488.h>
+#else
+#include "ni488.h"
+#endif
+#include <stdio.h>
+
+void GpibError(char *msg);        /* Error function declaration              */
+
+int Device = 0;                   /* Device unit descriptor                  */
+int BoardIndex = 0;               /* Interface Index (GPIB0=0,GPIB1=1,etc.)  */
+	
+int main() {
+   int   PrimaryAddress = 22;      /* 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("ibdev Error"); 
+   }
+
+   ibclr(Device);                 /* Clear the device                        */
+   if (ibsta & ERR) {
+      GpibError("ibclr Error");
+   }
+
+/*****************************************************************************
+ * Main Application Body - Write the majority of your GPIB code here.
+ *****************************************************************************/
+
+   ibwrt(Device, "MEASure:VOLTage:DC?", 19);     /* Send the identification query command   */
+   if (ibsta & ERR) {
+      GpibError("ibwrt Error");
+   }
+
+   ibrd(Device, Buffer, 100);     /* Read up to 100 bytes from the device    */
+   if (ibsta & ERR) {
+      GpibError("ibrd Error");	
+   }
+
+   Buffer[ibcntl] = '\0';         /* Null terminate the ASCII string         */
+
+   printf("%s\n", Buffer);        /* 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 Error");	
+   }
+
+   ibonl(BoardIndex, 0);          /* Take the interface offline              */
+   if (ibsta & ERR) {
+      GpibError("ibonl Error");	
+   }
+   
+   return 0;
+}
+
+
+/*****************************************************************************
+ *                      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 ("%s\n", msg);
+
+    printf ("ibsta = 0x%x  <", ibsta);
+    if (ibsta & ERR )  printf (" ERR");
+    if (ibsta & TIMO)  printf (" TIMO");
+    if (ibsta & END )  printf (" END");
+    if (ibsta & SRQI)  printf (" SRQI");
+    if (ibsta & RQS )  printf (" RQS");
+    if (ibsta & CMPL)  printf (" CMPL");
+    if (ibsta & LOK )  printf (" LOK");
+    if (ibsta & REM )  printf (" REM");
+    if (ibsta & CIC )  printf (" CIC");
+    if (ibsta & ATN )  printf (" ATN");
+    if (ibsta & TACS)  printf (" TACS");
+    if (ibsta & LACS)  printf (" LACS");
+    if (ibsta & DTAS)  printf (" DTAS");
+    if (ibsta & DCAS)  printf (" DCAS");
+    printf (" >\n");
+
+    printf ("iberr = %d", iberr);
+    if (iberr == EDVR) printf (" EDVR <System Error>\n");
+    if (iberr == ECIC) printf (" ECIC <Not Controller-In-Charge>\n");
+    if (iberr == ENOL) printf (" ENOL <No Listener>\n");
+    if (iberr == EADR) printf (" EADR <Address error>\n");
+    if (iberr == EARG) printf (" EARG <Invalid argument>\n");
+    if (iberr == ESAC) printf (" ESAC <Not System Controller>\n");
+    if (iberr == EABO) printf (" EABO <Operation aborted>\n");
+    if (iberr == ENEB) printf (" ENEB <No GPIB board>\n");
+    if (iberr == EOIP) printf (" EOIP <Async I/O in progress>\n");
+    if (iberr == ECAP) printf (" ECAP <No capability>\n");
+    if (iberr == EFSO) printf (" EFSO <File system error>\n");
+    if (iberr == EBUS) printf (" EBUS <GPIB bus error>\n");
+    if (iberr == ESTB) printf (" ESTB <Status byte lost>\n");
+    if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n");
+    if (iberr == ETAB) printf (" ETAB <Table Overflow>\n");
+
+    printf ("\n");
+    printf ("ibcntl = %ld\n", ibcntl);
+    printf ("\n");
+
+    /* Call ibonl to take the device and interface offline */
+    ibonl (Device,0);
+    ibonl (BoardIndex,0);    
+}