【C#源码】ModbusRTU和ModbusTCP扩展类库代码CSharp标准MdobusRTU/ModbusTCP

原创 Yearn  2020-09-09 09:51:41  阅读 725 次 评论 0 条

本源码已封装好 ModbusTCP 和 ModbusRTU 两部分通讯代码,可以满足标准的ModbusRTU和TCP的读写需求


ModbusRTU 是通过串口进行通讯.

ModbusTCP 是通过网络进行通讯.


支持的功能码如下

HEX 功能码功能说明
0x01读线圈寄存器
0x02读离散输入寄存器
0x03读保持寄存器
0x04读模拟量输入寄存器
0x05写单个线圈寄存器
0x06写单个保持寄存器
0x0F写多个线圈寄存器
0x10写多个保持寄存器


Demo 示例图片


【C#源码】ModbusRTU和ModbusTCP扩展类库代码CSharp标准MdobusRTU/ModbusTCP


【C#源码】ModbusRTU和ModbusTCP扩展类库代码CSharp标准MdobusRTU/ModbusTCP


【C#源码】ModbusRTU和ModbusTCP扩展类库代码CSharp标准MdobusRTU/ModbusTCP


Modbus Demo 调用演示代码

using System;
using System.Windows.Forms;

namespace ModbusEx
{
    public partial class MainForm : Form
    {
        ModbusMaster.RTU modbusRtu = new ModbusMaster.RTU();
        ModbusMaster.TCP modbusTcp = new ModbusMaster.TCP();
        byte SlaveAddress = 1; //从机地址
        
