当前位置: 首页 > news >正文

使用三菱PLC源码进行PLC读取写入操作

  1. 安装 MX Component 。

  2. 我的安装地址在:

  3. 在这里插入图片描述

  4. 打开 utl 文件夹下的 Communication Settings Utility 执行。
    配置PLC 添加当前需要配置的PLC 注意 logical station Namber 就是程序里需要对接的逻辑站点编号
    在这里插入图片描述
    5.配置选择对应的COM操作选择对应的cpu型型号,然后测试程序是否可以联通,如果联通则可以继续进行。
    5.程序编辑。
    5.1 选择 对应的SDK
    在这里插入图片描述
    在此demo下有众多可以适用的功能。
    在这里插入图片描述
    其中已经包含了数据各种谁操作,连接关闭等操作。程序引用相关文件。 修改嵌入方式改成否,选择保存本地。
    在这里插入图片描述
    以下就是我简单写了一个操作类:

 public static  class MXCommonGet
{public static bool IsConnect;public static ActUtlType64Lib.ActUtlType64Class axActUtlType1 = new ActUtlType64Lib.ActUtlType64Class();//public   MXCommonGet()//{//    解决因为第三方控件报错,将实例化的对象添加到控件合集中//    //((ISupportInitialize)(this.axActUtlType1)).BeginInit();//    //this.Controls.Add(axActUtlType1);//    //((ISupportInitialize)(this.axActUtlType1)).EndInit();//    }public static  bool ConnectM(){axActUtlType1.ActLogicalStationNumber = 2;//填设置的逻辑站号,站号是在MXcomponent软件里设置的axActUtlType1.ActPassword = "";//密码int iReturnCode = axActUtlType1.Open();//尝试连接PLC,如果连接成功则返回值为0if (iReturnCode == 0){OPCommon.LogWrite.WriteLog("PLC连接成功!");IsConnect = true;return true;}else{OPCommon.LogWrite.WriteLog("PLC连接失败!");IsConnect = false;return false;}}/// <summary>/// 获取前节点数据/// </summary>/// <param name="PointId"></param>/// <returns></returns>public static ResultMsg GetValueInPoint(string PointId){ResultMsg msg = new ResultMsg();try{if ( IsConnect){int relust;int iReturnCode = axActUtlType1.GetDevice(PointId, out relust);if (iReturnCode == 0){msg.ReturnInt = relust;msg.Success = true;}else{msg.Success = false;}}else{ConnectM();msg.Success = true;msg.ReturnInt = 0;}}catch (Exception ex){msg.Success = false;msg.ReturnInt = 0;msg.ErrMsg = "连接出错";} return msg; }/// <summary>/// 设置当前节点数据/// </summary>/// <param name="PointId">节点编号</param>/// <param name="Result"></param>/// <returns></returns>public static ResultMsg SetValueInPoint(string PointId,int  Result){ResultMsg msg = new ResultMsg();try{if ( IsConnect){ int iReturnCode = axActUtlType1.SetDevice(PointId, Result);if (iReturnCode == 0){msg.ReturnInt = Result;msg.Success = true;}else{msg.Success = false;}}else{ConnectM();msg.Success = true;msg.ReturnInt = 0;}}catch (Exception ex){msg.Success = false;msg.ReturnInt = 0;msg.ErrMsg = $"连接出错 {ex.Message}";}return msg;}/// <summary>/// 关闭当前连接/// </summary>/// <returns></returns>public static ResultMsg   CloseThisMX(){ResultMsg msg = new ResultMsg();if (axActUtlType1 != null){int iReturnCode = axActUtlType1.Close();if (iReturnCode == 0){msg.Success = true;msg.ReturnInt = 0;}else{msg.Success = false ;msg.ReturnInt = iReturnCode;}}else{msg.Success = false;msg.ErrMsg = "数据不存在";}return msg;}
}
http://www.lryc.cn/news/426246.html

相关文章:

  • 使用Nvm切换nodeJs高版本之后,使用npm install一闪而过
  • 【Kubernetes】k8s集群安全机制
  • 嵌入式学习---DAY24:进程--二
  • Diffusion Model相关论文解析之(二)DENOISING DIFFUSION IMPLICIT MODELS
  • 【STM32嵌入式系统设计与开发拓展】——14_定时器之输入捕获
  • docker swarm如何让两个副本分别跑在两台不同的主机上
  • GPT助手的训练流程四个主要阶段( GPT Assistant training pipeline )
  • 网络如何发送一个数据包
  • 【Harmony OS 4.0】向上滑动加载案例
  • SQL基础教程(八)SQL高级处理
  • [论文笔记] Data-Juicer: A One-Stop Data Processing System for Large Language Models
  • 期末速成复习资料——操作系统
  • Android之Service与IntentService区别
  • 【MySQL】表的设计
  • NC 用两个栈实现队列
  • 用后端实现一个简单的登录模块2 前端页面
  • MySQL慢查询的查找语法
  • SQL中的聚合方法与Pandas的对应关系
  • 计算机毕业设计选题推荐-计算中心高性能集群共享平台-Java/Python项目实战
  • 仿RabbitMq实现简易消息队列基础篇(future操作实现异步线程池)
  • 经典算法题总结:数组常用技巧(双指针,二分查找和位运算)篇
  • 版本控制基础理论
  • 微分方程(Blanchard Differential Equations 4th)中文版Section1.4
  • 求职Leetcode算法题(7)
  • ActiveMQ、RabbitMQ、Kafka、RocketMQ在事务性消息、性能、高可用和容错、定时消息、负载均衡、刷盘策略的区别
  • HanLP分词的使用与注意事项
  • Python 的进程、线程、协程的区别和联系是什么?
  • 实时数据推送:Spring Boot 中两种 SSE 实战方案
  • 数据守护者:SQL一致性检查的艺术与实践
  • jenkins配置+vue打包多环境切换