0
点赞
收藏
分享

微信扫一扫

C# ABB机器人通讯04

ZSACH 2022-04-08 阅读 68
c#

1、打开程序

TabTages的第三个为机器人程序,自己可以看着设计

将工具箱中的openFileDialog拖入界面设计中,添加文件控件

 双击打开程序

        private void button15_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.textBox5.Text = this.openFileDialog1.FileName;
                FileStream fileStream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
                byte[] arraydate = new byte[(int)fileStream.Length];
                int index = 0;
                int code = fileStream.ReadByte();
                while (code != -1)
                {
                    arraydate[index] = Convert.ToByte(code);
                    code = fileStream.ReadByte();
                    index++;
                }
                this.textBox4.Text = Encoding.Default.GetString(arraydate);
                fileStream.Close();
            }
        }

2、PP to main 

双击PP to main 按键控件

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                if (controller.OperatingMode == ControllerOperatingMode.Auto)
                {
                    tasks = controller.Rapid.GetTasks();
                    using (Mastership.Request(controller.Rapid))
                    {
                        tasks[taskint].ResetProgramPointer();
                        MessageBox.Show("程序指针已经复位");
                    }
                }
                else
                {
                    MessageBox.Show("请切换自动模式");
                }
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show("权限已经占用" + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            iscanchangetext = true;
        }

3、指针设置 // 将指针指向指定程序

双击指针设计

        private void button16_Click(object sender, EventArgs e)
        {
            try
            {
                if (controller.OperatingMode == ControllerOperatingMode.Auto)
                {
                    tasks = controller.Rapid.GetTasks();
                    using (Mastership.Request(controller.Rapid))
                    {

                        tasks[taskint].SetProgramPointer(modulestring, routinestring);
                        MessageBox.Show("程序指针已经设置到" + routinestring);
                    }

                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("发生错误!:" + ex.Message);
            }
        }

4、程序启动

双击程序启动按键

        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                if (controller.OperatingMode == ControllerOperatingMode.Auto)
                {
                    using (Mastership.Request(controller.Rapid))
                    {
                        StartResult s = controller.Rapid.Start();
                    }
                    isfinshgravity = true;
                }
                else
                {
                    MessageBox.Show("请切换自动模式");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("出错了!" + ex.Message);
            }
            iscanchangetext = true;
        }

5、程序停止

        private void button8_Click(object sender, EventArgs e)
        {
            try
            {
                using (Mastership.Request(controller.Rapid))
                {
                    controller.Rapid.Stop(StopMode.Immediate);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("出错了!" + ex.Message);
            }
            iscanchangetext = false;
        }

6、保存程序

首先需要saveFileDialog控件,将此控件添加在主窗口

 双击保存程序

        private void button21_Click(object sender, EventArgs e)
        {
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllText(this.openFileDialog1.FileName, this.textBox4.Text);
                MessageBox.Show("保存成功");
            }
            else
            {
                return;
            }
        }
举报

相关推荐

0 条评论