Computer to Computer Communication Via GPIB

Updated Sep 20, 2023

Environment

Driver

  • NI-488.2

How can I set up two computers to communicate with each other via GPIB?

Below is a sequence of events that you can use as a guideline for computer to computer communication. Complete the following steps to communicate from computer to computer using GPIB:
  1. Leave both computers with their default GPIB settings. We are going to define one computer as the Controller and the other computer as the Non-Controller. You do not have to change any settings.
  2. On the Controller computer, you will need to make sure that you open a session to an instrument with primary address of 1 (as set above). Complete the following steps to open an instrument session in IBIC:
    1. Use the command ibfind GPIB0 to open a session to the GPIB board.
    2. Use the ibsic to send an interface clear message to the bus.
    3. Use the ibsre 1 to assert the Remote Enable line whenever you address instruments.
    4. Use ibdev 0 1 0 13 1 0 to to open a session to the Non-Controller. The first parameter is the index of the access board. Second is the primary GPIB address for the device. Third is the secondary address of the GPIB device (generally 0). Fourth is the I/O timeout value. Fifth is the EOI mode of the device. Sixth is the EOS character mode for the device. All of these settings can be found in NI-MAX for a specific GPIB device.
    5. Use the ibwrt "HELLO" to send a string of data, in this case the word HELLO to the Non-Controller.
  3. Use the Interactive Control (IBIC) to test these commands. Later, you can implement these steps in your program. Complete the following steps on the Non-Controller:
    1. Use the command ibfind GPIB0 to open a session to the GPIB board.
    2. Use the command ibrsc 0 to release system control. This is where you make it the computer a non-controller.
    3. Use the command ibpad 1 to change the primary GPIB address of the Non-Controller from 0 to 1.
    4. Check to see if the ATN line is unasserted and the computer is addressed as a listener. The LACS line goes high in the Status Word when the computer is addresses as a listener. You can create a loop which constantly checks this.
    5. Read the command sent from the Controller using the ibrd #, where # is the number of bytes you expect to receive. In this case we are expecting 5 bytes to be read since we sent HELLO. 
For the Controller steps, you should enable readdressing to make sure that the Non-Controller is readdressed to listen every time. Otherwise, you will get an ENOL error, which means no listener is found. To enable readressing, you can use the command ibconfig ibcreaddr 1; this is something you only need to do on the Controller. This step is required if you want to modify the above code to run in a loop.

For the Non-Controller steps, you would perform step 4 in a loop, until the Non-Controller is addressed to listen. This will happen when the Controller sends a data message, and then you perform step 5 and read the message. You would use a similar approach on writes, but instead of waiting to see if you were told to listen, you would wait to see if you were told to talk which happens when the TACS line goes high in the Status Word.

For programmatic control follow this sample source code created in C that performs these operations:

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

In order to run this code, be sure to complete the following steps:
  1. Include the windows.h header file.
  2. Include the ni488.h header file.
  3. Link your application with the appropriate language interface file.
    1. For Microsoft C/C++, link with gpib-32.obj.
    2. For Borland C/C++, link with borlandc_gpib-32.obj. 
For more information about these GPIB functions and the Status Word, see the related links section.

Next Steps

It's important to note that using GPIB for PC to PC communication is generally outdated due to reliability and speed concerns. For most modern applications, it's recommended to use a protocol like USB or Ethernet to communicate between two computers, and to save GPIB communication for instruments and devices specifically made to communicate using GPIB.