Robot Web Services
3HAC050973-001 Revision:L, Application Manual - Robot Web Services
HelloControllerJson.cs

This is an example of how to use Robot Web Services, JSON and C# (.net 4.5). The idea of this example comes from http://blogs.msdn.com/b/henrikn/archive/2012/02/16/httpclient-is-here.aspx.

The output will look like:

  Hit ENTER to exit ...
  service=system name=RW6_1014 version=6.00.1014.00
  category=OS option=RobotWare OS and English
  category=Options option=613-1 Collision Detection
  ...

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Json;
namespace HelloControllerJson
{
class Program
{
static string _address = "http://192.168.8.105/rw/system?json=1"; // resource to get
static void Main(string[] args)
{
Task t = new Task(GetRWService);
t.Start();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}
// <summary>
// Get the robotware system name, version and version name
// </summary>
static async void GetRWService()
{
var handler = new HttpClientHandler { Credentials = new NetworkCredential("Default User", "robotics") };
handler.Proxy = null; // disable the proxy, the controller is connected on same subnet as the PC
handler.UseProxy = false;
// Send a request continue when complete
using (HttpClient client = new HttpClient(handler))
using (HttpResponseMessage response = await client.GetAsync(_address))
using (HttpContent content = response.Content)
{
// Check that response was successful or throw exception
response.EnsureSuccessStatusCode();
// Get HTTP response from completed task.
string result = await content.ReadAsStringAsync();
// Deserialize the returned json string
dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
// Display controller name, version and version name
var service = obj._embedded._state[0]; // the first item in the json state response is the system name, robotware version and robotware version name
Console.WriteLine(" service={0} name={1} version={2} versionname={3}", service._title, service.name, service.rwversion, service.rwversionname);
// Display all installed options
foreach (var option in obj._embedded._state[1].options) // the second state item is an array of installed options
{
Console.WriteLine(" option={0}", option.option);
}
}
}
}
}