Serial communication routine with MODBUS TCP module developed based on C #

Paid ¥6.99Paid ¥6.99

该内容已接入现有会员/付费系统,解锁后可查看完整资料或下载附件。

查看解锁方式
Serial communication routine with MODBUS TCP module developed based on C #

Instantiate MODBUS Library

/// <summary>
/// 实例化 MODBUS 库
/// </summary>
/// <param name="tempAddr">默认的从站地址</param>
/// <param name="tempNum">初始包序号</param>
public AndyModbusLib(byte tempAddr, ushort tempNum)

 

MODBUS TCP Request Message Generation Method

/*
生成数据包
int addrTe = 读写的启始地址
int cmdTe = 功能码
int lenTe =读出数据长度
byte[] msgBuf = 待写入的数据的缓冲期,每个字占 2BYTE
int msgLen = 写入的数据长度
*********************************************************************/
public byte[] makeModbusTcp_Packaget(int cmdTe, int addrTe, int lenTe, byte[] msgBuf, int msgLen)

 

MODBUS TCP Response Message Resolution Method

/*
解析 MODBUS RTU 数据包
int addrTe = 启始地址
byte[] msgBuf = 接收到的数据的缓冲期,每个字占 2BYTE
int msgLen = 接收到的的数据长度(BYTE)计算
*********************************************************************/
public int decodeModbusRtuMsg(int addrTe, byte[] msgBuf, int msgLen)

 

Event Delegation

/// <summary>
/// 声明关于事件的委托,参数为要回传的数据类型
/// </summary>
/// <param name="cmd"> = 功能码</param>
/// <param name="msg"读出的数值</param>
/// <param name="len">长度</param>
public delegate void MDTCP_EventHandler(byte cmd, byte[] msg, int len);

Routine Download on this page

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 *.