⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remcom_rtu.cpp

📁 串口传输数据库函数
💻 CPP
字号:
// RemCom_rtu.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "RemCom_rtu.h"
#include "SerialPort.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
//	Note!
//
//		If this DLL is dynamically linked against the MFC
//		DLLs, any functions exported from this DLL which
//		call into MFC must have the AFX_MANAGE_STATE macro
//		added at the very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

/////////////////////////////////////////////////////////////////////////////
// CRemCom_rtuApp

BEGIN_MESSAGE_MAP(CRemCom_rtuApp, CWinApp)
	//{{AFX_MSG_MAP(CRemCom_rtuApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRemCom_rtuApp construction

CRemCom_rtuApp::CRemCom_rtuApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CRemCom_rtuApp object

//CRemCom_rtuApp theApp;

CString CRemCom_rtuApp::AddnumToChar(int Num)
{
    int NumH,NumL;
	char CharH,CharL;
	NumH = Num/16;   //高位
	NumL = Num%16;  //低位

	CString StringH,StringL;

    if (NumH >= 10)
    {
		CharH = 0x41 + (NumH - 10); //A~F
	}
    else
	{
        CharH = 0x30 + NumH ;    //0~9
	}

    if (NumL >= 10)
    {
		CharL = 0x41 + (NumL - 10); //A~F
	}
    else
	{
        CharL = 0x30 + NumL ;    //0~9
	}
    
	StringH = CharH;
	StringL = CharL;

	return StringH + StringL; 

}
CString CRemCom_rtuApp::AddCheckSum(CString m_str)
{
	CString m_Val;
	m_Val = m_str;
	BYTE m_flag,m_First,m_Second;
	unsigned int strnum;
	m_First = 0x00;
	m_flag = *(LPSTR)(LPCTSTR)(m_Val.Left(1)); //判断左边的第一个字母是否是0x0d
	while (m_flag != 0x0d)
	{
	  m_Second = *(LPSTR)(LPCTSTR)(m_Val.Left(1));
	  m_First = m_First + m_Second;
	  m_Val = m_Val.Mid(1);
	  m_flag = *(LPSTR)(LPCTSTR)(m_Val.Left(1)); 
	}
	strnum = (unsigned int)m_First;

	return AddnumToChar(strnum);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -