## String signal

Typically: "How do I... ", "How can I... " questions
zzxx
Posts: 4
Joined: 24 Nov 2020, 12:54

### String signal

Hello,

I'm trying to retrieve data from my simulation through MATLAB. I've got the data going into a table in a non-threaded child script and I set the string signal:

Code: Select all

% matlab
sim.setStringSignal("dataata",sim.packTable(table))

But I'm not sure how to get this data into MATLAB? I've tried this:

Code: Select all

% matlab
sim.simxGetStringSignal(clientID,'data',sim.simx_opmode_streaming);
[r, string] = sim.simxGetStringSignal(clientID,'data',sim.simx_opmode_buffer);

But I get the return code 1, and no value for the string.

Please can you help with this?

coppelia
Posts: 8371
Joined: 14 Dec 2012, 00:25

### Re: String signal

Please make sure to understand how data streaming works with the legacy remote API: it is normaly that in the first moments the function will return simx_return_novalue_flag, i.e. 1

Additionally, you can't unpack the table on the Matlab side, when you pack it with sim.packTable. Instead pack it with e.g. messagePack. On CoppeliaSim's side you'd do something like:

Code: Select all

    msgPack=require('messagePack')
packedData=msgPack.pack(myTable)
On Matlab's side, e.g.:

Code: Select all

data=parsemsgpack(packedData)
You can of course also use another serialization protocol, such as json, on CoppeliaSim's side:

Code: Select all

    json=require('dkjson')
packedData=json.encode(myTable,{indent=true})
Another way would be to send/receive only simply data types, e.g. a table of float values:

Code: Select all

packedData=sim.packFloatTable(myFloatTable)
then use simxUnpackFloats on the Matlab side.

Cheers

zzxx
Posts: 4
Joined: 24 Nov 2020, 12:54

### Re: String signal

Thank you very much for your support. However, I don't seem to be able to get the information from my table. I tried your suggestions and for the msgpack one I just get the value 112, and for the packed float I get this error:

Error using typecast
The first input must contain a multiple of 4 elements to convert from uint8 (8 bits) to single (32 bits).

Error in remApi/simxUnpackFloats (line 1806)
floatArray=typecast(uint8(single(string)),'single');

I'm just trying to retrieve all of the sensor data I have placed in the table at each simulation pass, is this the correct way to do it?