Receiving

[At master]

BYTE Srbuf[100];                      //Buffer for receiving

 

Cmd[0] = 2;                           //The number of listeners + 1 (here, there is one listener)

Cmd[1] = TalkerAdrs;                  //The address of device that sends data

Cmd[2] = ListenerAdrs;                //The address of device that receives data (own address)

Ret = GpListen(Cmd, &Srlen, Srbuf);   //Srlen = data length: Srbuf = buffer that stores data

 

[At slave]

Ex. 1:  The receiving operation starts after checking the talker designation from the master.
This implementation is recommended to match the communication timing with the master.

DWORD   Ret, RecLen, Cmd[10], LAreg;

char    RecBuf[10];

do{

    Ret = GpBoardstsEx(0, 0x14, &LAreg); // Confirms listener is specified.

    if(Ret != 0) return;                 // Checks return code.

}while(LAreg == 0);                      // Loops until listener is specified.

Cmd[0] = 0;                              // Indicates no multi line message.

RecLen = 10;                             // Sets maximum number of data to receive to 10.

Ret = GpListen(Cmd, &RecLen, RecBuf);    // Receives data from talker.

 

Ex. 2: Receives without checking the talker designation from the master.

BYTE Srbuf[100];                      //Buffer for receiving

 

Cmd[0] = 0;                           //As cannot specify multi line message, writes code like this.

Ret = GpListen(Cmd, &Srlen, Srbuf);   //Srlen = data length: Srbuf = buffer that stores data

 

Notes

The receiving data program is almost the same as the transmitting data.
Uses GpListen function.

The value of Srlen must not exceed the number of data in Srbuf (the number of bytes).
For receiving data, the size of Srbuf must be specified.

To easy understand the error, the CheckRet function is provided.
This function code is written in standard module.

Writing this function in the standard module makes it used for general purpose.

This function can be used in other programs by "Add File". (The code of CheckRet function is written in "SubFunc.cpp".)

 

Notes on the master side:

If you attempt to send or receive data from the master side when a slave device is measuring, communication processing may not be performed correctly.
In general, slave devices have a function that issues an SRQ request to the master when a time-consuming process is completed.

In this case, we recommend that the master side wait for an SRQ request before sending or receiving data.