        public MainForm()
        {
            InitializeComponent();
        }
        void Button1Click(object sender, EventArgs e)
        {
            modbusRtu.OpenPort(textBox1.Text,Convert.ToInt32(textBox2.Text),System.IO.Ports.Parity.None,8,System.IO.Ports.StopBits.One);
        }
        void Button2Click(object sender, EventArgs e)
        {
            modbusRtu.Write0x10(SlaveAddress,0,new long[] {100,200,102,103});
        }
        void Button3Click(object sender, EventArgs e)
        {
            long[] value = new long[10];
            if (modbusRtu.Read0x03(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("*********** long ************");
                foreach (long element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("\n*********** short ************");
                foreach (short element in ModbusMaster.auxFunction.longToShort(value)) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
        }
        void Button4Click(object sender, EventArgs e)
        {
            modbusRtu.ClosePort();
        }
        void Button5Click(object sender, EventArgs e)
        {
            modbusRtu.Write0x06(SlaveAddress,0,100);
        }
        
        void Button7Click(object sender, EventArgs e)
        {
            bool[] value = new bool[10];
            if ( modbusRtu.Read0x01(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("");
                foreach (bool element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
            }
        }
        void Button8Click(object sender, EventArgs e)
        {
            bool[] value = new bool[10];
            if (modbusRtu.Read0x02(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("");
                foreach (bool element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
        }
        void Button9Click(object sender, EventArgs e)
        {
            bool[] write = {true,false,false,false,true,false,true,false,false,true};
            modbusRtu.Write0x0F(SlaveAddress,0,write);
        }
        void Button10Click(object sender, EventArgs e)
        {
            long[] value = new long[10];
            if (modbusRtu.Read0x04(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("*********** long ************");
                foreach (long element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("\n*********** short ************");
                foreach (short element in ModbusMaster.auxFunction.longToShort(value)) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
        }
        void Button11Click(object sender, EventArgs e)
        {
            modbusRtu.Write0x05(SlaveAddress,2,true);
        }
        void Button12Click(object sender, EventArgs e)
        {
            modbusTcp.ConnSlaveASync(textBox3.Text,Convert.ToInt32(textBox4.Text));
        }
        void Button13Click(object sender, EventArgs e)
        {
            modbusTcp.CloseSlave();
        }
        void Button14Click(object sender, EventArgs e)
        {
            bool[] value = new bool[10];
            if (modbusTcp.Read0x01(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("");
                foreach (bool element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
        }
        void Button15Click(object sender, EventArgs e)
        {
            bool[] value = new bool[10];
            if (modbusTcp.Read0x02(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("");
                foreach (bool element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
        }
        void Button16Click(object sender, EventArgs e)
        {
            long[] value = new long[10];
            if (modbusTcp.Read0x03(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("*********** long ************");
                foreach (long element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("\n*********** short ************");
                foreach (short element in ModbusMaster.auxFunction.longToShort(value)) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
        }
        void Button17Click(object sender, EventArgs e)
        {
            long[] value = new long[10];
            if (modbusTcp.Read0x04(SlaveAddress,0,ref value)) {
                System.Diagnostics.Debug.WriteLine("*********** long ************");
                foreach (long element in value) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("\n*********** short ************");
                foreach (short element in ModbusMaster.auxFunction.longToShort(value)) {
                    System.Diagnostics.Debug.Write(element);
                    System.Diagnostics.Debug.Write("\t");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
        }
        void Button18Click(object sender, EventArgs e)
        {
            modbusTcp.Write0x05(SlaveAddress,1,true);
        }
        void Button19Click(object sender, EventArgs e)
        {
            modbusTcp.Write0x06(SlaveAddress,2,32768);
        }
        void Button20Click(object sender, EventArgs e)
        {
            bool[] write = {false,true,false,false,true,false,true,false,false,true};
            modbusTcp.Write0x0F(SlaveAddress,0,write);
        }
        void Button21Click(object sender, EventArgs e)
        {
            modbusTcp.Write0x10(SlaveAddress,0,new long[] {-25,-3275,102,103,0,104,105,106});
        }
        void MainFormLoad(object sender, EventArgs e)
        {
            
        }
    }
}

Modbus 类库全部可用函数的注释文档

<?xml version="1.0"?>
<doc>
    <assembly>
        <name>ModbusMaster</name>
    </assembly>
    <members>
        <member name="T:ModbusMaster.auxFunction">
            <summary>
            Modbus 辅助类
            </summary>
        </member>
        <member name="M:ModbusMaster.auxFunction.byteArrayToHex(System.Byte[])">
            <summary>
            字节数组到十六进制
            </summary>
            <param name="arryByte">字节数组</param>
            <returns>成功返回十六进制字符串,失败返回 null</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.byteToHex(System.Byte)">
            <summary>
            字节到十六进制
            </summary>
            <param name="pByte">字节数值</param>
            <returns>成功返回十六进制字符串,失败返回 null</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.HexToByteArray(System.String)">
            <summary>
            十六进制到字节数组
            </summary>
            <param name="hexText">十六进制字符串</param>
            <returns>成功返回字节数组,失败返回长度为 0 的字节数组</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.HexToLong(System.String)">
            <summary>
            十六进制到 long
            </summary>
            <param name="hexText">十六进制字符串</param>
            <returns>成功回long数值,失败返回 0</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.longToHex(System.Int64)">
            <summary>
            long 到十六进制
            </summary>
            <param name="pLong">数值</param>
            <returns>成功返回十六进制字符串, 失败返回 null</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.longToHex(System.Int64,System.UInt32)">
            <summary>
            long 到十六进制
            </summary>
            <param name="pLong">数值</param>
            <param name="len">指定返回的十六进制字符串的长度</param>
            <returns>成功返回十六进制字符串, 失败返回 null</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.GetByteArrayMiddle(System.Byte[],System.Int32,System.Int32)">
            <summary>
            取字节中间
            </summary>
            <param name="lpByte">欲操作的字节数组</param>
            <param name="lpStartIndex">起始索引 0 开始</param>
            <param name="lpCount">取出数量</param>
            <returns>返回取出的结果数组</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.GetByteArrayLeft(System.Byte[],System.Int32)">
            <summary>
            取字节左边
            </summary>
            <param name="lpByte">欲操作的字节数组</param>
            <param name="lpCount">取出数量</param>
            <returns>返回取出的结果数组</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.longToShort(System.Int64[])">
            <summary>
            把读取到的 long 类型数据转换到 short 类型
            </summary>
            <param name="values">long 数组</param>
            <returns>返回转换的数组</returns>
        </member>
        <member name="M:ModbusMaster.auxFunction.longToShort(System.Int64)">
            <summary>
            把读取到的 long 类型数据转换到 short 类型
            </summary>
            <param name="values">long 数值</param>
            <returns>返回转换的数值</returns>
        </member>
        <member name="T:ModbusMaster.RTU">
            <summary>
            Modbus-RTU 扩展类
            </summary>
        </member>
        <member name="F:ModbusMaster.RTU.SerialPort1">
            <summary>
            串口通信组件
            </summary>
        </member>
        <member name="F:ModbusMaster.RTU.ReadTimeout">
            <summary>
            读取超时时间
            </summary>
        </member>
        <member name="F:ModbusMaster.RTU.errorStatusMessage">
            <summary>
            最后的错误提示消息
            </summary>
        </member>
        <member name="M:ModbusMaster.RTU.#ctor">
            <summary>
            实例化 Modbus-RTU 操作类
            </summary>
        </member>
        <member name="M:ModbusMaster.RTU.SetDataReadTimeout(System.Int32)">
            <summary>
            读取超时时间, 如果读取的数据比较多, 请适当的把超时时间加大, 否则通讯可能会存在问题
            </summary>
            <param name="Timeout">数据读取超时时间,不能太小否则可能读取不到数据, 单位/毫秒, 默认:500ms</param>
        </member>
        <member name="M:ModbusMaster.RTU.OpenPort(System.String,System.Int32,System.IO.Ports.Parity,System.Int32,System.IO.Ports.StopBits)">
            <summary>
            打开串口
            </summary>
            <param name="portName">端口名称</param>
            <param name="baudRate">波特率</param>
            <param name="parity">校验位</param>
            <param name="databits">数据位</param>
            <param name="stopBits">停止位</param>
            <returns>打开成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.ClosePort">
            <summary>
            关闭串口
            </summary>
            <returns>成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.ReadDateToEnd">
            <summary>
            读取串口缓冲区全部数据
            </summary>
            <returns>成功返回读取到的数据,否则返回长度为 0 的字节数组</returns>
        </member>
        <member name="M:ModbusMaster.RTU.ReadDate(System.Int32,System.Int32)">
            <summary>
            读取串口缓冲区指定字节数量的数据, 返回字节数组
            </summary>
            <param name="byteCount">读取字节数</param>
            <param name="timeOut">读取超时时间</param>
            <returns>成功返回读取到的数据,否则返回长度为 0 的字节数组</returns>
        </member>
        <member name="M:ModbusMaster.RTU.ReadDateText(System.Int32,System.Int32)">
            <summary>
            读取串口缓冲区指定字节数量的数据, 返回十六进制文本
            </summary>
            <param name="byteCount">读取字节数</param>
            <param name="timeOut">读取超时时间</param>
            <returns>成功返回读取到的数据,否则返回 null</returns>
        </member>
        <member name="M:ModbusMaster.RTU.WriteLine(System.String)">
            <summary>
            写行数据 string
            </summary>
            <param name="data">数据</param>
            <returns>写入成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Write(System.String)">
            <summary>
            写数据 String
            </summary>
            <param name="data">数据</param>
            <returns>写入成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Write(System.Byte[],System.Int32,System.Int32)">
            <summary>
            写数据 Byte[]
            </summary>
            <param name="buffer">数据</param>
            <param name="offset">起始偏移位置</param>
            <param name="count">偏移后发送的数据长度</param>
            <returns>写入成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.ModbusWrite(System.String)">
            <summary>
            Modbus 写数据
            </summary>
            <param name="data">modbus 数据</param>
            <returns>写入成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.EmptyInputBuffer">
            <summary>
            清空输入缓冲区,每次执行 Read0x*/Write0x* 指令之前会自动清除
            </summary>
            <returns></returns>
        </member>
        <member name="M:ModbusMaster.RTU.EmptyOutputBuffer">
            <summary>
            清空输出缓冲区,每次执行 Read0x*/Write0x* 指令之前会自动清除
            </summary>
            <returns></returns>
        </member>
        <member name="M:ModbusMaster.RTU.caclCRC(System.String)">
            <summary>
            计算 Moudbus CRC 校验码
            </summary>
            <param name="data">十六进制 Modbus 协议字符串</param>
            <returns>成功返回校验码,失败返回 null</returns>
        </member>
        <member name="M:ModbusMaster.RTU.checkCRC(System.String)">
            <summary>
            检查消息CRC是否正确
            </summary>
            <param name="data">十六进制 Modbus 协议字符串</param>
            <returns>正确返回 true ,否则返回 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Read0x01(System.Byte,System.UInt16,System.Boolean[]@)">
            <summary>
            读线圈寄存器,功能码 0x01
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回线圈寄存器的值,线圈寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Read0x02(System.Byte,System.UInt16,System.Boolean[]@)">
            <summary>
            读离散输入寄存器,功能码 0x02
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回离散寄存器的值,离散寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Read0x03(System.Byte,System.UInt16,System.Int64[]@)">
            <summary>
            读保持寄存器,功能码 0x03
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回保持寄存器的值,寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Read0x04(System.Byte,System.UInt16,System.Int64[]@)">
            <summary>
            读模拟量输入寄存器,功能码 0x04
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回模拟量寄存器的值,模拟量寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Write0x05(System.Byte,System.UInt16,System.Boolean)">
            <summary>
            写单个线圈寄存器,功能码 0x05
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">写入寄存器的值</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Write0x06(System.Byte,System.UInt16,System.Int64)">
            <summary>
            写单个保持寄存器,功能码 0x06
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="value">写入寄存器的值</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Write0x0F(System.Byte,System.UInt16,System.Boolean[])">
            <summary>
            写多个线圈寄存器,功能码 0xOF
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">写入寄存器的值,线圈寄存器数量由此数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.RTU.Write0x10(System.Byte,System.UInt16,System.Int64[])">
            <summary>
            写多个保持寄存器,功能码 0x10
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">写入寄存器的值,保持寄存器数量由此数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="T:ModbusMaster.TCP">
            <summary>
            Modbus-TCP 扩展类
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.connSlaveStatus">
            <summary>
            从机连接状态
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP._ip">
            <summary>
            从机 IP
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP._port">
            <summary>
            从机 Port
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.recThread">
            <summary>
            Socket 接收线程
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.recByte">
            <summary>
            Socket 接收缓冲区
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.socketClient">
            <summary>
            Socket 客户端组件
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.mbapHeaderN">
            <summary>
            MBAP Header 6 - 2 byte
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.ReadTimeout">
            <summary>
            读取超时时间
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.errorStatusMessage">
            <summary>
            最后的错误提示消息
            </summary>
        </member>
        <member name="M:ModbusMaster.TCP.#ctor">
            <summary>
            实例化 Modbus-TCP 操作类, 事务标识头默认: 0x01 0x01
            </summary>
        </member>
        <member name="M:ModbusMaster.TCP.#ctor(System.Byte,System.Byte)">
            <summary>
            实例化 Modbus-TCP 操作类
            </summary>
            <param name="reqTagHi">事务标识头 高位, 默认: 0x01</param>
            <param name="reqTagLo">事务标识头 低位, 默认: 0x01</param>
        </member>
        <member name="M:ModbusMaster.TCP.SetDataReadTimeout(System.Int32)">
            <summary>
            读取超时时间, 如果读取的数据比较多, 请适当的把超时时间加大, 否则通讯可能会存在问题
            </summary>
            <param name="Timeout">数据读取超时时间,不能太小否则可能读取不到数据, 单位/毫秒, 默认:500ms</param>
        </member>
        <member name="M:ModbusMaster.TCP.ConnSlaveSync(System.String,System.Int32)">
            <summary>
            连接 Modubus TCP 从机,同步模式:直到连接处理完毕后才会返回,连接过程中会卡 UI 几秒或者几十秒
            </summary>
            <param name="ip">ip地址</param>
            <param name="port">端口</param>
            <returns>返回连接状态</returns>
        </member>
        <member name="M:ModbusMaster.TCP.ConnSlaveASync(System.String,System.Int32)">
            <summary>
            连接 Modubus TCP 从机,异步模式:执行连接后立即返回,连接过程中不会卡 UI ,需要自己读取属性(connStatus)判断连接状态
            </summary>
            <param name="ip">ip地址</param>
            <param name="port">端口</param>
        </member>
        <member name="M:ModbusMaster.TCP.ConnSlave">
            <summary>
            连接 Modubus TCP 从机
            </summary>
        </member>
        <member name="M:ModbusMaster.TCP.CloseSlave">
            <summary>
            关闭 Modbus TCP 从机
            </summary>
            <returns>关闭成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.socketRecData">
            <summary>
            接收 TCP 从机数据
            </summary>
        </member>
        <member name="M:ModbusMaster.TCP.checkMBAP(System.Byte[])">
            <summary>
            校验 Modbus 事务标识头
            </summary>
            <param name="data">消息</param>
            <returns>成功返回 true , 失败返回 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.EmptyRecBuffer">
            <summary>
            清空接收缓冲区
            </summary>
            <returns></returns>
        </member>
        <member name="M:ModbusMaster.TCP.ModbusWrite(System.String)">
            <summary>
            Modbus 写数据
            </summary>
            <param name="data">十六进制字符串数据</param>
            <returns>写入成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Write(System.String)">
            <summary>
            写数据
            </summary>
            <param name="data">数据</param>
            <returns>写入成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.ReadDateToEnd">
            <summary>
            读取TCP缓冲区全部数据
            </summary>
            <returns></returns>
        </member>
        <member name="M:ModbusMaster.TCP.ReadDate(System.Int32,System.Int32)">
            <summary>
            读取TCP缓冲区指定字节数量的数据
            </summary>
            <param name="byteCount">读取字节数</param>
            <param name="timeOut">读取超时时间</param>
            <returns>成功返回读取到的数据,否则返回长度为 0 的字节数组</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Read0x01(System.Byte,System.UInt16,System.Boolean[]@)">
            <summary>
            读线圈寄存器,功能码 0x01
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回线圈寄存器的值,线圈寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Read0x02(System.Byte,System.UInt16,System.Boolean[]@)">
            <summary>
            读离散量输入,功能码 0x02
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回离散寄存器的值,离散寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Read0x03(System.Byte,System.UInt16,System.Int64[]@)">
            <summary>
            读保持寄存器,功能码 0x03
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回保持寄存器的值,寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Read0x04(System.Byte,System.UInt16,System.Int64[]@)">
            <summary>
            读模拟量输入寄存器,功能码 0x04
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">返回模拟量寄存器的值,模拟量寄存器数量由此数组初始化数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Write0x05(System.Byte,System.UInt16,System.Boolean)">
            <summary>
            写单个线圈寄存器,功能码 0x05
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="value">写入寄存器的值</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Write0x06(System.Byte,System.UInt16,System.Int64)">
            <summary>
            写单个保持寄存器,功能码 0x06
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="value">写入寄存器的值</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Write0x0F(System.Byte,System.UInt16,System.Boolean[])">
            <summary>
            写多个线圈寄存器,功能码 0xOF/15
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">写入寄存器的值,线圈寄存器数量由此数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="M:ModbusMaster.TCP.Write0x10(System.Byte,System.UInt16,System.Int64[])">
            <summary>
            写多个保持寄存器,功能码 0x10
            </summary>
            <param name="address">站号</param>
            <param name="start">寄存器起始地址</param>
            <param name="values">写入寄存器的值,保持寄存器数量由此数组长度决定</param>
            <returns>执行成功返回 true 否则 false</returns>
        </member>
        <member name="P:ModbusMaster.TCP.connStatus">
            <summary>
            从机连接状态
            </summary>
        </member>
        <member name="T:ModbusMaster.TCP.ConnStatus">
            <summary>
            连接状态
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.ConnStatus.Connecting">
            <summary>
            正在连接
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.ConnStatus.Success">
            <summary>
            连接成功
            </summary>
        </member>
        <member name="F:ModbusMaster.TCP.ConnStatus.Fail">
            <summary>
            连接失败
            </summary>
        </member>
    </members>
</doc>


有兴趣的话可以到博主淘宝购买此套源代码https://lovecxu.taobao.com/

打赏
本文地址:https://www.yfyun.xin/index.php/post/37.html
版权声明:本文为原创文章,版权归 Yearn 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?