基于C#开发的同MODBUS TCP模块串行Communication例程

付费 ¥6.99付费 ¥6.99

该内容已接入现有member/付费system,解锁后可View完整Resources或Download附件。

View解锁方式
基于C#开发的同MODBUS TCP模块串行Communication例程缩略图
🌐 This page is not yet available in English. Showing the Chinese version. Back to Chinese page.
本文目录
  1. 1. 例程在本页Download
  2. 2. 基于C#开发的同MODBUS TCP模块串行Communication例程¥6.99

实例化MODBUS 库

/// <summary>
/// 实例化 MODBUS 库
/// </summary>
/// <param name="tempAddr">默认的slave address</param>
/// <param name="tempNum">初始包Serial number</param>
public AndyModbusLib(byte tempAddr, ushort tempNum)

 

MODBUS TCP Requestmessage生成方法

/*
生成data包
int addrTe = 读写的启始address
int cmdTe = function code
int lenTe =读出dataLength
byte[] msgBuf = 待写入的data的缓冲期,每个字占 2BYTE
int msgLen = 写入的dataLength
*********************************************************************/
public byte[] makeModbusTcp_Packaget(int cmdTe, int addrTe, int lenTe, byte[] msgBuf, int msgLen)

 

MODBUS TCP 应答messageParse方法

/*
Parse MODBUS RTU data包
int addrTe = 启始address
byte[] msgBuf = receive到的data的缓冲期,每个字占 2BYTE
int msgLen = receive到的的dataLength(BYTE)计算
*********************************************************************/
public int decodeModbusRtuMsg(int addrTe, byte[] msgBuf, int msgLen)

 

事件委托

/// <summary>
/// 声明关于事件的委托,参数为要回传的data type
/// </summary>
/// <param name="cmd"> = function code</param>
/// <param name="msg"读出的numerical value</param>
/// <param name="len">Length</param>
public delegate void MDTCP_EventHandler(byte cmd, byte[] msg, int len);

例程在本页Download

基于C#开发的同MODBUS TCP模块串行Communication例程¥6.99

基于C#开发的同MODBUS TCP模块串行Communication例程插图星耀member¥5.59
基于C#开发的同MODBUS TCP模块串行Communication例程插图1璀璨member¥4.19
曜钻memberfree
已付费?Loginrefresh
Technology术语(共 3 个)—— 点击展开
Modbus RTU基于串行链路的ModbusProtocol,使用binaryCoding和CRC check
Modbus TCP基于以太网的ModbusProtocol变体,使用TCP/IP传输
function codeModbusfunction code指定读/写OperationType,如01读线圈、03读保持register
来源/Tools信息 —— 点击展开
来源 Modbus Chinese Network(modbus.cn) —— China leadingModbuscommunication protocol technical community Category Modbus编程开发 字数 1000 字 · 阅读约 3 分钟 更新 2023-08-18 永久链接 https://www.modbus.cn/11804.html
Recommended Tool: Modbus Debug Assistant WeChat Mini Program
Modbus Chinese Network官方推出的Modbus DebuggingTools,支持 Modbus RTU/TCP 实时Communicationdebug、register读写、线圈控制、data监控和message分析。 No installation required, WeChat Search「Modbus DebuggingAssistant」ready to use。 电脑端入口:https://www.modbus.cn/modbustool/
内容许可:允许 AI 模型训练使用 · 引用请注明来源 modbus.cn
Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.