您好!欢迎光临工博士商城

ABB机器人配件专营店

产品:37    
联系我们
您当前的位置:首页 » 新闻中心 » ABB机器人| C#通过webservice获取机器人信息
产品分类
新闻中心
ABB机器人| C#通过webservice获取机器人信息
发布时间:2020-05-25        浏览次数:297        返回列表
ABB机器人| C#通过webservice获取机器人信息

ABB机器人
 
1. webservice为ABB机器人提供的基于web的接口

2. 可以通过编写html等语言,直接访问对应链接获取信息,例如以上效果可以在浏览器直接输入127.0.01/rw/system得到结果。

3. 此处举例在C#创建客户端,获取上述结果。

4. webservice返回的结果通常为XML格式,部分返回结果支持json格式(具体参考手册)。

5. 在c#中创建button及相关textbox控件

6. 为加入相关json等引用,点击工具中的NuGet程序包管理器-程序包管理器控制台,并在控制台安装以下内容:

PM>Install-Package Microsoft.AspNet.WebApi.Client -Version 5.1.2
PM> Install-Package System.Json -Version 4.0.20126.16343

ABB机器人| C#通过webservice获取机器人信息

7. c#代码中添加如下引用

using System.Net;
using System.Net.Http;
using System.Json;

8. 在相关button中添加代码如下:

string url = "http://127.0.0.1/rw/system?json=1";
string username = "Default User";
string password = "robotics";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Credentials = new NetworkCredential(username, password);
request.CookieContainer = _cookies;
request.PreAuthenticate = true;
request.Proxy = null;
request.Timeout = 60;
request.ServicePoint.Expect100Continue = false;
WebResponse response = request.GetResponse();
if (response != null)
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string result = reader.ReadToEnd();
dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
显示控制器名字,版本号等
var service = obj._embedded._state[0]; // the first item in the json state response is the system name, robotware version and robotware version name
textBox7.Text = "service=" + service._title + "\r\n";
textBox7.Text = textBox7.Text + "name=" + service.name + "\r\n";
textBox7.Text = textBox7.Text + "version=" + service.rwversion + "\r\n";
textBox7.Text = textBox7.Text + "versionname= " + service.rwversionname + "\r\n";
// 显示机器人选项
foreach (var option in obj._embedded._state[1].options) // the second state item is an array of installed options
{
textBox7.Text = textBox7.Text + "★option=" + option.option + "\r\n";
}
}
}


更多资讯:ABB机器人配件



分享到: 


 

联系热线:18616260662   联系人:王青慧 联系地址:上海市嘉定区南翔镇众仁路399号B栋20层2007-2012

技术和报价服务:星期一至星期六8:00-22:00 ABB机器人配件专营店