Extending the legacy remote APIInstead of extending the functions that the legacy remote API offers, one can use the generic legacy remote API function simxCallScriptFunction: this will call a CoppeliaSim 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 legacy 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=sim.simxCallScriptFunction(clientID,'/path/to/object',
sim.sim_scripttype_childscript,'myFunctionName',inputInts,inputFloats,inputStrings,
inputBuffer,sim.simx_opmode_blocking)
if res==sim.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. For other usage examples, refer to the various files named complexCommandTest.* in folder programming/remoteApiBindings. |