en-lulu 发表于 2004-12-22 23:44:17

GPIB編程資料

<P>http://students.washington.edu/gwl/phys434/gpib.html</P>
<P>上面的網頁有些GPIB編程的資料不過NI的列子是最簡單明瞭的:</P>
<P>*****************************************************************************
* Refer to the language interface documentation for details on
* which header and .obj files to include in your project.
*****************************************************************************/
#include &lt;windows.h&gt;
#include "decl-32.h"
#include &lt;stdio.h&gt;</P>
<P>void GpibError(char *msg);      /* Error function declaration            */</P>
<P>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         */
   charBuffer;             /* Read buffer                           */</P>
<P>/*****************************************************************************
* Initialization - Done only once at the beginning of your application.
*****************************************************************************/</P>
<P>   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 &amp; ERR) {             /* Check for GPIB Error                  */
      GpibError("ibdev Error");
   }</P>
<P>   ibclr(Device);               /* Clear the device                        */
   if (ibsta &amp; ERR) {
      GpibError("ibclr Error");
   }</P>
<P>/*****************************************************************************
* Main Application Body - Write the majority of your GPIB code here.
*****************************************************************************/</P>
<P>   ibwrt(Device, "*IDN?", 5);   /* Send the identification query command   */
   if (ibsta &amp; ERR) {
      GpibError("ibwrt Error");
   }</P>
<P>   ibrd(Device, Buffer, 100);   /* Read up to 100 bytes from the device    */
   if (ibsta &amp; ERR) {
      GpibError("ibrd Error");
   }</P>
<P>   Buffer = '\0';         /* Null terminate the ASCII string         */</P>
<P>   printf("%s\n", Buffer);      /* Print the device identification         */


/*****************************************************************************
* Uninitialization - Done only once at the end of your application.
*****************************************************************************/</P>
<P>   ibonl(Device, 0);            /* Take the device offline               */
   if (ibsta &amp; ERR) {
      GpibError("ibonl Error");
   }</P>
<P>   ibonl(BoardIndex, 0);          /* Take the interface offline            */
   if (ibsta &amp; ERR) {
      GpibError("ibonl Error");
   }
}</P>
<P>
/*****************************************************************************
*                      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) {</P>
<P>    printf ("%s\n", msg);</P>
<P>    printf ("ibsta = &amp;H%x&lt;", ibsta);
    if (ibsta &amp; ERR )printf (" ERR");
    if (ibsta &amp; TIMO)printf (" TIMO");
    if (ibsta &amp; END )printf (" END");
    if (ibsta &amp; SRQI)printf (" SRQI");
    if (ibsta &amp; RQS )printf (" RQS");
    if (ibsta &amp; CMPL)printf (" CMPL");
    if (ibsta &amp; LOK )printf (" LOK");
    if (ibsta &amp; REM )printf (" REM");
    if (ibsta &amp; CIC )printf (" CIC");
    if (ibsta &amp; ATN )printf (" ATN");
    if (ibsta &amp; TACS)printf (" TACS");
    if (ibsta &amp; LACS)printf (" LACS");
    if (ibsta &amp; DTAS)printf (" DTAS");
    if (ibsta &amp; DCAS)printf (" DCAS");
    printf (" &gt;\n");</P>
<P>    printf ("iberr = %d", iberr);
    if (iberr == EDVR) printf (" EDVR &lt;DOS Error&gt;\n");
    if (iberr == ECIC) printf (" ECIC &lt;Not Controller-In-Charge&gt;\n");
    if (iberr == ENOL) printf (" ENOL &lt;No Listener&gt;\n");
    if (iberr == EADR) printf (" EADR &lt;Address error&gt;\n");
    if (iberr == EARG) printf (" EARG &lt;Invalid argument&gt;\n");
    if (iberr == ESAC) printf (" ESAC &lt;Not System Controller&gt;\n");
    if (iberr == EABO) printf (" EABO &lt;Operation aborted&gt;\n");
    if (iberr == ENEB) printf (" ENEB &lt;No GPIB board&gt;\n");
    if (iberr == EOIP) printf (" EOIP &lt;Async I/O in progress&gt;\n");
    if (iberr == ECAP) printf (" ECAP &lt;No capability&gt;\n");
    if (iberr == EFSO) printf (" EFSO &lt;File system error&gt;\n");
    if (iberr == EBUS) printf (" EBUS &lt;Command error&gt;\n");
    if (iberr == ESTB) printf (" ESTB &lt;Status byte lost&gt;\n");
    if (iberr == ESRQ) printf (" ESRQ &lt;SRQ stuck on&gt;\n");
    if (iberr == ETAB) printf (" ETAB &lt;Table Overflow&gt;\n");</P>
<P>    printf ("ibcntl = %ld\n", ibcntl);
    printf ("\n");</P>
<P>    /* Call ibonl to take the device and interface offline */
    ibonl (Device,0);
    ibonl (BoardIndex,0);</P>
<P>    exit(1);
}</P>

cpubbs 发表于 2004-12-22 23:50:39

哇,好贴,支持,支持!再支持,兄弟,继续努力,谢谢你哈!

en-lulu 发表于 2004-12-22 23:58:17

一個VC進行GPIB儀器控制的實例

<P>今天剛做的,很簡單所操作的儀器為 Agilent 11713A 指令只有兩種 A , B.涉及儀器控制的全在 ChangeState()中.</P>
<P>執行檔有2M多,嚇死人了,我去掉了執行檔把源文件傳上來.</P>
<P>最逕在學VC希望可以以後可以有高人指點啊!</P>

en-lulu 发表于 2004-12-23 00:01:20

<P>大家一起學習啦,關鍵是把這裡的氣氛要搞起來.</P>

acqua_23 发表于 2007-3-13 11:15:56

我有个QB的程序,不知道现在还有人懂吗? 总之我是没有明白-_-!

wangtun 发表于 2008-10-21 14:18:14

为什么有的附件下不了呢??

fjczd 发表于 2009-2-10 16:54:38

仪器控制领域,GPIB用的还是很多的
页: [1]
查看完整版本: GPIB編程資料