For data transmitting/receiving as slave mode in GPIB, to perform data transmitting/receiving, you need not to specify the address.
Example:
- Transfer (Transmits data to listener and returns 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 ( DevId, &SendLen, SendBuf ); // Transmits data to master if ( Ret == 0 ) Printf ( "%ld\n", SendLen ); // Outputs number of transmitted data on normal completion
|
- Reception (Receives data from talker, 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 ( DevId, &RecLen, RecBuf ); // Receives data from talker if ( Ret == 0 ) { // Confirms whether reception normally completed Printf ( "%ld\n", RecLen ); // Outputs number of received data Printf ( "%s\n", RecBuf ); // Outputs received data } |
Practical sample:
Performs data transmitting/receiving after master confirms talker and listener.
- Transfer (Transmits data to listener and returns number of transmitted data on normal completion.) |
long SendLen; char SendBuf[256]; long TAflag; TAflag = 0; // Initializes flag to confirm specified talker do { Ret = GpibGetStatus ( Id, 0x13, &TAflag); // Confirms talker is specified if ( Ret != 0 ) break; // Checks return code } while ( TAflag == 0 ); // Loops until talker is specified if (TAflag == 1 ) { // Performs transfer when talker is specified 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 master if ( Ret == 0 ) Printf ( "%ld\n", SendLen ); // Outputs number of transmitted data on normal completion } |
- Reception (Receives data from talker, outputs number of received data and received data on normal completion.) |
long RecLen; char RecBuf[256]; long LAflag; LAflag = 0; // Initializes flag to confirm specified listener do { Ret = GpibGetStatus ( Id, 0x14, &LAflag); // Confirms listener is specified if ( Ret != 0 ) break; // Checks return code } while ( LAflag == 0 ); // Loops until listener is specified if (LAflag == 1 ) { // Performs transfer when listener is specified RecLen = 256; // Sets maximum number of data to receive to 256 Ret = GpibRecData ( DevId, &RecLen, RecBuf ); // Receives data from talker if ( Ret == 0 ) { // Confirms whether reception normally completed Printf ( "%ld\n", RecLen ); // Outputs number of received data Printf ( "%s\n", RecBuf ); // Outputs received data } |
Remarks:
Usually the following codes are unnecessary in initial state because the address is not set. If address has been set, the following codes must be added before executing data transmitting/receiving functions to make address information nothing.
short Talker, ListenerArray[15]; Talker = -1; ListenerArray[0] = -1; Ret = GpibSetAddrInfo ( DevId, Talker, ListenerArray ); |