cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 6283|回复: 6

GPIB編程資料

[复制链接]
发表于 2004-12-22 23:44:17 | 显示全部楼层 |阅读模式
<>http://students.washington.edu/gwl/phys434/gpib.html</P>
<>上面的網頁有些GPIB編程的資料不過NI的列子是最簡單明瞭的:</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         */
   char  Buffer[101];             /* 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[ibcntl] = '\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>
发表于 2004-12-22 23:50:39 | 显示全部楼层
哇,好贴,支持,支持!再支持,兄弟,继续努力,谢谢你哈![em08][em08][em17][em17][em31][em31]
 楼主| 发表于 2004-12-22 23:58:17 | 显示全部楼层

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

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2004-12-23 00:01:20 | 显示全部楼层
<>大家一起學習啦,關鍵是把這裡的氣氛要搞起來.</P>
发表于 2007-3-13 11:15:56 | 显示全部楼层
我有个QB的程序,不知道现在还有人懂吗? 总之我是没有明白-_-!
发表于 2008-10-21 14:18:14 | 显示全部楼层
为什么有的附件下不了呢??
发表于 2009-2-10 16:54:38 | 显示全部楼层
仪器控制领域,GPIB用的还是很多的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2024-5-18 16:46 , Processed in 0.548389 second(s), 9 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表