simxCallScriptFunction handle parameter question

Typically: "How do I... ", "How can I... " questions
Post Reply
SamuelXu
Posts: 8
Joined: 30 Oct 2016, 11:12

simxCallScriptFunction handle parameter question

Post by SamuelXu »

Hi:
According manual, simxCallScriptFunction() looks a magic remote function, which can call into simulator remotely
I just curious whether I can call a regular API which doesn't have a remote API version, via simxCallScriptFunction().
I have an experiment in my C client to invoke simGetObjectName indirectly via simxCallScriptFunction(), just like to implement a missing simxGetObjectName(), while looks failed. the return value is 8: I guess it means invalid handle

ret=simxCallScriptFunction(client_id,
"just_a_test",
sim_scripttype_mainscript,
"GetObjectName_function",
1,
&g_handle, /*here handle, I just get from a remote API inside C client, and I can make sure it maps to a valid object of C client side*/
0,
NULL,
0,
NULL,
0,
NULL,
&outIntCnt,
&outInt,
&outFloatCnt,
&outFloat,
&outStringCnt,
&outString,
NULL,
NULL,
simx_opmode_blocking);

I just wonder: is it a right way to try to call some regular API which missed remote version. If it is possible, I guess client and server has diff understanding of "handle"?

Thanks!

Samuel

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

Re: simxCallScriptFunction handle parameter question

Post by coppelia »

Hello Samuel,

How does your function GetObjectName_function look like in your main script?
Make sure to test and modify the code in programming/remoteApiBindings/lib/complexCommandTest.cpp and the scene that goes with it in scenes/remoteApiCommandServerExample.ttt.

Cheers

SamuelXu
Posts: 8
Joined: 30 Oct 2016, 11:12

Re: simxCallScriptFunction handle parameter question

Post by SamuelXu »

Hi, coppelia:
Thanks for reply!
There isn't a main script which contains GetObjectName in my ttt.
My main purpose is to invoke simGetObjectName() directly from client side without a main script involvement. Yes I mimic complexCommandTest.cpp's example of createDummy_function() as following.

result=simxCallScriptFunction(clientID,"remoteApiCommandServer",sim_scripttype_childscript,"createDummy_function",0,NULL,3,coords,1,"MyDummyName",0,NULL,&retIntCnt,&retInts,NULL,NULL,NULL,NULL,NULL,NULL,simx_opmode_blocking);


I guess above example shows how to invoke simCreateDummy() with name conversion of createDummy_function, or my understanding is incorrect, here createDummy_function() != simCreateDummy()? :)

Thanks!
Samuel

SamuelXu
Posts: 8
Joined: 30 Oct 2016, 11:12

Re: simxCallScriptFunction handle parameter question

Post by SamuelXu »

Hi, coppelia:
Could you kindly point it out where my above understanding make sense or not?

Thanks!

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

Re: simxCallScriptFunction handle parameter question

Post by coppelia »

I would suggest that you take the example that I mention and try to understand it, then modify it step-by-step. Eventually you will see that something is not working anymore and you will immediately know why this is (because of the change).

In order to be able to call a script function, you need to know:
  • The name of the script function
  • On which object the script is attached to
  • The type of script to call (e.g. a customization script or a child script can exist at the same time for the same object)
Cheers

SamuelXu
Posts: 8
Joined: 30 Oct 2016, 11:12

Re: simxCallScriptFunction handle parameter question

Post by SamuelXu »

Thanks coppelia:

Your suggestion works for me. Now I can play with the complexCommandTest.cpp and corresponding ttt correctly, and it answers my question: I should always call a script inside ttt script, and try to avoid directly invoke a regular API directly from client (in this case, I need stub inside ttt scene script).

I have additional question related with complexCommandTest.cpp:
simxCallScriptFunction() is a wonderful way inside example, while manual mentions there is a better simCallScriptFunctionEx() which using stack to exchange data between simulator and client. But I only find Stack functionality API from regular API list, which means my C client doesn't have a way to create/push/pop the stack.
So I just wonder, if I want to use simCallScriptFunctionEx(), how my C part (client side) can manipulate the stack via some stack API? Or could you kindly point me same example of simCallScriptFunctionEx() which is using stack to exchange var?

Thanks a lot!

Samuel

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

Re: simxCallScriptFunction handle parameter question

Post by coppelia »

Unfortunately you can't use the stack functionality to exchange data between a remote API client and V-REP. The stack functionality is currently only supported for plugins. So that means, you will have to somehow pack/unpack more complex data yourself, and transmit it via simxCallScriptFunction.

Cheers

Post Reply