首先添加引用 三菱PLCdll文件
1、导入 命名空间:
using HslCommunication.Profinet.Melsec;
2、声明一个PLC对象:
private MelsecMcNet melsecMcNet = null;
3、读取PLC地址值
///
/// 读取bool值
///
/// PLC地址:如M100,X100,Y100,B100
///
public bool ReadBool(string str_Add)
{
OperateResult rt = this.melsecMcNet.ReadBool(str_Add);
if (rt.IsSuccess)
return rt.Content;
else
return false;
}
///
/// 读取short值
///
/// PLC地址:如D100,W100,R100
///
public int ReadInt16(string str_Add)
{
OperateResult rt = melsecMcNet.ReadInt16(str_Add);
if (rt.IsSuccess)
{
return rt.Content;
}
else
{
return 0;
}
}
///
/// 读取ushort值
///
/// PLC地址:如D100,W100,R100
///
public int ReadUInt16(string str_Add)
{
OperateResult rt = melsecMcNet.ReadUInt16(str_Add);
if (rt.IsSuccess)
{
return rt.Content;
}
else
{
return 0;
}
}
///
/// 读取int值
///
/// PLC地址:如D100,W100,R100
///
public int ReadInt32(string str_Add)
{
OperateResult rt = melsecMcNet.ReadInt32(str_Add);
if (rt.IsSuccess)
return rt.Content;
else
return 0;
}
///
/// 读取uint值
///
/// PLC地址:如D100,W100,R100
///
public int ReadUInt32(string str_Add)
{
OperateResult rt = melsecMcNet.ReadUInt32(str_Add);
if (rt.IsSuccess)
return (int)rt.Content;
else
return 0;
}
///
/// 读取float值
///
/// PLC地址:如D100,W100,R100
///
public float ReadFloat(string str_Add)
{
OperateResult rt = melsecMcNet.ReadFloat(str_Add);
if (rt.IsSuccess)
return rt.Content;
else
return 0;
}
///
/// 读取double值
///
/// PLC地址:如D100,W100,R100
///
public double ReadDouble(string str_Add)
{
OperateResult rt = melsecMcNet.ReadDouble(str_Add);
if (rt.IsSuccess)
return rt.Content;
else
return 0;
}

    /// <summary>/// 读取多个连续的bool值/// </summary>/// <param name="str_Add">PLC地址:如M100,X100,Y100,B100</param>/// <param name="length">地址个数</param>/// <returns></returns>public bool[] ReadBool(string str_Add, ushort length){OperateResult<bool[]> rt = this.melsecMcNet.ReadBool(str_Add, length);if (rt.IsSuccess)            return rt.Content;            else            return null;            }/// <summary>/// 读取short值/// </summary>/// <param name="str_Add">PLC地址:如D100,W100,R100</param>/// <param name="length">地址个数</param> /// <returns></returns>public short[] ReadInt16(string str_Add, ushort length){OperateResult<short[]> rt = melsecMcNet.ReadInt16(str_Add, length);if (rt.IsSuccess)            return rt.Content;            else           return null;        }/// <summary>/// 读取ushort值/// </summary>/// <param name="str_Add">PLC地址:如D100,W100,R100</param>/// <param name="length">地址个数</param>/// <returns></returns>public ushort[] ReadUInt16(string str_Add, ushort length){OperateResult<ushort[]> rt = melsecMcNet.ReadUInt16(str_Add, length);if (rt.IsSuccess)         return rt.Content;          else           return null;            }/// <summary>/// 读取int值/// </summary>/// <param name="str_Add">PLC地址:如D100,W100,R100</param>/// <param name="length">地址个数</param>/// <returns></returns>public int[] ReadInt32(string str_Add, ushort length){OperateResult<int[]> rt = melsecMcNet.ReadInt32(str_Add, length);if (rt.IsSuccess)            return rt.Content;        else          return null;         }/// <summary>/// 读取uint值/// </summary>/// <param name="str_Add">PLC地址:如D100,W100,R100</param>/// <param name="length">地址个数</param>/// <returns></returns>public uint[] ReadUInt32(string str_Add, ushort length){OperateResult<uint[]> rt = melsecMcNet.ReadUInt32(str_Add, length);if (rt.IsSuccess)           return rt.Content;           else            return null;            }/// <summary>///  读取float值/// </summary>/// <param name="str_Add">PLC地址:如D100,W100,R100</param>/// <param name="length">地址个数</param>/// <returns></returns>public float[] ReadFloat(string str_Add, ushort length){OperateResult<float[]> rt = melsecMcNet.ReadFloat(str_Add, length);if (rt.IsSuccess)           return rt.Content;          else           return null;            }/// <summary>///  读取double值/// </summary>/// <param name="str_Add">PLC地址:如D100,W100,R100</param>/// <param name="length">地址个数</param>/// <returns></returns>public double[] ReadDouble(string str_Add, ushort length){OperateResult<double[]> rt = melsecMcNet.ReadDouble(str_Add, length);if (rt.IsSuccess)          return rt.Content;          else           return null;           }/// <summary>/// 读取string值/// </summary>/// <param name="str_Add">PLC地址:如D100,W100,R100</param>/// <param name="length">地址个数</param>/// <returns></returns>public string ReadString(string str_Add, ushort length){OperateResult<string> rt = melsecMcNet.ReadString(str_Add, length);if (rt.IsSuccess)            return rt.Content;           else            return string.Empty;           }

