C#ABB机器人PC SDK 通讯05

1、加载程序:相当于把自己写的机器人代码加载到ABB机器人示教器中。加载需要机器人程序路径,上一篇所讲到的保存就是为加载准备,所以加载之前必须保存。

还是老样子,双击加载控件

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6JC95Y-25L2V5Y67,size_20,color_FFFFFF,t_70,g_se,x_16

        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、显示程序机器手臂所在程序步骤和指针所在程序的步骤。

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6JC95Y-25L2V5Y67,size_20,color_FFFFFF,t_70,g_se,x_16

进入实时函数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通讯的时候花费更少的时间,把更多的时间用在项目开发上。博客可能存在问题,可以一起谈论

  • 15
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值