Extending the remote API

The remote API, or legacy remote API, should not be mixed-up with the BØ-based remote API, which is a newer version of the remote API that is more flexible, easier to use and most importantly, much simpler to extend.

Instead of extending the functions that the remote API offers, one can use the generic remote API function simxCallScriptFunction: this will call a V-REP script function, which can then execute any type of operation locally, then return data. The called script function should always have following input/output form:

function myFunctionName(inInts,inFloats,inStrings,inBuffer)
	-- inInts, inFloats and inStrings are tables
	-- inBuffer is a string
    
    -- Perform any type of operation here.

	-- Always return 3 tables and a string, e.g.:
	return {},{},{},''
end

The remote API client application would then call above script function in following manner (e.g. via a Python script):

inputInts=[1,2,3]
inputFloats=[53.21,17.39]
inputStrings=['Hello','world!']
inputBuffer=bytearray()
inputBuffer.append(78)
inputBuffer.append(42)
res,retInts,retFloats,retStrings,retBuffer=vrep.simxCallScriptFunction(clientID,'objectName',vrep.sim_scripttype_childscript,
                'myFunctionName',inputInts,inputFloats,inputStrings,inputBuffer,vrep.simx_opmode_blocking)
if res==vrep.simx_return_ok:
    print (retInts)
    print (retFloats)
    print (retStrings)
    print (retBuffer)

Make sure that the script, where you are trying to call a function, is initialized: trying to call a function in a simulation script, while simulation is not running will not work. Similarly, trying to call a function in a threaded child script that has already ended (or not yet started) will not work.

For other usage examples, refer to the various files named complexCommandTest.* in folder programming/remoteApiBindings.



Recommended topics

  • Remote API modus operandi