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:
- 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.
- 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:
- Use the command ibfind GPIB0 to open a session to the GPIB board.
- Use the ibsic to send an interface clear message to the bus.
- Use the ibsre 1 to assert the Remote Enable line whenever you address instruments.
- 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.
- Use the ibwrt "HELLO" to send a string of data, in this case the word HELLO to the Non-Controller.
- 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:
- Use the command ibfind GPIB0 to open a session to the GPIB board.
- Use the command ibrsc 0 to release system control. This is where you make it the computer a non-controller.
- Use the command ibpad 1 to change the primary GPIB address of the Non-Controller from 0 to 1.
- 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.
- 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:
- Include the windows.h header file.
- Include the ni488.h header file.
- Link your application with the appropriate language interface file.
- For Microsoft C/C++, link with gpib-32.obj.
- 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.