4、写入PLC地址值
///
/// 写入单个bool数据
///
///
///
///
public bool WriteBool(string str_Add,bool data)
{
OperateResult rt= melsecMcNet.Write(str_Add, data);
if(!rt.IsSuccess)
return false;
return true;
}
///
/// 写入单个ushort数据
///
///
///
///
public bool WriteUInt16(string str_Add, ushort data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 写入单个short数据
///
///
///
///
public bool WriteInt16(string str_Add, short data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 写入单个uint数据
///
///
///
///
public bool WriteUInt32(string str_Add, uint data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 写入单个int数据
///
///
///
///
public bool WriteInt32(string str_Add, int data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 写入单个float数据
///
///
///
///
public bool WriteFloat(string str_Add, float data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 写入单个double数据
///
///
///
///
public bool WriteDouble(string str_Add, double data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 写入字符串
///
///
///
///
public bool WriteString(string str_Add, string data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 连续写入多个bool数据
///
///
///
///
public bool WriteBool(string str_Add, bool[] data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 连续写入多个ushort数据
///
///
///
///
public bool WriteUInt16(string str_Add, ushort[] data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 连续写入多个short数据
///
///
///
///
public bool WriteInt16(string str_Add, short[] data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 连续写入多个uint数据
///
///
///
///
public bool WriteUInt32(string str_Add, uint[] data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 连续写入多个int数据
///
///
///
///
public bool WriteInt32(string str_Add, int[] data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 连续写入多个float数据
///
///
///
///
public bool WriteFloat(string str_Add, float[] data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}
///
/// 连续写入多个double数据
///
///
///
///
public bool WriteDouble(string str_Add, double[] data)
{
OperateResult rt = melsecMcNet.Write(str_Add, data);
if (!rt.IsSuccess)
return false;
return true;
}

在C#程序中三菱PLC读写数据相关推荐

  1. 三菱Plc怎么用c语言编程,如何用程序在三菱PLC上写出配方功能

    如何用程序在三菱PLC上写出配方功能 2018年09月26日 09:05:25来源:今日头条作者:永战胜关键词:PLC编程器 有许多机器客户都要求可以出产多种类型的产品,这些产品工艺相同,仅仅相应的数 ...

  2. 小程序中神秘的用户数据

    前面 上一篇文章手把手教会你小程序登录鉴权介绍了小程序如何进行登录鉴权,那么一般小程序的用户标识可以使用上文所述微信提供的jscode2session接口来换取,小程序还提供了一个getUserInf ...

  3. python通过opc读plc实例_OPC通讯实例(C#通过OPC连接PLC读写数据)

    [实例简介]C#通过OPC连接PLC读写数据 [实例截图] [核心代码] using System; using System.Collections.Generic; using System.Co ...

  4. 如何把三菱plc的数据导入mysql_三菱plc数据采集储存 plc数据采集并存入数据库

    三菱PLC如何用于数据采集? 现在三菱PLC技术越来越强,其数据存储面积越来越大,可以存储大量的数据,具有很大的应用空间.数据采集可以用计数器记录采集到的脉冲数,并定期传送到DM区.A/D单元也可用于 ...

  5. python 三菱plc读写_小说python操作PLC

    PLC(Programmable Logic Controller)可编程逻辑控制器,可以理解为一个微型计算机,广泛应用于工业控制中,如楼宇智控.精密机床.汽车电子等等. 随着物联网的兴起,越来越多的 ...

  6. 在Dephi中使用TStream读写数据的技巧

    在Dephi中提供了一个抽象的数据类型TStream来支持对流式数据的操作.这些数据通常来自文件.数据库.内存对象.OLE对象等,TStream提供了统一.简洁的方法来进行数据的读写.在通常情况下,我 ...

  7. linux sd卡中文件多时读写,数据存储与访问之——文件存储读写

    1.Android文件的操作模式 在java中要想对文件做读写操作,只需创建 文件,读写数据即可,Android却是不同,android基于Linux,在读写文件的时候,还需要加上文件的操作模式. 文 ...

  8. 小程序中实现获取全部数据

    日常在开发小程序的时候,我们的后端服务可以采用云开发的模式,但是云开发限制每次最多获取100条的数据,如果我们需要获取全部数据,必须自己构造后端服务.本篇我们介绍一下如何获取全部数据. 定义api 微 ...

  9. python开发的程序中以电子表格显示数据_使用 Python 读取电子表格中的数据实例详解...

    Python 是最流行.功能最强大的编程语言之一.由于它是自由开源的,因此每个人都可以使用.大多数 Fedora 系统都已安装了该语言.Python 可用于多种任务,其中包括处理逗号分隔值(CSV)数 ...

最新文章

  1. ygm900常用网站
  2. 教学思路SQL之预备课程学习 建库、建表、建约束、关系、部分T-sql语句
  3. 深度优先遍历 java
  4. SSM整合框架实现发送邮件功能
  5. 软件測试之独步武林系列(一)
  6. 后台产品的基石:权限管理体系设计
  7. url 编码 js url传参中文乱码解决方案
  8. HTML+CSS 整站 步骤
  9. 内存:DDR2与DDR
  10. java寻路算法_具有指定距离/节点数的寻路算法
  11. 获取所有股票历史数据存到Excel
  12. 命里有时终须有,命里无时莫强求
  13. 使用OpenSSL库函数测试AES-CCM加密算法
  14. Leetcode 5855 数组第K大的整数
  15. 【verbs】ibv_create_cq()
  16. 远程调用报错java.net.UnknownHostException 解决方法
  17. 我的第一个油猴脚本--微博超话自动签到
  18. 关于MySql的Unhandled异常
  19. 2019.7学习总结-目标检测-Python+pytorch
  20. 计算机快捷方式在哪儿,Windows电脑计算器快捷键在哪里打开及敬业签云便签在线计算器怎么使用...

热门文章

  1. ABCNet 精读:使用自适应贝塞尔曲线网络进行进行实时场景文本定位 OCR 文本定位 文本检测 CVPR
  2. 实现和IE浏览器交互的几种方法
  3. 了最新最全的网站收录地址搜索引擎网址提交及站长工具
  4. CSDN_获取积分制
  5. 摩尔庄园卷土重来,能否带来新的“快乐童年”?
  6. C语言/关于字符串逆序存储
  7. mahout 推荐算法 java_Mahout之推荐算法基本实例
  8. 基于PCI9054和LTC4240的CPCI总线接口设计
  9. python怎么更新setuptools_linux 升级python2.7 安装setuptools
  10. 【案例练习】15—27个网页设计的 HTML 时间线