簡體   English   中英

如何僅使用ansi-c在Windows計算機上連接GPIB設備

[英]How to interface a GPIB device on a windows machine using only ansi-c

如何僅使用ANSI-C和可能的Windows標頭打開和關閉與GPIB設備的連接。

有沒有執行此操作的默認方法,或者gpib本質上涉及第三方驅動程序?

僅使用Windows標頭和ANSI C ...不太可能。 正如阿德里亞諾指出的。

最簡單的方法是使用VISA庫 它們是(幾乎)不同制造商之間的GPIB的標准化接口...使用此庫,您的代碼和生成的可執行文件將不在乎您使用的是誰的VISA實現(示例警告鏈接到下面)...

您將需要針對visa32.lib進行鏈接。 可以在目錄$(VXIPNPPATH)/WinNT/lib/msc 認為變量VXIPNPPATH是默認設置,指向C:\\Program Files (x86)\\IVI Foundation\\VISA\\或32位計算機上的等效文件。

然后,可以在$(VXIPNPPATH)/WinNT/include找到C VISA庫的頭文件。

請注意,根據您安裝了跨制造商使用GPIB的VISA庫,您可能需要進行一些配置。 例如,當使用NI的庫成功連接到安捷倫設備時,必須啟用本文所述的選項

我知道NI可以提供一些示例程序。 打開和關閉設備的一般示例可能類似於...

ViStatus status;
ViChar buffer[80];
unsigned int board = 0, device = 10;

/* Open the default resource manage */
status = viOpenDefaultRM(&mVisaDefaultRM);
if (status < VI_SUCCESS)
    exit(-1);

/* Construct a string describing the GPIB device to open and open it! */
sprintf(buffer, "GPIB%u::%u::INSTR", board, device);    
status = viOpen(mVisaDefaultRM, buffer, VI_NULL, VI_NULL, &mVisaInst);
if (status < VI_SUCCESS)
{
    viClose(mVisaDefaultRM);
    exit(-1);
}

/* Close it */
viClose(mVisaInst);
viClose(mVisaDefaultRM);

然后,您可以使用其余的API進行各種操作……例如,要重置設備,您可以編寫類似以下內容……

/* Reset the device */
status = viEnableEvent(mVisaInst, VI_EVENT_SERVICE_REQ, VI_QUEUE, VI_NULL);
if( status >= VI_SUCCESS )
{
    /* Send SDC (Selected Device Clear) to reset the information interchange 
     * between controller and instrument. 
     * Cleans input and output buffer, aborts operations that prevent 
     * processing of new commands etc. */   
    status = viClear(mVisaInst); 
    if (status >= VI_SUCCESS)
    {
        /* If the SDC successed progress onto reset the device and set it 
         * up for detecting SRQ events... */
        Write("*CLS;");     /* Clear status command. Clears the whole status structure */
        Write("*RST;");     /* Reset command. Abort all activities and initialise the device (instrument specific) */
        Write("*SRE 255;"); /* Service request enable. Disable all service requests except ESB: 0010_0000 */
        Write("*ESE 255;"); /* Standard event status enable. Disable all statuses except the errors and op complete: 0011_1101 */                   
    }
}

if (status < VI_SUCCESS)
{
    /* Do something */
}

可以在此處找到National Instruments VISA API文檔的示例。 我確信安捷倫和其他人也必須有他們的版本。 他們的關鍵是您編碼並且生成的EXE不必關心正在使用誰的實現...

最后的小鏈接...我發現此GPIB編程教程非常有用...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM