rosbridge v2 msg format and subscriber callback in csharp
With the help of the code provided here: RosBrigde client for windows in C# I managed to communicate with winros's tcp_server from my external program and subscribe to a topic. When I try to receive the topic data I face two problems:
- I receive a string formatted as: "topic: ... msg: {data: ...} op: ..." How do I manage to retrieve the data value of the string? my message as I have created it consists of a class with three string variables, but that doesn't seem to work
- I receive only one string and then the call back times out. I have put the code inside a loop but no results
Thank you for any help.
Asked by Morgane on 2015-03-10 03:27:52 UTC
Answers
rosbridge messages come in a JSON encoded string as defined in the rosbridge protocol spec (https://github.com/RobotWebTools/rosbridge_suite/blob/develop/ROSBRIDGE_PROTOCOL.md). You will need to utilize a JSON parser in C# to extract the data field which will contain your message data as a JSON object. This data comes in as a single JSON string.
Asked by rtoris288 on 2015-03-10 07:41:07 UTC
Comments
So when I receive this message ex: socket.receive(recdata); recdata is a string with the format I described. I made a class with op, msg and topic members, and if rd is an instance of that class I went on an called the deserializer rd = jsonconvert.deserializeobject(recdata); rd.msg doesn't work
Asked by Morgane on 2015-03-11 02:57:42 UTC
I am unfamiliar with JSON parsing in C# but I suspect something needs to be done to parse the msg
field which in itself is its own JSON object. Are the other fields set correctly? Can you post the recdata
string that is coming in or verify it is valid JSON (http://jsonlint.com/)?
Asked by rtoris288 on 2015-03-11 07:03:06 UTC
yes the string is: {"topic": "/chatter", "msg":{"data": "hello world 1"}, "op": "publish"} The actual question is: what type of c# type is msg? (it must contain the string _data)
Asked by Morgane on 2015-03-11 07:30:59 UTC
Comments