Return error with simxCallScriptFunction()

Typically: "How do I... ", "How can I... " questions
Post Reply
johnrowlay
Posts: 19
Joined: 09 Aug 2017, 18:52

Return error with simxCallScriptFunction()

Post by johnrowlay » 02 Nov 2018, 22:24

Hello,

I have a V-Rep scene containing a robot, and in the scene hierarchy I also have a dummy named "remoteApi". This dummy has a non-threaded child script attached, and in this script is the following function:

Code: Select all

testFunction=function(inInts,inFloats,inStrings,inBuffer)
    print('Running test function')
    return {},{},{},''
end
I now want to launch a V-Rep server using the Python remote API. Below is a simple script which I have written to do this:

Code: Select all

from subprocess import Popen
import os
import time

import vrep

port_num = 19990
scene_file = '/home/me/scene.ttt'
host = '127.0.0.1'
process = Popen(['vrep.sh', '-gREMOTEAPISERVERSERVICE_' + str(port_num) + '_FALSE_TRUE', scene_file], preexec_fn=os.setsid)
time.sleep(2)
client_id = vrep.simxStart(host, port_num, True, True, 5000, 5)
if client_id == -1:
    connected = False
    print('Failed to start simulation')
else:
    connected = True
    return_code = vrep.simxSynchronous(client_id, enable=True)
    if return_code is not vrep.simx_return_ok:
        print('Failed to enable synchronous mode')
ret_code, _, _, _, _ = vrep.simxCallScriptFunction(client_id, 'remoteApi', vrep.sim_scripttype_childscript, 'testFunction', [], [], [], bytearray(), vrep.simx_opmode_blocking)
print('Return code = ' + str(ret_code))
This runs fine, until the end, where the return code for simxCallScriptFunction() is 8, instead of 0. This means "The function caused an error on the server side (e.g. an invalid handle was specified)".

What is wrong with my script?

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

Re: Return error with simxCallScriptFunction()

Post by coppelia » 07 Nov 2018, 07:51

Hello,

to be able to call your script function, your script needs to be initialized. A child script is a simulation script, and only gets initialized when simulation is running.

Try maybe using a customization script instead.

Cheers

Post Reply