透過GPIB介面進行電腦-電腦的通訊



主要軟體: Driver Software>>NI-488.2
主要軟體版本: N/A
主要軟體修正版本: N/A
次要軟體:

問題: 如何透過GPIB介面進行電腦-電腦的通訊?

解答: 下面是關於透過GPIB介面進行電腦-電腦的通訊的設定順序,基本的程序如下:

 

  1. 將所有GPIB相關的設定回歸原始狀態。(我們將會編輯所有內容)
  2. 先確定哪一台電腦為Controller 而另外一台電腦為Non-Controller。(你尚不需改變任何設定)
  3. 接下來使用 Interactive Control ( IBIC ) 來測試下面的命令。 成功之後即可在程式中來進行下指令的動作。 在Non-Controller的電腦上進行下面的動作:

     

    1. 輸入指令 ibfind GPIB0 與 GPIB 卡片進行連線。
    2. 輸入指令 ibrsc 0 解除系統控制權( i.e.  設定此卡片為non-controller )。
    3. 輸入指令 ibpad 1 改變 Non-Controller 的 primary GPIB address 由 0 變成 1。
    4. 檢查ATN狀態是否改變,電腦變成listener的狀態。( LACS 的 Status Word 為 High ) -- 你可以建立一個迴圈來不間斷的確認。
    5. 接收由 Controller 發出的指令, 使用 ibrd # 命令, # 代表接收的位元長度。

您可以把步驟 d 放在迴圈中,直到 Non-Controller 被指定為listener為止。 ( i.e. Controller 送出一筆資料) , 接著重複步驟 e 去接受這筆資料。 您可以使用相同的方式在writes上。 但不是要等待被通知去接收訊息( listen ),而是要等待被通知要發送訊息( talk ) ( TACS 的 Status Word 為 High )

 

以下是用C程式語言所撰寫上面步驟的程式碼:

static int noncontroller;
static char buffer[100];
static int panelHandle;

int main ()
{
// Open a session to the GPIB board
noncontroller = ibfind ("gpib0");

// Release system control
ibrsc (noncontroller, 0);

// Change primary address from 0 to 1
ibpad (noncontroller, 1);

while (1)
{
// Update Status variable
ibwait (noncontroller, 0);

// Wait until non-controller is listener and ATN line is dropped.
if ((ibsta&LACS)&&(!(ibsta&ATN)))
{
ibrd (noncontroller, buffer, 100); // Read data bytes
buffer[ibcnt] = '\n'; // Add linefeed and 0 to string.
buffer[ibcnt + 1] = 0;
printf ("%s",buffer); print buffer
return 0;
} // first if

// If addressed to talk, send the response "I am a talker"
if ((ibsta&TACS)&&(!(ibsta&ATN)))
{
// Send data across the bus.
ibwrt (noncontroller, "I am a talker", strlen("I am a talker"));
return 0;
} // second if
} // while
} // main

 

註記: 在執行此程式碼之前,請先確定下列事項已完成:

  1. 包含 windows.h 標頭檔。

  2. 包含 ni488.h 標頭檔。
  3. 將你的應用程式和適合的語言介面檔案做連結。

    1. 對於 Microsoft C/C++, 連結 gpib-32.obj。

    2. 對於 Borland C/C++,連結 borlandc_gpib-32.obj。

在controller這一端,必須要注意的是使否與non-controller這一端建立了通訊(如上例是primary address 1,例如:

 

  1. 使用 ibfind GPIB0 連接 GPIB 卡片的通訊。
  2. 使用 ibsic 指令清除bus上的指令。
  3. 使用 ibsre 1 指令允許設定的儀器接受遠端控制。
  4. 使用 ibdev 0 1 0 13 1 0 指令打開與 Non-Controller 的通訊。
  5. 使用 ibwrt "HELLO"  送出一個字串資料( 在此例為HELLO ) 給 Non-Controller

建議您要允許 readdressing 以確保 Non-Controller 可以每一次都被設定為 listen 。否則您會接收到一個 ENOL error (沒有 listener 被找到的錯誤)。要允許 readressing ,可以使用 ibconfig ibcreaddr 1 指令。(對 controller 您只需進行上面這些動作) 若你想要修改上面的程式放在迴圈內執行,這個動作就是必須的。

想要更了解這些 GPIB 的功能和 Status Word ,請參考下列的 Related Links 網址連結。



相關連結:

Product Manuals: NI-488.2 User Manual for Windows
Product Manuals: NI-488.2 Function Reference Manual for Windows
KnowledgeBase 2I4E7MXH: Disabling a GPIB Interface as System Controller (SC)
Developer Zone Example: Serial Polling Between Two Computers (Controller and Non-controller)



附加檔案:

 






報告日期: 03/30/1998
最後更新: 01/03/2013
文件偏號: 17TGL4TR