代码理解
Slave104.h界面信息更新接口头文件及Slave104.cpp实现文件
已注释过内容不再注释,请参考
C++代码审阅–ice104协议从站(1)
C++代码审阅–ice104协议从站(2)
C++代码审阅–ice104协议从站(3)
C++代码审阅–ice104协议从站(4)
C++代码审阅–ice104协议从站(5)
C++代码审阅–ice104协议从站(6)
C++代码审阅–ice104协议从站(7)
后面几篇内容只需了解iec104协议基础知识即可理解,请看以下链接,看懂了有协议基础都很好理解了。
电力IEC104规约协议解读(含源码下载)
头文件
//界面数据更新接口文件,作用是更新dlg界面的信息。
#if !defined(AFX_SLAVE104_H__7ACBCB35_4EAC_4775_9784_3D8572104FE9__INCLUDED_)
#define AFX_SLAVE104_H__7ACBCB35_4EAC_4775_9784_3D8572104FE9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "IEC104Slave.h"
class CIEC104NASlaveDlg;
class Slave104 : public CIEC104Slave
{
public:
void OnUpdateWnd();
void OnTxMsg(BYTE *msgbuf, unsigned int len);
void OnRxMsg(BYTE *msgbuf, unsigned int len);
void OnUpdateTime(int nType, BOOL isInvalid);
void OnUpdateRemainTime(int nType, int nRemainSecond, BOOL isInvalid);
Slave104();
virtual ~Slave104();
CIEC104NASlaveDlg *dlg;
};
#endif // !defined(AFX_SLAVE104_H__7ACBCB35_4EAC_4775_9784_3D8572104FE9__INCLUDED_)
实现文件
// Slave104.cpp: implementation of the Slave104 class.
//
//
#include "stdafx.h"
#include "IEC104NASlave.h"
#include "IEC104NASlaveDlg.h"
#include "Slave104.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//
// Construction/Destruction
//
Slave104::Slave104()
{
}
Slave104::~Slave104()
{
}
void Slave104::OnRxMsg(BYTE *msgbuf, unsigned int len)
{
CString ch, str;
str="Rece:";
for(unsigned int n = 0; n < len; n++)
{
ch.Format(" %02x",msgbuf[n]);
str += ch;
if(n>0 && !(n%20))
{
str += "\n";
}
}
// dlg->m_revList.AddString(str);
dlg->m_sendList.AddString(str);
}
void Slave104::OnTxMsg(BYTE *msgbuf, unsigned int len)
{
CString ch, str;
str="Send:";
for(unsigned int n = 0; n < len; n++)
{
ch.Format(" %02x",msgbuf[n]);
str += ch;
if(n>0 && !(n%20))
{
str += "\n";
}
}
dlg->m_sendList.AddString(str);
}
void Slave104::OnUpdateTime(int nType, BOOL isInvalid)
{
dlg->SetTimeCtrl(nType, isInvalid);
}
void Slave104::OnUpdateRemainTime(int nType, int nRemainSecond, BOOL isInvalid)
{
dlg->SetRemainTimeCtrl(nType, nRemainSecond, isInvalid);
}
void Slave104::OnUpdateWnd()
{
dlg->SetButtonState(FALSE);
}
本系列所有源代码均从CSDN找的资源下载,在VS2015做了一点小改动编译通过后发表,如有侵权请及时联系我删除。