CSerialPort教程(5) - cmake方式使用CSerialPort

CSerialPort教程(5) - cmake方式使用CSerialPort


如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033

环境:

系统:windows 10 64位
QT: 5.12.9 LTS
MFC: vs2008、vs2017

前言

CSerialPort项目是基于C++的轻量级开源跨平台串口类库,用于实现跨平台多操作系统的串口读写。

CSerialPort项目的开源协议自 V3.0.0.171216 版本后采用GNU Lesser General Public License v3.0

为了让开发者更好的使用CSerialPort进行开发,特编写基于4.x版本的CSerialPort教程系列。

本文将介绍如何以cmake方式使用CSerialPort,包括但不限于console控制台项目、QT项目以及MFC项目。

CSerialPort项目地址:

  • https://github.com/itas109/CSerialPort
  • https://gitee.com/itas109/CSerialPort

1. cmake构建console控制台的CSerialPort项目

$ cd CommConsole
$ git clone https://github.com/itas109/CSerialPort

目录结构如下:

CommConsole $ tree
.
+--- CMakeLists.txt
+--- CSerialPort
|   +--- include
|   |   +--- CSerialPort
|   |   |   +--- SerialPort.h
|   |   |   +--- SerialPortInfo.h
|   +--- src
|   |   +--- SerialPort.cpp
|   |   +--- SerialPortBase.cpp
|   |   +--- SerialPortInfo.cpp
|   |   +--- SerialPortInfoBase.cpp
|   |   +--- SerialPortInfoWinBase.cpp
|   |   +--- SerialPortWinBase.cpp
+--- main.cpp

构建命令

mkdir bin
cd bin
set path=D:\Qt\Qt5.12.9\Tools\mingw730_64\bin;%path%
cmake .. -G "MinGW Makefiles" -DCMAKE_PREFIX_PATH=D:\Qt\Qt5.12.9\5.12.9\mingw73_64
cmake --build .

main.cpp

#include <iostream>

#include "CSerialPort/SerialPort.h"
#include "CSerialPort/SerialPortInfo.h"

#include <vector>
using namespace itas109;
using namespace std;

class mySlot : public has_slots<>
{
public:
    mySlot(CSerialPort *sp)
    {
        recLen = -1;
        p_sp = sp;
    };

    void OnSendMessage()
    {
        // read
        recLen = p_sp->readAllData(str);

        if (recLen > 0)
        {
            str[recLen] = '\0';
            std::cout << "receive data : " << str << ", receive size : " << recLen << std::endl;
        }
    };

private:
    mySlot(){};

private:
    CSerialPort *p_sp;

    char str[1024];
    int recLen;
};

int main()
{
    CSerialPort sp;
    mySlot receive(&sp);

    std::cout << "Version : " << sp.getVersion() << std::endl << std::endl;

    vector<SerialPortInfo> m_availablePortsList = CSerialPortInfo::availablePortInfos();

    if (0 == m_availablePortsList.size())
    {
        std::cout << "No valid port" << std::endl;
        return 0;
    }

    sp.init(m_availablePortsList[0].portName, // windows:COM1 Linux:/dev/ttyS0
            itas109::BaudRate9600, 
            itas109::ParityNone, 
            itas109::DataBits8, 
            itas109::StopOne);

    sp.open();

    if (sp.isOpened())
    {
        std::cout << "open " << m_availablePortsList[0].portName << " success" << std::endl;
    }
    else
    {
        std::cout << "open " << m_availablePortsList[0].portName << " failed" << std::endl;
        return 0;
    }

    // 绑定接收函数
    sp.readReady.connect(&receive, &mySlot::OnSendMessage);

    // 写入数据
    sp.writeData("itas109", 7);

    for (;;);

    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12)

project(CommConsole LANGUAGES CXX)

# add by itas109
set(CSerialPortRootPath "${PROJECT_SOURCE_DIR}/CSerialPort")
include_directories(${CSerialPortRootPath}/include)
list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPort.cpp ${CSerialPortRootPath}/src/SerialPortBase.cpp ${CSerialPortRootPath}/src/SerialPortInfo.cpp ${CSerialPortRootPath}/src/SerialPortInfoBase.cpp)
if (WIN32)
    list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPortInfoWinBase.cpp ${CSerialPortRootPath}/src/SerialPortWinBase.cpp)
else (UNIX)
    list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPortInfoUnixBase.cpp ${CSerialPortRootPath}/src/SerialPortUnixBase.cpp)
endif()
# end by itas109

add_executable(${PROJECT_NAME}
    main.cpp
    ${CSerialPortSourceFiles} # add by itas109
)

# add by itas109
if (WIN32)
        # for function availableFriendlyPorts
        target_link_libraries( ${PROJECT_NAME} setupapi)
elseif(APPLE)
    find_library(IOKIT_LIBRARY IOKit)
    find_library(FOUNDATION_LIBRARY Foundation)
    target_link_libraries( ${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
        target_link_libraries( ${PROJECT_NAME} pthread)
endif ()
# end by itas109

2. cmake构建QT的CSerialPort项目

新建一个QT项目目,解决方案名称为CommQT

【文件】-【新建文件或项目】-【Application(Qt)】-【Qt Widgets Application】-【choose…】-【名称: CommQT】-【Build system: CMake】

CommQT解决方案目录下载CSerialPort源码

$ cd CommQT
$ git clone https://github.com/itas109/CSerialPort

目录结构如下:

CommQT $ tree
.
+--- CMakeLists.txt
+--- CSerialPort
|   +--- include
|   |   +--- CSerialPort
|   |   |   +--- SerialPort.h
|   |   |   +--- SerialPortInfo.h
|   +--- src
|   |   +--- SerialPort.cpp
|   |   +--- SerialPortBase.cpp
|   |   +--- SerialPortInfo.cpp
|   |   +--- SerialPortInfoBase.cpp
|   |   +--- SerialPortInfoWinBase.cpp
|   |   +--- SerialPortWinBase.cpp
+--- main.cpp
+--- mainwindow.cpp
+--- mainwindow.h
+--- mainwindow.ui

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12)

project(CommQT LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5 COMPONENTS Widgets REQUIRED)

# add by itas109
set(CSerialPortRootPath "${PROJECT_SOURCE_DIR}/CSerialPort")
include_directories(${CSerialPortRootPath}/include)
list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPort.cpp ${CSerialPortRootPath}/src/SerialPortBase.cpp ${CSerialPortRootPath}/src/SerialPortInfo.cpp ${CSerialPortRootPath}/src/SerialPortInfoBase.cpp)
if (WIN32)
    list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPortInfoWinBase.cpp ${CSerialPortRootPath}/src/SerialPortWinBase.cpp)
elseif (UNIX)
    list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPortInfoUnixBase.cpp ${CSerialPortRootPath}/src/SerialPortUnixBase.cpp)
endif ()
# end by itas109

add_executable(${PROJECT_NAME}
    main.cpp
    mainwindow.cpp
    mainwindow.h
    mainwindow.ui
    ${CSerialPortSourceFiles} # add by itas109
)

target_link_libraries(CommQT Qt5::Widgets)

# add by itas109
if (WIN32)
        # for function availableFriendlyPorts
        target_link_libraries( ${PROJECT_NAME} setupapi)
elseif(APPLE)
    find_library(IOKIT_LIBRARY IOKit)
    find_library(FOUNDATION_LIBRARY Foundation)
    target_link_libraries( ${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
        target_link_libraries( ${PROJECT_NAME} pthread)
endif ()
# end by itas109

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

// add by itas109
#include <QPlainTextEdit>

#include "CSerialPort/SerialPort.h"
#include "CSerialPort/SerialPortInfo.h"
using namespace itas109;
// end by itas109

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow, public has_slots<> // add by itas109
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    // add by itas109
private:
    void OnReceive();

signals:
    void emitUpdateReceive(QString str);

private slots:
    void OnUpdateReceive(QString str);
    // end by itas109

private:
    Ui::MainWindow *ui;

    // add by itas109
    QPlainTextEdit * p_plainTextEditReceive;
    CSerialPort m_serialPort;
    // end by itas109
};
#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // add by itas109
    p_plainTextEditReceive = NULL;
    p_plainTextEditReceive = new QPlainTextEdit(ui->centralwidget);
    this->setCentralWidget(p_plainTextEditReceive);

    vector<SerialPortInfo> portNameList = CSerialPortInfo::availablePortInfos();

    if (portNameList.size() > 0)
    {
        p_plainTextEditReceive->moveCursor (QTextCursor::End);
        p_plainTextEditReceive->insertPlainText(QString("First avaiable Port: %1\n").arg(portNameList[0].portName.c_str()));
    }
    else
    {
        p_plainTextEditReceive->moveCursor (QTextCursor::End);
        p_plainTextEditReceive->insertPlainText("No avaiable Port");
        return;
    }

    connect(this,&MainWindow::emitUpdateReceive,this,&MainWindow::OnUpdateReceive,Qt::QueuedConnection);

    m_serialPort.readReady.connect(this, &MainWindow::OnReceive);

#ifdef Q_OS_WIN
    m_serialPort.init(portNameList[0].portName);
#else
    m_serialPort.init(portNameList[0].portName);
#endif
    m_serialPort.open();

    if (m_serialPort.isOpened())
    {
        p_plainTextEditReceive->moveCursor (QTextCursor::End);
        p_plainTextEditReceive->insertPlainText(QString("open %1 success\n").arg(portNameList[0].portName.c_str()));

        m_serialPort.writeData("itas109", 7);
    }
    else
    {
        p_plainTextEditReceive->moveCursor (QTextCursor::End);
        p_plainTextEditReceive->insertPlainText(QString("open %1 failed\n").arg(portNameList[0].portName.c_str()));
    }
    // end by itas109
}

