The SendRemoteString function ultimately results in a call to the CommBTWrite system call function on the NXT running your program. This system call is defined as shown below:
Code: Select all
//cCmdWrapCommBTWrite
//ArgV[0]: (return) Status byte, SBYTE
//ArgV[1]: Connection index, 0-3
//ArgV[2]: Buffer
//
NXT_STATUS cCmdWrapCommBTWrite(UBYTE * ArgV[])
{
SBYTE * pReturnVal = (SBYTE*)(ArgV[0]);
UBYTE Connection = *(ArgV[1]);
UBYTE * pBuf;
UWORD BufLength;
DV_INDEX DVIndex;
//Resolve array arguments
DVIndex = *(DV_INDEX *)(ArgV[2]);
pBuf = cCmdDVPtr(DVIndex);
BufLength = DV_ARRAY[DVIndex].Count;
//If there's an old error code hanging around, clear it before proceeding.
if (VarsCmd.CommStat < 0)
VarsCmd.CommStat = SUCCESS;
//!!! Only first 256 bytes could possibly make it through! Should return error on longer input?
//!!! Not requesting a wait-for-response because only known use doesn't read responses.
pMapComm->pFunc(SENDDATA, (UBYTE)BufLength, Connection, FALSE, pBuf, (UWORD*)&(VarsCmd.CommStat));
//!!! Reasonable to wrap below code in cCmdCommBTCheckStatus?
//INPROGRESS means our request was accepted by His Funkiness of pFunc
if (VarsCmd.CommStat == (SWORD)INPROGRESS)
{
*pReturnVal = STAT_COMM_PENDING;
//Set DirtyComm flag so stream is reset after program ends
VarsCmd.DirtyComm = TRUE;
}
//Translate BTBUSY to ERR_COMM_CHAN_NOT_READY
else if (VarsCmd.CommStat == (SWORD)BTBUSY)
{
*pReturnVal = ERR_COMM_CHAN_NOT_READY;
}
else
{
*pReturnVal = UNPACK_STATUS(VarsCmd.CommStat);
}
return (NO_ERR);
}
So the result of this function call is whatever gets written to ArgV[0] of the CommBTWrite system call structure, i.e.,
Code: Select all
TCommBTWrite struct
Result sbyte
Connection byte
Buffer byte[]
TCommBTWrite ends
The return value is stored in Result. This value has nothing whatsoever to do with the remote NXT. The message has not even been sent yet. It is sent by the NXT firmware asynchronously, i.e., the CommBTWrite call returns immediately with a status (Result) value and some time later on the firmware will send the message to the remote NXT on the specified Connection. You can see above where pReturnVal gets set to different values depending on what happens during this function call.
Code: Select all
#define STAT_COMM_PENDING 32 /*!< Pending setup operation in progress */
The most likely result is STAT_COMM_PENDING (aka 0x20 aka 32). That means: "okay, I will send that message ASAP. Please check the bluetooth communication layer status using BluetoothStatus(byte conn) in a loop until it says that the comm status is idle again before trying to send another BT message"
The help for SendRemoteString says "Use RemoteConnectionIdle to determine when this write request is completed." RemoteConnectionIdle just calls BluetoothStatus and returns true when it returns 0.
If you want to get information from the remote NXT, i.e., something that it tries to send the master in response to the message the master sent it then the master will need to read the reponse message from a remote NXT response mailbox using something like ReceiveRemoteString.
John Hansen