- Home /
Unity crash at RESTSharp GET Call
I use RestSharp to send post and get calls to a robot which is connected via LAN through a switch with my computer. My get call:
public Vector3 getEffectorPos()
{
var c = new RestClient("http://" + robotIP);
var r = new RestRequest("/present/effector_position.json", Method.GET);
List<String> queryResult = c.Execute<List<String>>(r).Data;
string[] tmp = queryResult[0].Split('[', ']');
Vector4 x = parseStringToFloat4(tmp[2]);
Vector4 y = parseStringToFloat4(tmp[4]);
Vector4 z = parseStringToFloat4(tmp[6]);
Vector3 pos = new Vector3(x.w, y.w, z.w);
effPos.setPos(x.w, y.w, z.w);
effPos.cos = x.x;
effPos.sin = -x.y;
return pos;
}
Because the robot has the static ip 192.168.200.99 I have to switch to a static ip adress in the .200 subnet every time I want to run the project. When I first started the project I would get an error like NullReference or Bad Gateway if the robot was not connected.
But now if I forget to switch from dynamic ip to a static one and the programm can't connect to the robot Unity crashes. And afterwards even if I switch back to a static ip Unity proceeds to crash and it seems like nothing helps but waiting and after some time it will just work again without me doing anything.
It seems like I don't have the same problem with the post call:
public bool postEffectroPos(Vector3 pos, float speed_n)
{
var client = new RestClient("http://" + robotIP);
var request = new RestRequest("/present/effector_position_with_speed.json", Method.POST) { RequestFormat = RestSharp.DataFormat.Json };
effectorPos a = new effectorPos();
a.x = pos.x;
a.y = pos.y;
a.z = pos.z;
a.speed = speed_n;
request.AddBody(a);
bool move = false;
try
{
client.ExecuteAsync(request, response =>
{
if (response.StatusCode == HttpStatusCode.OK)
{
string[] tmp = response.Content.Split(':');
string t = tmp[1].Remove(tmp[1].Length - 1);
move = bool.Parse(t);
//Debug.Log(move);
}
else
{
Debug.Log(response.StatusCode);
}
});
}
catch (Exception error)
{
Debug.Log(error);
}
return move;
}
The post call is async but I didn't figure out yet how to a return a value with async(returns always zero or false, depending on type) and I need the return value of the get call.