1、加载程序:相当于把自己写的机器人代码加载到ABB机器人示教器中。加载需要机器人程序路径,上一篇所讲到的保存就是为加载准备,所以加载之前必须保存。
还是老样子,双击加载控件
private void button19_Click(object sender, EventArgs e)
{
Task tRob = controller.Rapid.GetTask(comboBoxtask.SelectedItem.ToString());
if (tasks != null)
{
string str = textBox5.Text;
if (str == "")
{
MessageBox.Show("请选择路径");
return;
}
try
{
using (Mastership.Request(controller.Rapid))
{
tRob.LoadModuleFromFile(str, RapidLoadMode.Replace);
}
MessageBox.Show("加载成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
2、显示程序机器手臂所在程序步骤和指针所在程序的步骤。
进入实时函数Timer,在Timer中创建线程 ,加快运算时间
private void timer1_Tick(object sender, EventArgs e)
{
//程序加载步骤
Thread ProgressChange = new Thread(progresschange);
ProgressChange.IsBackground = true;
ProgressChange.Start();
}
private void progresschange()
{
if (iscanchangetext == true && tasks[taskint].ProgramPointer != null && tasks[taskint].MotionPointer != null)
{
try
{
ProgramPosition programPosition = tasks[taskint].ProgramPointer;
string programstr = programPosition.Range.End.Row.ToString();
ProgramPosition position = tasks[taskint].MotionPointer;
string motionstr = position.Range.End.Row.ToString();
alllines = textBox4.Text.Split('\n');
postionindex = Convert.ToInt32(programstr);
motionindex = Convert.ToInt32(motionstr);
string changeprogram = postionindex.ToString() + " ->" + alllines[postionindex - 1].Trim();//指针
string changemotion = motionindex.ToString() + " Z*" + alllines[motionindex].Trim();//机器人
textBox10.Text = changeprogram;
textBox8.Text = changemotion;
string[] changePointx = alllines[postionindex - 1].Trim().Split(' ');
changePoint = changePointx[1].Split(',');
}
catch (Exception ex)
{
beginback = false;
}
}
}
2、查看数据变量
双击数据控件
private void button11_Click(object sender, EventArgs e)
{
if (comboBoxtask.SelectedItem.ToString() != null)
{
RapidSymbolSearchProperties date = RapidSymbolSearchProperties.CreateDefault();
date.Types = SymbolTypes.Data;
date.SearchMethod = SymbolSearchMethod.Block;
date.Recursive = true;
date.InUse = false;
date.LocalSymbols = false;
RapidSymbol[] symbols = tasks[taskint].SearchRapidSymbol(date, comboBox2.SelectedItem.ToString(), string.Empty);
this.listView2.Items.Clear();
foreach (RapidSymbol symbol in symbols)
{
try
{
RapidData rD = tasks[taskint].GetRapidData(symbol);
textBox3.AppendText(rD.Name + " |");
ListViewItem item2 = new ListViewItem(symbol.Name);
item2.SubItems.Add(symbol.Type.ToString());
item2.SubItems.Add(rD.RapidType.ToString());
if (rD.Value != null)
{
item2.SubItems.Add(rD.Value.ToString());
}
else
{
item2.SubItems.Add("0");
}
item2.Tag = symbol;
this.listView2.Items.Add(item2);
}
catch (Exception ex)
{
return;
}
}
}
}
3、写入数据
该代码只能写入一些类型变量,其他复杂变量写入并未开发,大家可以自己尝试着,思路是一样的
双击写入按键
private void button22_Click(object sender, EventArgs e)
{
string str = textBox7.Text;
string strVariable = listView2.SelectedItems[0].ToString();
WriteRapidDate(taskstring, modulestring, strVariable, str);
}
void WriteRapidDate(string strName, string strModule, string strVariable, string str)
{
if (controller == null)
{
return;
}
try
{
RapidData rD = controller.Rapid.GetRapidData(strModule, strVariable);
IRapidData val = rD.Value;
if (val is ABB.Robotics.Controllers.RapidDomain.Num)
{
Num rapidNum = (Num)rD.Value;
rapidNum.FillFromString2(str);
using (Mastership.Request(controller.Rapid))
{
rD.Value = rapidNum;
}
}
else if (val is ABB.Robotics.Controllers.RapidDomain.Bool)
{
Bool rapidBool = (Bool)rD.Value;
rapidBool.FillFromString2(str);
using (Mastership.Request(controller.Rapid))
{
rD.Value = rapidBool;
}
}
else if (val is ABB.Robotics.Controllers.RapidDomain.Pos)
{
Pos rapidPos = (Pos)rD.Value;
rapidPos.FillFromString2(str);
using (Mastership.Request(controller.Rapid))
{
rD.Value = rapidPos;
}
}
}
catch (Exception ex)
{
MessageBox.Show("异常错误:" + ex.Message);
}
}
好了,C#ABB机器人PC SDK通讯已经初步完成,但是PC SDK还有很多封装好的功能,本人曾经因为解决ABB机器人通讯问题花费大量的时间,写这个博客是为了让后面一些人在ABB通讯的时候花费更少的时间,把更多的时间用在项目开发上。博客可能存在问题,可以一起谈论