三菱PLC通讯 基于官方项目Sample2010的借鉴二次开发---C#连接三菱PLC进行通讯的方法

 

环境:打开三菱PLC安装目录下,Act>Samples>Vcs.NET>Sample2010>bin>Debug目录下分别加载以下 dll(全部都加载是为了后续开发需要用到)

准备工作:

打开官方提供的Sample2010(在Act>Samples>Vcs.NET目录下)将图中两个控件copy到自己的项目中

代码:

        #region 建立连接
        //连接
        private void button1_Click(object sender, EventArgs e)
        {
            //逻辑站
            axActUtlType1.ActLogicalStationNumber = int.Parse(this.textBox1.Text);
            //密码
            axActUtlType1.ActPassword = this.textBox2.Text;
            //打开plc
            int status = axActUtlType1.Open();

            if (status == 0)
            {
                LoadInputPage(iniPath, ref butList);
                LoadOutputPage(iniPath, ref butList);
                Monitor_IO(butList);
                MessageBox.Show("连接成功!");
            }
        }
        //断开连接
        private void button2_Click(object sender, EventArgs e)
        {
            axActUtlType1.Close();
        }
        #endregion

完整项目另见:https://blog.csdn.net/weixin_44490080/article/details/102919269

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值