Remote API getting object name (extension)

Typically: "How do I... ", "How can I... " questions
Post Reply
lisavitolo
Posts: 2
Joined: 12 Jul 2013, 15:04

Remote API getting object name (extension)

Post by lisavitolo » 12 Jul 2013, 15:30

Hello,

I'm using the Remote C++ API and I'm trying to get the object name given the handle. Following your tutorial I added a custom command to the remote API. The issue is, when I call the new command I get garbage data, and V-REP immediately crashes. This is the code:

The "client" part:

Code: Select all

EXTAPI_DLLEXPORT simxInt simxCustomGetObjectName(simxInt clientID,simxInt objectHandle,simxChar** objectName,simxInt operationMode)
{
	simxChar* dataPointer;
	simxInt returnValue;

	if (_communicationThreadRunning[clientID]==0)
		return(simx_error_initialize_error_flag);

	if (operationMode==simx_opmode_remove)
		return(_removeCommandReply_int(clientID, simx_customcmd_get_object_name, objectHandle));

	dataPointer=_exec_int(clientID,simx_customcmd_get_object_name,operationMode,0,objectHandle,&returnValue);
	if ((dataPointer!=0)&&(returnValue==0))
		objectName[0] = dataPointer+SIMX_SUBHEADER_SIZE+_getCmdDataSize(dataPointer);
        
	return(returnValue);
}
The V-REP side:

Code: Select all

if (_rawCmdId == simx_customcmd_get_object_name)
{
    int handle = littleEndianIntConversion( ((int *)(_cmdData+0))[0], otherSideIsBigEndian );
    char* objName = simGetObjectName(handle);
    bool success = (objName != NULL);
    
    if (success) {
        retCmd->setDataReply_custom_copyBuffer(objName, int(strlen(objName) + 1), success);
        simReleaseBuffer(objName);
    } else {
        retCmd->setDataReply_nothing(false);
    }
}
And finally, how the command is invoked in my application (the id is returned by simxGetObjects):

Code: Select all

#include <extApi.h>
#include <extApi.c>
#include <extApiPlatform.h>
#include <extApiPlatform.c>
#include <extApiCustom.c>
#include <extApiCustom.h>
#include <extApiCustomConst.h>

[...]
simxChar **name = new simxChar *;
name[0] = new simxChar[200];
simxCustomGetObjectName(connection, id, name, simx_opmode_oneshot_wait);
cout << (*name) << endl;
The function call returns an error "3", which I couldn't find in the error list, and as I mentioned the string contains garbage data. What am I doing wrong?

Thanks a lot,
Lisa

coppelia
Site Admin
Posts: 7325
Joined: 14 Dec 2012, 00:25

Re: Remote API getting object name (extension)

Post by coppelia » 12 Jul 2013, 15:45

Hello Lisa,

Before having a look at your code... do you really want to implement your own function for that? You could use the remote API function simxGetObjectGroupData, with dataType=0. But make sure you have the last V-REP version (3.0.4): only since then is that function implemented.

Cheers

lisavitolo
Posts: 2
Joined: 12 Jul 2013, 15:04

Re: Remote API getting object name (extension)

Post by lisavitolo » 15 Jul 2013, 20:11

Hello,

yes, I had the one immediately preceding that. Thanks for the input, with the newest version it worked.

Post Reply