Extending the B0-based remote API

The BØ-based remote API should not be mixed-up with the legacy remote API (or simply remote API), which is an older version of the remote API that is less flexible, and more difficult to extend.

You basically have two options, if you wish to use API commands that are not exposed by the B0-based remote API:

  • You can use the generic function simxCallScriptFunction
  • You can extend the B0-based remote API


  • Using the generic function simxCallScriptFunction: instead of extending the functions that the B0-based remote API offers, one can use the generic B0-based remote API function simxCallScriptFunction: this will call a CoppeliaSim script function, which can then execute any type of operation locally, then return data. For instance:

    function myFunctionName(args)
        for i=1,#args,1 do
            print('Argument '..i..' is :')
            print(args[i])
            print('')
        end
        return 'Hello to you too!',42 -- return a string and a number
    end

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

    import b0RemoteApi
    
    with b0RemoteApi.RemoteApiClient('b0RemoteApi_pythonClient','b0RemoteApi') as client:    
        args=['Hello World!',[1,2,3],59]
        ret=client.simxCallScriptFunction('myFunctionName@objectName','sim.scripttype_childscript',args,client.simxServiceCall())
        print(ret)

    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.


    Extending the B0-based remote API: there are 4 simple steps involved:

  • Add your function as the end of file programming/remoteApiBindings/b0-based/generate/simxFunctions.xml
  • Run following: python generate.py --gen-simx-all --xml-file simxFunctions.xml ./generated
  • As a result of previous step, /generated will contain the client-side B0-based remote API code, as well as the generated documentation. Copy those files into place.
  • Finally, add the server-side counterpart to your new function at the beginning of file lua/b0RemoteApiServer.lua


  • Recommended topics

  • B0-based remote API modus operandi