Data Transmitting/Receiving


For data transmitting/receiving as master mode in GPIB, at first, you need to set the address of destination device to communicate with, and then perform data transmitting/receiving.

For API-GPIB(LNX), when use Equipment ID in data transmitting/receiving functions, data transmitting/receiving can be performed without setting address because the ID contains address information of destination device. When use Device ID , It is necessary to set address information with GpibSetAddrInfo function because the ID does not contain address information.

 

 

Example:

Use Equipment ID

- Transfer (Transmits data (IDN*) to destination device specified by EqpID, and outputs the number of transmitted data on normal completion.)

long SendLen;

char SendBuf[256];

        strcpy ( SendBuf, "*IDN?" );                                   // Sets data to transmit to [*IDN?]

        SendLen = strlen ( SendBuf );                                // Retrieves number of transfer string from data to transmit

        Ret = GpibSendData ( EqpId, &SendLen, SendBuf );   // Transmits data to device specified by Equipment ID

        if ( Ret == 0 ) Printf ( "%ld\n", SendLen );              // Outputs number of transmitted data on normal completion

- Reception (Receives data from device specified by EqpID, outputs number of received data and received data on normal completion.)

long RecLen;

char RecBuf[256];

        RecLen = 256;                                                     // Sets maximum number of data to receive to 256

        Ret = GpibRecData ( EqpId, &RecLen, RecBuf );        // Receives data from device specified by Equipment ID

        if ( Ret == 0 ) {                                                     // Confirms whether reception normally completed

                Printf ( "%ld\n", RecLen );                            // Outputs number of received data

                Printf ( "%s\n", RecBuf );                             // Outputs received data

        }

Use Device ID

- Transfer (Transmits data (IDN*) to slave device whose address is 1, and returns number of transmitted data on normal completion.)

short Talker, ListenerArray[15];

long SendLen;

char SendBuf[256];

        Talker = 0;                                                                // Specifies My Address (GPIB board)

        ListenerArray[0] = 1;                                                  // Specifies address of destination device to receive data

        ListenerArray[1] = -1;                                                // Specifies [-1] as terminal (It must be input at last of array for listener.)

        Ret = GpibSetAddrInfo ( DevId, Talker, ListenerArray );   // Sets address

        strcpy ( SendBuf, "*IDN?" );                                       // Sets data to transmit to [*IDN?]

        SendLen = strlen ( SendBuf );                                     // Retrieves number of transfer string from data to transmit

        Ret = GpibSendData ( DevId, &SendLen, SendBuf );        // Transmits data to device specified by GpibSetAddrInfo function

        if ( Ret == 0 ) Printf ( "%ld\n", SendLen );                    // Outputs number of transmitted data on normal completion

 

- Reception (Receives data from slave device whose address is 1, outputs number of received data and received data on normal completion.)

short Talker, ListenerArray[15];

long RecLen;

char RecBuf[256];

        Talker = 1;                                                                   // Specifies address of destination device to transmit data

        ListenerArray[0] = 0;                                                     // Specifies My Address (GPIB board)

        ListenerArray[1] = -1;                                                   // Specifies [-1] as terminal (It must be input at last of array for listener.)

        Ret = GpibSetAddrInfo ( DevId, Talker, ListenerArray );      // Sets address

        RecLen = 256;                                                              // Sets maximum number of data to receive to 256

        Ret = GpibRecData ( DevId, &RecLen, RecBuf );                // Receives data from device specified by GpibSetAddrInfo function

        if ( Ret == 0 ) {                                                              // Confirms whether reception normally completed

                Printf ( "%ld\n", RecLen );                                      // Outputs number of received data

                Printf ( "%s\n", RecBuf );                                       // Outputs received data

        }