int CCjModbusTcp::makeSendFrame( const CFrameModbusPdu* pdu,CFrameModbus* frame ) { CFrameModbusTcp* pFrame = (CFrameModbusTcp*)frame; // 处理报文头 //ztn 20161019 mod if(m_falg_mbap_transId == MBAP_TRANSID_DEFAULT) { if( pFrame->getTransId()==0xFF ) pFrame->getTransId() = 0; else pFrame->getTransId() = pFrame->getTransId()+1; } else pFrame->getTransId() = m_falg_mbap_transId; if( m_falg_mbap_protocolId == MBAP_PROTOCOLID_DEFAULT) pFrame->getProtocolId() = 0; else pFrame->getProtocolId() = m_falg_mbap_protocolId; pFrame->getUnitId() = address(); pFrame->pdu() = *pdu; return 0; } extern "C" CProtocolBase* CreateProtocolOf124() { cout <<"create protocol of 124 cj modbus tcp"<<endl; return new CCjModbusTcp; }

时间: 2024-04-06 08:31:19 浏览: 15
这段代码是一个名为 CCjModbusTcp 的类中的 makeSendFrame 函数和一个名为 CreateProtocolOf124 的函数。makeSendFrame 函数接受两个参数:一个 CFrameModbusPdu 类型的指针 pdu,和一个 CFrameModbus 类型的指针 frame。函数的作用是构造一个 Modbus TCP 帧的发送帧。首先将 frame 转换成 CFrameModbusTcp 类型的指针 pFrame。然后根据 m_falg_mbap_transId 和 m_falg_mbap_protocolId 的值,处理报文头的传输标识和协议标识。如果 m_falg_mbap_transId 的值为 MBAP_TRANSID_DEFAULT,则将 pFrame 的传输标识设置为 0 或者加 1;否则将 pFrame 的传输标识设置为 m_falg_mbap_transId 的值。如果 m_falg_mbap_protocolId 的值为 MBAP_PROTOCOLID_DEFAULT,则将 pFrame 的协议标识设置为 0;否则将 pFrame 的协议标识设置为 m_falg_mbap_protocolId 的值。最后将 pFrame 的单元标识设置为 address(),并将 pdu 的值赋给 pFrame 的 PDU。函数返回 0。 CreateProtocolOf124 函数是一个 CProtocolBase 的工厂函数,用于创建一个 CCjModbusTcp 对象。函数返回一个 CProtocolBase 类型的指针,指向新创建的 CCjModbusTcp 对象。

相关推荐

填充下面这个程序中所有出现// TODO: fill the code这个任务的地方#include <iostream> #include <cstring> #include "ourstring.h" #include "strlib.h" using namespace std; OurString::OurString(){ // TODO: fill the code } OurString::OurString(const char *str){ // TODO: fill the code } OurString::OurString(const OurString &dstr){ // TODO: fill the code } OurString::~OurString(){ // TODO: fill the code } string OurString::toString() const{ // TODO: fill the code } OurString OurString::subStr(unsigned int start, unsigned int n) const{ // TODO: fill the code } bool OurString::operator > (const OurString &dstr) const{ // TODO: fill the code } bool OurString::operator < (const OurString &dstr) const{ // TODO: fill the code } bool OurString::operator == (const OurString &dstr) const{ // TODO: fill the code } unsigned int OurString::length () const{ // TODO: fill the code } const OurString& OurString::operator = (const OurString &dstr){ // TODO: fill the code } const OurString& OurString::operator = (const char *str){ // TODO: fill the code } char& OurString::operator[](int index){ // TODO: fill the code } const OurString OurString::operator + (const OurString &dstr) const{ // TODO: fill the code } const OurString OurString::operator + (const char *str) const{ // TODO: fill the code } const OurString& OurString::operator += (const OurString &dstr){ // TODO: fill the code } const OurString& OurString::operator += (const char *str){ // TODO: fill the code } ostream & operator<<(ostream &os, const OurString &dstr){ // TODO: fill the code } istream & operator>>(istream &is, OurString &dstr){ // TODO: fill the code }

最新推荐

recommend-type

深入const int *p与int * const p的区别详解(常量指针与指向常量的指针)

本篇文章是对const int *p与int * const p的区别进行了详细的分析介绍,需要的朋友参考下
recommend-type

const用法 const int *a; int * const a;

const char* pCh; // 指向字符串常量的指针; 表示pch是一个指针,指向字符串常量。根据需要还可以指向另一个字符串。 但字符串不能被改变。 char* const pCh; // 指向字符串的常量指针; 表示pch是一个字符串常...
recommend-type

实验五、运算符重载 复数+-*/ 大数+-*/

BigInteger operator +(const BigInteger& B); BigInteger operator -(const BigInteger& B); BigInteger operator *(const BigInteger& B); BigInteger operator /(const BigInteger& B); c++,大数类,完整程序...
recommend-type

std::string、char*、const char*转托管byte数组或托管字符串String

std::string、char*、const char*转托管byte数组或托管字符串String
recommend-type

android手机应用源码Imsdroid语音视频通话源码.rar

android手机应用源码Imsdroid语音视频通话源码.rar
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

可见光定位LED及其供电硬件具体型号,广角镜头和探测器,实验设计具体流程步骤,

1. 可见光定位LED型号:一般可使用5mm或3mm的普通白色LED,也可以选择专门用于定位的LED,例如OSRAM公司的SFH 4715AS或Vishay公司的VLMU3500-385-120。 2. 供电硬件型号:可以使用常见的直流电源供电,也可以选择专门的LED驱动器,例如Meanwell公司的ELG-75-C或ELG-150-C系列。 3. 广角镜头和探测器型号:一般可采用广角透镜和CMOS摄像头或光电二极管探测器,例如Omron公司的B5W-LA或Murata公司的IRS-B210ST01。 4. 实验设计流程步骤: 1)确定实验目的和研究对象,例如车辆或机器人的定位和导航。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。