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 <windows.h>
#include "decl-32.h"
#include <stdio.h></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 & ERR) { /* Check for GPIB Error */
GpibError("ibdev Error");
}</P>
<P> ibclr(Device); /* Clear the device */
if (ibsta & 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 & ERR) {
GpibError("ibwrt Error");
}</P>
<P> ibrd(Device, Buffer, 100); /* Read up to 100 bytes from the device */
if (ibsta & 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 & ERR) {
GpibError("ibonl Error");
}</P>
<P> ibonl(BoardIndex, 0); /* Take the interface offline */
if (ibsta & 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 = &H%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");</P>
<P> printf ("iberr = %d", iberr);
if (iberr == EDVR) printf (" EDVR <DOS 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 <Command 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");</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> 哇,好贴,支持,支持!再支持,兄弟,继续努力,谢谢你哈!
一個VC進行GPIB儀器控制的實例
<P>今天剛做的,很簡單所操作的儀器為 Agilent 11713A 指令只有兩種 A , B.涉及儀器控制的全在 ChangeState()中.</P><P>執行檔有2M多,嚇死人了,我去掉了執行檔把源文件傳上來.</P>
<P>最逕在學VC希望可以以後可以有高人指點啊!</P>
<P>大家一起學習啦,關鍵是把這裡的氣氛要搞起來.</P> 我有个QB的程序,不知道现在还有人懂吗? 总之我是没有明白-_-! 为什么有的附件下不了呢?? 仪器控制领域,GPIB用的还是很多的
页:
[1]