MainWindow::~MainWindow()
{
    delete ui;

    // add by itas109
    this->disconnect();
    // end by itas109
}

// add by itas109
void MainWindow::OnReceive()
{
    char str[1024];
    int recLen = m_serialPort.readAllData(str);

    if (recLen > 0)
    {
        emitUpdateReceive(QString::fromLocal8Bit(str,recLen));
    }
}

void MainWindow::OnUpdateReceive(QString str)
{
    p_plainTextEditReceive->moveCursor (QTextCursor::End);
    p_plainTextEditReceive->insertPlainText(str);
}
// end by itas109

main.cpp

#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget"/>
  <widget class="QMenuBar" name="menubar"/>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

3. cmake构建MFC的CSerialPort项目

新建一个基于对话框的MFC项目,解决方案名称为CommMFC

$ cd CommMFC
$ git clone https://github.com/itas109/CSerialPort

目录结构如下:

CommMFC $ tree
.
+--- CMakeLists.txt
+--- CommMFC.cpp
+--- CommMFC.h
+--- CommMFC.rc
+--- CommMFCDlg.cpp
+--- CommMFCDlg.h
+--- CSerialPort
|   +--- include
|   |   +--- CSerialPort
|   |   |   +--- SerialPort.h
|   |   |   +--- SerialPortInfo.h
|   +--- src
|   |   +--- SerialPort.cpp
|   |   +--- SerialPortBase.cpp
|   |   +--- SerialPortInfo.cpp
|   |   +--- SerialPortInfoBase.cpp
|   |   +--- SerialPortInfoWinBase.cpp
|   |   +--- SerialPortWinBase.cpp
+--- ReadMe.txt
+--- res
|   +--- CommMFC.ico
|   +--- CommMFC.rc2
+--- Resource.h
+--- stdafx.cpp
+--- stdafx.h
+--- targetver.h

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12)

project(CommMFC)

set(MFCFiles
    CommMFC.cpp
    CommMFC.h
    CommMFC.rc
    CommMFCDlg.cpp
    CommMFCDlg.h
    Resource.h
    stdafx.cpp
    stdafx.h
    targetver.h
)

# add by itas109
set(CSerialPortRootPath "${PROJECT_SOURCE_DIR}/CSerialPort")
include_directories(${CSerialPortRootPath}/include)
list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPort.cpp ${CSerialPortRootPath}/src/SerialPortBase.cpp ${CSerialPortRootPath}/src/SerialPortInfo.cpp ${CSerialPortRootPath}/src/SerialPortInfoBase.cpp)
if(WIN32)
    list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPortInfoWinBase.cpp ${CSerialPortRootPath}/src/SerialPortWinBase.cpp)
elseif(UNIX)
    list(APPEND CSerialPortSourceFiles ${CSerialPortRootPath}/src/SerialPortInfoUnixBase.cpp ${CSerialPortRootPath}/src/SerialPortUnixBase.cpp)
endif()
# end by itas109

FIND_PACKAGE(MFC)
IF (NOT MFC_FOUND)
  MESSAGE(FATAL_ERROR "MFC not found")
