loading
 
Processing rr_api
Josh from United States  [1 posts]
11 year
So I am using Processing to write the program that will control my robot, the problem I am having is that in the API zip file the processing file does not work. I know that RoboRealm API option is working properly because I can use the command prompt and the telnet command to get responses from RoboRealm, but when I use the API I get no errors, but I get no response. I am not sure what I am doing wrong but would greatly appreciate some help. Code below:

import processing.net.*;
Client rr;
String message;
String totalMsg;

void setup()
{
  size(200, 200);
  // Connect to the local machine at port 5204.
  // This example will not run if you haven't
  // previously started a server on this port
  rr = new Client(this, "127.0.0.1", 6060);
}

String readMessage()
{
  int count=0;
  String msg;
  totalMsg = "";
  
  while ((++count)<10000)
  {
    while (rr.available() <= 0);

    msg = rr.readStringUntil('>');
    if (msg!=null)
    {
      totalMsg = totalMsg + msg;
      if (totalMsg.length()>11)
      {
        if (totalMsg.substring(totalMsg.length()-11).equals("</response>"))
        {
          return totalMsg;
        }
      }
    }
  }
  
  return null;
}

int getVariable(String name)
{
  rr.write("<request><get_variable>"+name+"</get_variable></request>\n");
  message = readMessage();
  if (message!=null)
  {
    String[] m = match(message, "<response>[^>]+>([^<]+)");
    if (m!=null) return Integer.parseInt(m[1]);
  }
  
  return 0;
}  

void draw()
{
  background(0);
  
  int result = getVariable("IMAGE_WIDTH");
  println("The current image count is "+result);
}


This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index