endif()

add_definitions(-D_AFXDLL)
set(CMAKE_MFC_FLAG 2)

add_executable(${PROJECT_NAME} WIN32 ${MFCFiles} ${CSerialPortSourceFiles})

# add by itas109
if (WIN32)
        # for function availableFriendlyPorts
        target_link_libraries( ${PROJECT_NAME} setupapi)
elseif(APPLE)
    find_library(IOKIT_LIBRARY IOKit)
    find_library(FOUNDATION_LIBRARY Foundation)
    target_link_libraries( ${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
        target_link_libraries( ${PROJECT_NAME} pthread)
endif ()
# end by itas109

CommMFCDlg.h

// CommMFCDlg.h : header file
//

#pragma once

// add by itas109
#include "CSerialPort/SerialPort.h"
#include "CSerialPort/SerialPortInfo.h"
using namespace itas109;
// end by itas109

// CCommMFCDlg dialog
class CCommMFCDlg : public CDialog, public has_slots<> // add by itas109
{
// Construction
public:
	CCommMFCDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_COMMMFC_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support

	// add by itas109
private:
	void OnReceive();
    // end by itas109

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

    // add by itas109
private:
	CSerialPort m_serialPort;
	// end by itas109
};

CommMFCDlg.cpp

// CommMFCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CommMFC.h"
#include "CommMFCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CCommMFCDlg dialog




CCommMFCDlg::CCommMFCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCommMFCDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCommMFCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CCommMFCDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// CCommMFCDlg message handlers

BOOL CCommMFCDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
    // add by itas109
    CString message;
    vector<SerialPortInfo> portNameList = CSerialPortInfo::availablePortInfos();

    if (portNameList.size() > 0)
    {
        message.Format(_T("First avaiable Port: %s\n"),portNameList[0].portName.c_str());
        MessageBox(message);
    }
    else
    {
        MessageBox(_T("No avaiable Port"));
        return TRUE;
    }

	m_serialPort.readReady.connect(this, &CCommMFCDlg::OnReceive);

	m_serialPort.init(portNameList[0].portName);
	m_serialPort.open();

	if (m_serialPort.isOpened())
	{
        message.Format(_T("open %s success"),portNameList[0].portName.c_str());
		MessageBox(message);

		m_serialPort.writeData("itas109", 7);
	}
	else
	{
        message.Format(_T("open %s failed"),portNameList[0].portName.c_str());
		MessageBox(message);
	}
	// end by itas109

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// add by itas109
void CCommMFCDlg::OnReceive()
{
	char str[1024];
	int recLen = m_serialPort.readAllData(str);

	if (recLen > 0)
	{
		str[recLen] = '\0';

		CString cstr;
		cstr.Format(_T("OnReceive - data: %s, size: %d"), CString(str), recLen);
		MessageBox(LPCTSTR(cstr));
	}
}
// end by itas109

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCommMFCDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCommMFCDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

CommMFC.h

// CommMFC.h : main header file for the PROJECT_NAME application
//

#pragma once

#ifndef __AFXWIN_H__
	#error "include 'stdafx.h' before including this file for PCH"
#endif

#include "resource.h"		// main symbols


// CCommMFCApp:
// See CommMFC.cpp for the implementation of this class
//

class CCommMFCApp : public CWinApp
{
public:
	CCommMFCApp();

// Overrides
	public:
	virtual BOOL InitInstance();

// Implementation

	DECLARE_MESSAGE_MAP()
};

extern CCommMFCApp theApp;

CommMFC.cpp

// CommMFC.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "CommMFC.h"
#include "CommMFCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CCommMFCApp

BEGIN_MESSAGE_MAP(CCommMFCApp, CWinApp)
	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()


// CCommMFCApp construction

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


// The one and only CCommMFCApp object

CCommMFCApp theApp;


// CCommMFCApp initialization

BOOL CCommMFCApp::InitInstance()
{
	CWinApp::InitInstance();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	CCommMFCDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

CommMFC.rc

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/
//
// Generated from the TEXTINCLUDE 2 resource.
//
#ifndef APSTUDIO_INVOKED
#include "targetver.h"
#endif
#include "afxres.h"

/
#undef APSTUDIO_READONLY_SYMBOLS

#ifdef APSTUDIO_INVOKED
/
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE
BEGIN
	"#ifndef APSTUDIO_INVOKED\r\n"
    "#include ""targetver.h""\r\n"
    "#endif\r\n"
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE
BEGIN
    "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
    "#define _AFX_NO_OLE_RESOURCES\r\n"
    "#define _AFX_NO_TRACKER_RESOURCES\r\n"
    "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
    "\r\n"
    "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
    "LANGUAGE 9, 1\r\n"
    "#pragma code_page(1252)\r\n"
    "#include ""res\\CommMFC.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
    "#include ""afxres.rc""  	// Standard components\r\n"
    "#endif\r\n"
    "\0"
END

/
#endif    // APSTUDIO_INVOKED


/
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME           ICON         "res\\CommMFC.ico"


#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)

/
//
// Dialog
//

IDD_COMMMFC_DIALOG DIALOGEX  0, 0, 320, 200
STYLE DS_SHELLFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION
 | DS_MODALFRAME
 | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "CommMFC"
FONT 8, "MS Shell Dlg"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,209,179,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,263,179,50,14
	CTEXT           "TODO: Place dialog controls here.",IDC_STATIC,10,96,300,8
END

/
//
// Version
//

VS_VERSION_INFO     VERSIONINFO
  FILEVERSION       1,0,0,1
  PRODUCTVERSION    1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
	BLOCK "StringFileInfo"
	BEGIN
        BLOCK "040904e4"
		BEGIN
            VALUE "CompanyName", "TODO: <Company name>"
            VALUE "FileDescription", "TODO: <File description>"
			VALUE "FileVersion",     "1.0.0.1"
			VALUE "InternalName",    "CommMFC.exe"
            VALUE "LegalCopyright", "TODO: (c) <Company name>.  All rights reserved."
			VALUE "OriginalFilename","CommMFC.exe"
            VALUE "ProductName", "TODO: <Product name>"
			VALUE "ProductVersion",  "1.0.0.1"
		END
	END
	BLOCK "VarFileInfo"
	BEGIN
		VALUE "Translation", 0x0409, 1252
    END
END

/
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    IDD_COMMMFC_DIALOG, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 313
        TOPMARGIN, 7
        BOTTOMMARGIN, 193
    END
END
#endif    // APSTUDIO_INVOKED



/
//
// String Table
//



#endif

#ifndef APSTUDIO_INVOKED
/
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)
#include "res\\CommMFC.rc2"  // non-Microsoft Visual C++ edited resources
#include "afxres.rc"  	// Standard components
#endif
/
#endif    // not APSTUDIO_INVOKED

CommMFC.rc2

//
// CommMFC.RC2 - resources Microsoft Visual C++ does not edit directly
//

#ifdef APSTUDIO_INVOKED
#error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED


/
// Add manually edited resources here...

/

Resource.h

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by CommMFC.rc
//
#define IDR_MAINFRAME					128
#define IDD_COMMMFC_DIALOG				102

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NEXT_RESOURCE_VALUE	129
#define _APS_NEXT_CONTROL_VALUE		1000
#define _APS_NEXT_SYMED_VALUE		101
#define _APS_NEXT_COMMAND_VALUE		32771
#endif
#endif

stdafx.h

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently

#pragma once

#ifndef _SECURE_ATL
#define _SECURE_ATL 1
#endif

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
#endif

#include "targetver.h"

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit

// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions

#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                     // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

stdafx.cpp

// stdafx.cpp : source file that includes just the standard includes
// CommMFC.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

targetver.h

#pragma once

// The following macros define the minimum required platform.  The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
// your application.  The macros work by enabling all features available on platform versions up to and 
// including the version specified.

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER                          // Specifies that the minimum required platform is Windows Vista.
#define WINVER 0x0600           // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINDOWS          // Specifies that the minimum required platform is Windows 98.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif

#ifndef _WIN32_IE                       // Specifies that the minimum required platform is Internet Explorer 7.0.
#define _WIN32_IE 0x0700        // Change this to the appropriate value to target other versions of IE.
#endif

License

License under CC BY-NC-ND 4.0: 署名-非商业使用-禁止演绎

如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033


Reference:

  1. https://github.com/itas109/CSerialPort
  2. https://gitee.com/itas109/CSerialPort
  3. https://blog.csdn.net/itas109
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

itas109

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值