【C/C++】开源串口库 CSerialPort 应用

news2024/10/1 19:38:06

文章目录

  • 1、简述
  • 2、效果图
    • 2.1、命令行(不带GUI)
    • 2.2、GUI(这里用的Qt)
  • 3、串口硬件知识普及
  • 4、核心实现
    • 4.1、Qt的pro文件
    • 4.2、main文件
    • 4.3、SSerialPort类
      • 4.3.1、头文件
      • 4.3.2、源文件
    • 4.4、Linux下的CMakeLists.txt

1、简述

本文主要讲述 C++开源库 CSerialPort 的使用,主要在Windows和Linux两个平台分别应用。
有需要了解 C++开源库 CSerialPort 的小伙伴,可以先去这边文章下了解下为什么要用 CSerialPort 和 CSerialPort 的介绍。

文章链接:【C/C++】轻量级跨平台 开源串口库 CSerialPort

2、效果图

2.1、命令行(不带GUI)

Windows效果如下,Linux一样可以运行,只是串口名称不一样。因为还要切换系统,我就不截Linux图了
在这里插入图片描述

2.2、GUI(这里用的Qt)

放开pro里面的这两行即可,注释掉就是命令行,Windows效果图如下。Linux下这台没装Qt,没尝试,串口名称改下问题不大。

DEFINES += SHASHIDI_GUI
CONFIG += SHASHIDI_GUI

在这里插入图片描述

3、串口硬件知识普及

在这里插入图片描述
因为只测试串口的收发消息,把发送和接收的两个端口短接。找一个杜邦线直接串联起来就可以,这样发什么消息,就收到什么消息。如图是1口和3口短接。

4、核心实现

4.1、Qt的pro文件

Qt 的 pro 文件,如下。这里我用了一个宏来区分,一个是Pro的区分,一个是代码里面的区分

DEFINES += SHASHIDI_GUI
CONFIG += SHASHIDI_GUI

SHASHIDI_GUI{
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Demo_SerialPort

SOURCES += main.cpp \
    mainwindow.cpp

FORMS += \
    mainwindow.ui

HEADERS += \
    mainwindow.h

} else {
TARGET = Demo_SerialPort_Console

CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

HEADERS += \
    jsserialport.h

SOURCES += main.cpp \
    jsserialport.cpp
}

TEMPLATE = app

DEFINES += _UNICODE

include($$PWD/CSerialPort/CSerialPort.pri)

win32*: {
    #about windows reg
    LIBS += $$PWD/CSerialPort/windows/x86/advapi32.lib
    #about windows setupapi
    LIBS += $$PWD/CSerialPort/windows/x86/setupapi.lib
}

CONFIG(debug, debug|release) {
    DESTDIR = $$PWD/bin_debug
} else {
    DESTDIR = $$PWD/bin_release
}

HEADERS += \
    CommonSerialPort.h

4.2、main文件

#ifdef SHASHIDI_GUI
#include "mainwindow.h"
#include <QApplication>
#else
#include "jsserialport.h"
#include <iostream>
using namespace std;
#endif


#ifdef SHASHIDI_GUI
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
#else
int main()
{
    JSSerialPort js;
    js.doWork();

    return 0;
#endif
}

4.3、SSerialPort类

4.3.1、头文件

#ifndef SSERIALPORT_H
#define SSERIALPORT_H

#include <iostream>
#include "CSerialPort/SerialPort.h"
#include "CSerialPort/SerialPortInfo.h"
#include "CommonSerialPort.h"

using namespace std;
using namespace itas109;

class SSerialPort : public CSerialPortListener
{
public:
    SSerialPort();

    // 工作
    void doWork();

    // 校验
    void doCheck(char receiveBuf[], int receiveSize);

    // 串口信号
    bool m_flag_serialport = false;

    // 发出消息
    void sendMessage();

    // 读取全部数据
    void readAllData();

private:
    // 获取端口列表
    vector<SerialPortInfo> getSerialPortList();

    // 打开串口
    bool openSerialPort(const char *portName,
                        int baudRate = 9600,
                        itas109::Parity parity = itas109::Parity::ParityNone,
                        itas109::DataBits dataBits = itas109::DataBits::DataBits8,
                        itas109::StopBits stopbits = itas109::StopBits::StopOne,
                        itas109::FlowControl flowControl = itas109::FlowControl::FlowNone,
                        unsigned int readBufferSize = 4096, int timeout = 0);

    // 关闭串口
    void closeSerialPort();

    // 收到消息
    void onReadEvent(const char *portName, unsigned int readBufferLen);

    // 设置串口模式  同步\异步
    void setSync(bool isSync);

    // 设置DTR
    void setDTR(bool isDTR);

    // 设置RTS
    void setRTS(bool isRTS);

    // 初始化串口
    void initSerialPort();

    // 初始化发送消息
    void initSendMessage();
private:
    CSerialPort m_SerialPort;   // 串口

    struct TERMINAL_TO_FIRECONTROL *m_terminal_to_firecontrol;    // 终端到火控
    struct FIRECONTROL_TO_TERMINAL *m_firecontrol_to_terminal;    // 火控到终端

    int m_packet_frame_count = 0;   // 报文帧号累计
    int m_buffer_size = 2048;
    int m_frame_length = 34;
    unsigned char m_firstChar = 161;    // 0xA1
    unsigned char m_secondChar = 177;   // 0xB1
    unsigned char m_thirdChar = 50;     // 0x32
    int m_tx = 0;
    int m_rx = 0;
};

#endif // SSERIALPORT_H

4.3.2、源文件

#include "sserialport.h"

#include <iostream>
#include <iomanip>

SSerialPort::SSerialPort()
{
}

void SSerialPort::doWork()
{
    cout << "doWork: initSerialPort" << endl;
    initSerialPort();
    cout << "doWork: initSendMessage" << endl;
    initSendMessage();
    cout << "doWork: sendMessage" << endl;
    sendMessage();
    cout << "doWork: readAllData" << endl;
    readAllData();
}

void SSerialPort::doCheck(char receiveBuf[], int receiveSize)
{
    cout << "doCheck: start" << receiveSize << endl;
    for(int i = 0; i < receiveSize; i++) {
        if( ( receiveSize - i ) < m_frame_length ) { //不足一帧则退出
            break;
        }
        cout << "doCheck1: " << receiveBuf[i] << endl;
        if( (receiveBuf[i] == m_secondChar) && (receiveBuf[i+1] == m_firstChar) ) { //发现帧头,取出一帧校验
            cout << "doCheck: " << receiveBuf[i] << endl;
            string aa(receiveBuf);
            cout << "doCheck: " << aa << endl;
            string tmp_s(aa, i, m_frame_length);
            cout << "doCheck: " << tmp_s << endl;
            int data = 0;
            for(int i = 0; i < (m_frame_length - 1); i++) {
                data = data + tmp_s[i];
            }
            unsigned char data1 = data & 0x7f;
            if(data1 != tmp_s[m_frame_length - 1]) {
                i = i + 1;
                continue;
            }
            //校验通过,取值
            m_firecontrol_to_terminal->send_address = tmp_s[0];
            m_firecontrol_to_terminal->receive_address = tmp_s[1];
            m_firecontrol_to_terminal->packet_length = tmp_s[2];
            m_firecontrol_to_terminal->packet_frame_number_low = tmp_s[3];
            m_firecontrol_to_terminal->packet_frame_number_high = tmp_s[4];
            m_firecontrol_to_terminal->light_aiming_status_word_1.all = tmp_s[5];
            m_firecontrol_to_terminal->light_aiming_status_word_2.all = tmp_s[6];
            m_firecontrol_to_terminal->laser_ranging_distance_low = tmp_s[7];
            m_firecontrol_to_terminal->laser_ranging_distance_high = tmp_s[8];
            m_firecontrol_to_terminal->servo_status_word_1.all = tmp_s[9];
            m_firecontrol_to_terminal->servo_status_word_2.all = tmp_s[10];
            m_firecontrol_to_terminal->speed_of_chassis = tmp_s[11];
            m_firecontrol_to_terminal->chassis_battery_power = tmp_s[12];
            m_firecontrol_to_terminal->front_flip_arm_angle_low = tmp_s[13];
            m_firecontrol_to_terminal->front_flip_arm_angle_high = tmp_s[14];
            m_firecontrol_to_terminal->back_flip_arm_angle_low = tmp_s[15];
            m_firecontrol_to_terminal->back_flip_arm_angle_high = tmp_s[16];
            m_firecontrol_to_terminal->relay_status_word.all = tmp_s[17];
            m_firecontrol_to_terminal->light_azimuth_position_low = tmp_s[18];
            m_firecontrol_to_terminal->light_azimuth_position_high = tmp_s[19];
            m_firecontrol_to_terminal->light_pitch_position_low = tmp_s[20];
            m_firecontrol_to_terminal->light_pitch_position_high = tmp_s[21];
            m_firecontrol_to_terminal->weapon_azimuth_position_low = tmp_s[22];
            m_firecontrol_to_terminal->weapon_azimuth_position_high = tmp_s[23];
            m_firecontrol_to_terminal->weapon_pitch_position_low = tmp_s[24];
            m_firecontrol_to_terminal->weapon_pitch_position_high = tmp_s[25];
            m_firecontrol_to_terminal->platform_pitch = tmp_s[26];
            m_firecontrol_to_terminal->platform_roll_angle = tmp_s[27];
            m_firecontrol_to_terminal->residual_bullet_low = tmp_s[28];
            m_firecontrol_to_terminal->residual_bullet_high = tmp_s[29];
            m_firecontrol_to_terminal->rsve1 = tmp_s[30];
            m_firecontrol_to_terminal->rsve2 = tmp_s[31];
            m_firecontrol_to_terminal->rsve3 = tmp_s[32];
            m_firecontrol_to_terminal->check = tmp_s[33];
            cout << "doCheck: send_address" << tmp_s << endl;
//            emit sig_check(data1);
        }
    }
}

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

    for (size_t i = 0; i < portNameList.size(); i++) {
        cout << "getSerialPortList:" << portNameList[i].portName << endl;
    }
    if ( portNameList.size() == 0 ) {
        cout << "getSerialPortList is Null" << endl;
    }
    return portNameList;
}

bool SSerialPort::openSerialPort(const char *portName, int baudRate, Parity parity, DataBits dataBits, StopBits stopbits, FlowControl flowControl, unsigned int readBufferSize, int timeout)
{
    cout << "openSerialPort-----------------------------------start" << endl;
    bool isOpen = false;
    if(getSerialPortList().size() > 0) {
        m_SerialPort.init(portName, baudRate, parity, dataBits, stopbits, flowControl, readBufferSize);

        cout << "portName:" << portName << endl;
        cout << "baudRate:" << baudRate << endl;
        cout << "parity:" << parity << endl;
        cout << "dataBits:" << dataBits << endl;
        cout << "stopbits:" << stopbits << endl;
        cout << "flowControl:" << flowControl << endl;
        cout << "readBufferSize:" << readBufferSize << endl;
        m_SerialPort.setReadIntervalTimeout(timeout);
        isOpen = m_SerialPort.open();
        if(!isOpen) {
            cerr << "open port error" << m_SerialPort.getLastError() << m_SerialPort.getLastErrorMsg() << endl;
        }
    } else {
        cerr << "This Computer no avaiable port!" << endl;
    }
    cout << "openSerialPort-----------------------------------end" << endl;
    return isOpen;
}

void SSerialPort::closeSerialPort()
{
    m_SerialPort.close();
}

void SSerialPort::onReadEvent(const char *portName, unsigned int readBufferLen)
{
    cout << "onReadEvent:" << portName << readBufferLen << endl;
    if(readBufferLen > 0) {
        unsigned long recLen = 0;
        char * str = NULL;
        str = new char[readBufferLen];
        recLen = m_SerialPort.readData(str, readBufferLen);

        if(recLen > 0) {
            // TODO: 中文需要由两个字符拼接,否则显示为空""
            cout << "onReadEvent:" << portName << str << recLen << endl;
            doCheck(str, recLen);
        } else {

        }

        if(str) {
            delete[] str;
            str = NULL;
        }
    }
}

void SSerialPort::sendMessage()
{
    char message[50];
    if(m_SerialPort.isOpen()) {
        // 伺服旋转限制

        // 高位低位赋值
        m_terminal_to_firecontrol->packet_frame_number_low = m_packet_frame_count & 0x00ff;
        m_terminal_to_firecontrol->packet_frame_number_high = (m_packet_frame_count >> 8) & 0x00ff;

        message[0] = m_firstChar;
        message[1] = m_secondChar;
        message[2] = m_thirdChar;
        cout << "m_terminal_to_firecontrol->packet_frame_number_low: " << m_terminal_to_firecontrol->packet_frame_number_low << endl;
        message[3] = m_terminal_to_firecontrol->packet_frame_number_low;
        message[4] = m_terminal_to_firecontrol->packet_frame_number_high;
        message[5] = m_terminal_to_firecontrol->light_aiming_control_word_1.all;//变化
        message[6] = m_terminal_to_firecontrol->light_aiming_control_word_2.all;
        message[7] = m_terminal_to_firecontrol->light_aiming_control_word_3.all;
        message[8] = m_terminal_to_firecontrol->servo_control_word_1.all;
        message[9] = m_terminal_to_firecontrol->servo_control_word_2.all;
        message[10] = m_terminal_to_firecontrol->chassis_control_word_1.all;
        message[11] = m_terminal_to_firecontrol->relay_control_word.all;
        message[12] = m_terminal_to_firecontrol->light_azimuth_rotation_speed_low;
        message[13] = m_terminal_to_firecontrol->light_azimuth_rotation_speed_high;
        message[14] = m_terminal_to_firecontrol->light_pitch_rotation_speed_low;
        message[15] = m_terminal_to_firecontrol->light_pitch_rotation_speed_high;
        message[16] = m_terminal_to_firecontrol->fan_sweep_azimuth_setting_Angle;
        message[17] = m_terminal_to_firecontrol->fan_sweep_azimuth_fu_setting_Angle;
        message[18] = m_terminal_to_firecontrol->fan_sweep_pitch_setting_Angle;
        message[19] = m_terminal_to_firecontrol->fan_sweep_pitch_fu_setting_Angle;
        message[20] = m_terminal_to_firecontrol->quick_boot_azimuth_coordinates_low;
        message[21] = m_terminal_to_firecontrol->quick_boot_azimuth_coordinates_high;
        message[22] = m_terminal_to_firecontrol->quick_boot_pitch_coordinates_low;
        message[23] = m_terminal_to_firecontrol->quick_boot_pitch_coordinates_high;
        message[24] = m_terminal_to_firecontrol->left_track_speed_low;
        message[25] = m_terminal_to_firecontrol->left_track_speed_high;
        message[26] = m_terminal_to_firecontrol->right_track_speed_low;
        message[27] = m_terminal_to_firecontrol->right_track_speed_high;
        message[28] = m_terminal_to_firecontrol->forward_arm_speed;
        message[29] = m_terminal_to_firecontrol->back_arm_speed;
        message[30] = m_terminal_to_firecontrol->residual_low;
        message[31] = m_terminal_to_firecontrol->residual_high;
        message[32] = m_terminal_to_firecontrol->azimuth_correction;
        message[33] = m_terminal_to_firecontrol->pitch_correction;
        message[34] = m_terminal_to_firecontrol->delay_correction;
        message[35] = m_terminal_to_firecontrol->light_aiming_control_word_4.all;
        message[36] = m_terminal_to_firecontrol->light_aiming_control_word_5.all;
        message[37] = m_terminal_to_firecontrol->servo_azimuth_rotation_speed_low;
        message[38] = m_terminal_to_firecontrol->servo_azimuth_rotation_speed_high;
        message[39] = m_terminal_to_firecontrol->servo_pitch_rotation_speed_low;
        message[40] = m_terminal_to_firecontrol->servo_pitch_rotation_speed_high;
        message[41] = m_terminal_to_firecontrol->firing_servo_start_low;
        message[42] = m_terminal_to_firecontrol->firing_servo_start_high;
        message[43] = m_terminal_to_firecontrol->firing_servo_stop_low;
        message[44] = m_terminal_to_firecontrol->firing_servo_stop_high;
        message[45] = m_terminal_to_firecontrol->firing_insurance_close_low;
        message[46] = m_terminal_to_firecontrol->firing_insurance_close_high;
        message[47] = m_terminal_to_firecontrol->firing_insurance_open_low;
        message[48] = m_terminal_to_firecontrol->firing_insurance_open_high;

        int data = 0;
        for( int i = 0; i < 49; i++ ) {
            cout << "sendMessage: " << message[i] << endl;
            data = data + message[i];
        }
        message[49] = data & 0x7f;

        int length = sizeof(message)/sizeof(char);
        if( !m_flag_serialport ) {
            // 支持中文并获取正确的长度
            m_SerialPort.writeData(message, length);
        } else {

        }
        if( m_packet_frame_count >= 0xffff ) {
            m_packet_frame_count = 1;
        } else {
            m_packet_frame_count++;
        }
        cout << "sendMessage:" << message << " length: " << length << endl;
    } else {
        cerr << "please open serial port first!" << endl;
    }
}

void SSerialPort::readAllData()
{
    int recLen = 0;
    char str[4096] = {0};
    recLen = m_SerialPort.readAllData(str);

    if(recLen > 0) {
        // TODO: 中文需要由两个字符拼接,否则显示为空""
        cout << "readAllData:" << str << " length: " << recLen << endl;
        doCheck(str, recLen);
    } else {

    }
}

void SSerialPort::setSync(bool isSync)
{
    if(isSync) {
        m_SerialPort.setOperateMode(itas109::SynchronousOperate);
    } else {
        m_SerialPort.setOperateMode(itas109::AsynchronousOperate);
    }
}

void SSerialPort::setDTR(bool isDTR)
{
    m_SerialPort.setDtr(isDTR);
}

void SSerialPort::setRTS(bool isRTS)
{
    m_SerialPort.setRts(isRTS);
}

void SSerialPort::initSerialPort()
{
#ifdef WIN32
    this->openSerialPort("COM3", 115200, itas109::ParityNone,
                         itas109::DataBits8, itas109::StopOne);
#else
    this->openSerialPort("/dev/ttyUSB0", 115200, itas109::ParityNone,
                         itas109::DataBits8, itas109::StopOne);
#endif
}

void SSerialPort::initSendMessage()
{
    cout << "initSendMessage-----------------------------------start" << endl;
    m_packet_frame_count = 1;

    m_terminal_to_firecontrol = (struct TERMINAL_TO_FIRECONTROL*)malloc(sizeof(struct TERMINAL_TO_FIRECONTROL));
    m_firecontrol_to_terminal = (struct FIRECONTROL_TO_TERMINAL*)malloc(sizeof(struct FIRECONTROL_TO_TERMINAL));
    m_terminal_to_firecontrol->send_address = m_firstChar;
    m_terminal_to_firecontrol->receive_address = m_secondChar;
    m_terminal_to_firecontrol->packet_length = m_thirdChar;
    m_terminal_to_firecontrol->packet_frame_number_low = 1;
    std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(m_terminal_to_firecontrol->packet_frame_number_low)<<endl;
    m_terminal_to_firecontrol->packet_frame_number_high = 0;
    m_terminal_to_firecontrol->light_aiming_control_word_1.all = 0x01;
    m_terminal_to_firecontrol->light_aiming_control_word_2.all = 0x00;
    m_terminal_to_firecontrol->light_aiming_control_word_3.all = 0x00;
    m_terminal_to_firecontrol->servo_control_word_1.all = 0x09;
    m_terminal_to_firecontrol->servo_control_word_2.all = 0x02;
    m_terminal_to_firecontrol->chassis_control_word_1.all = 0x00;
    m_terminal_to_firecontrol->relay_control_word.all = 0x00;
    m_terminal_to_firecontrol->light_azimuth_rotation_speed_low = 0x00;
    m_terminal_to_firecontrol->light_azimuth_rotation_speed_high = 0X00;
    m_terminal_to_firecontrol->light_pitch_rotation_speed_low = 0;
    m_terminal_to_firecontrol->light_pitch_rotation_speed_high = 0;
    m_terminal_to_firecontrol->fan_sweep_azimuth_setting_Angle = 0;
    m_terminal_to_firecontrol->fan_sweep_azimuth_fu_setting_Angle = 0;
    m_terminal_to_firecontrol->fan_sweep_pitch_setting_Angle = 0;
    m_terminal_to_firecontrol->fan_sweep_pitch_fu_setting_Angle = 0;
    m_terminal_to_firecontrol->quick_boot_azimuth_coordinates_low = 0;
    m_terminal_to_firecontrol->quick_boot_azimuth_coordinates_high = 0;
    m_terminal_to_firecontrol->quick_boot_pitch_coordinates_low = 0;
    m_terminal_to_firecontrol->quick_boot_pitch_coordinates_high = 0;
    m_terminal_to_firecontrol->left_track_speed_low = 0;
    m_terminal_to_firecontrol->left_track_speed_high = 0;
    m_terminal_to_firecontrol->right_track_speed_low = 0;
    m_terminal_to_firecontrol->right_track_speed_high = 0;
    m_terminal_to_firecontrol->forward_arm_speed = 0;
    m_terminal_to_firecontrol->back_arm_speed = 0;
    m_terminal_to_firecontrol->residual_low = 0;
    m_terminal_to_firecontrol->residual_high = 0;
    m_terminal_to_firecontrol->azimuth_correction = 0;
    m_terminal_to_firecontrol->pitch_correction = 0;
    m_terminal_to_firecontrol->delay_correction = 0;
    m_terminal_to_firecontrol->light_aiming_control_word_4.all = 0;
    m_terminal_to_firecontrol->light_aiming_control_word_5.all = 0;
    m_terminal_to_firecontrol->servo_azimuth_rotation_speed_low = 0x00;
    m_terminal_to_firecontrol->servo_azimuth_rotation_speed_high = 0x00;
    m_terminal_to_firecontrol->servo_pitch_rotation_speed_low = 0;
    m_terminal_to_firecontrol->servo_pitch_rotation_speed_high = 0;
    m_terminal_to_firecontrol->firing_servo_start_low = 0;
    m_terminal_to_firecontrol->firing_servo_start_high = 0;
    m_terminal_to_firecontrol->firing_servo_stop_low = 0;
    m_terminal_to_firecontrol->firing_servo_stop_high = 0;
    m_terminal_to_firecontrol->firing_insurance_close_low = 0;
    m_terminal_to_firecontrol->firing_insurance_close_high = 0;
    m_terminal_to_firecontrol->firing_insurance_open_low = 0;
    m_terminal_to_firecontrol->firing_insurance_open_high = 0;;
    m_terminal_to_firecontrol->check = 0;
    cout << "initSendMessage-----------------------------------end" << endl;
}

4.4、Linux下的CMakeLists.txt

cmake_minimum_required(VERSION 3.0.2)
project(electro_optical_system)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(OpenCV REQUIRED)

## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES electro_optical_system
#  CATKIN_DEPENDS roscpp rospy std_msgs
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/electro_optical_system.cpp
# )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/electro_optical_system_node.cpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
#   ${catkin_LIBRARIES}
# )

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )

## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )

## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_electro_optical_system.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
add_executable(EOS src/main.cpp src/jsserialport.cpp src/CSerialPort/SerialPort.cpp src/CSerialPort/SerialPortInfo.cpp  src/CSerialPort/SerialPortUnixBase.cpp src/CSerialPort/SerialPortBase.cpp  src/CSerialPort/SerialPortInfoUnixBase.cpp  src/CSerialPort/SerialPortInfoBase.cpp) 
target_link_libraries(EOS ${catkin_LIBRARIES}
                                ${OpenCV_LIBS})
add_dependencies(EOS ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1362621.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ruoyi若依 @DataScope(deptAlias = “d“, userAlias = “u“)不生效问题

DataScope注解不生效问题记录 问题&#xff1a;DataScope(deptAlias "d", userAlias "u")不生效问题原因排查&#xff1a;解决方案&#xff1a;结果&#xff1a;完美解决 问题&#xff1a;DataScope(deptAlias “d”, userAlias “u”)不生效问题 原因…

MDPI期刊word模版下载

先打开该网站 找到Manuscript 就能下载到word文件了

吴恩达深度学习l2week2编程作业—Optimization Methods(最新中文跑通版)

到目前为止&#xff0c;您一直使用渐变下降来更新参数并将成本降至最低。在本笔记本中&#xff0c;您将获得一些更先进的优化方法的技能&#xff0c;这些方法可以加快学习速度&#xff0c;甚至可能使您获得更好的成本函数最终值。拥有一个好的优化算法可能是等待几天与只需几个…

解决使用localhost或127.0.01模拟CORS失效

解决使用localhost或127.0.01模拟CORS失效 前言问题发现问题解决 前言 CORS (Cross-Origin Resource Sharing) 指的是一种机制&#xff0c;它允许不同源的网页请求访问另一个源服务器上的某些资源。通常情况下&#xff0c;如果 JavaScript 代码在一个源中发起了 AJAX 请求&…

HAL——定时器

学习目标 掌握定时器I配置方式掌握定时器占空比输出 学习内容 需求 以PA5对应的LED4为例&#xff0c;我们做一个呼吸灯的效果。 我们采用TIMER1进行实现&#xff1a; Timer配置 配置Timer通道输出 配置周期和分频计数 psc为分频系数&#xff0c;这里的值需要写入到寄存器中…

HAL——SPI

学习目标 掌握SPI配置方式掌握SPI读写操作 学习内容 需求 SPI配置 打开SPI1,选中全双工模式。观察下方自动生成的引脚&#xff0c;是否和自己开发板引脚对应。 修改引脚&#xff0c;来动右侧芯片引脚视图&#xff0c;找到开发板对应引脚&#xff0c;进行修改。

Linux 目录结构及其说明

Linux 操作系统遵循一种标准的目录结构&#xff0c;称为 Filesystem Hierarchy Standard&#xff08;文件系统层次结构标准&#xff09;&#xff0c;其定义了不同目录的用途和内容。 浅蓝色文字 /&#xff08;根目录&#xff09;&#xff1a; /根目录是整个文件系统的起点&…

学习Go语言Web框架Gee总结--http.Handler(一)

学习Go语言Web框架Gee总结--http.Handler http-base/go.modhttp-base/main.gohttp-base/gee/gee.gohttp-base/gee/go.mod 网站学习来源&#xff1a;Gee 代码目录结构&#xff1a; http-base/go.mod //指定当前模块的名称为 "example" module example//指定当前模…

一个命令查看linux系统是Centos还是Ubuntu

目 录 一、 背景介绍 二、一个命令查看linux系统的简单方法 1、 uname -a 2、cat /etc/issue 3、lsb_release -a 4、 dmesg | grep Ubuntu 一、 背景介绍 Linux 系统基本上分为两大类&#xff1a; 1. Red Hat 系列&#xff1a;包括 Red Ha…

SpringBoot 如何 配置端口号

结论 server:port: 8088演示 [Ref] 快速构建SpringBoot项目

AI看图识熊实战(一)

使用ONNX Runtime封装onnx模型并推理 进行这一步之前&#xff0c;请确保已正确安装配置了Visual Studio 2017 和 C#开发环境。 项目的代码也可以在这里找到&#xff0c;下面的步骤是带着大家从头到尾做一遍。 界面设计 创建Windows窗体应用(.NET Framework)项目&#xff0c…

CRC32的原理介绍以及查表法实现和多项式相除实现

1、CRC32的生成多项式 多项式系数提取出来&#xff0c;改写位16进制数为&#xff1a;0x104C11DB7&#xff0c;如果转换为33个二进制数[1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1] &#xff0c;那么从左到右对…

工地云平台源码,智慧工地源码,Spring Cloud智慧工地管理系统源码

智慧工地是一种基于信息技术和大数据应用的智能化管理平台&#xff0c;旨在提升建筑施工现场的安全、效率和质量。通过物联网、云计算、人工智能等技术手段&#xff0c;智慧工地可以对施工现场的各个要素进行全面感知、实时交互和智能分析&#xff0c;以实现更高效、更安全、更…

【LMM 015】LAMM:多模态指令微调数据集,框架和基准

论文标题&#xff1a;LAMM: Language-Assisted Multi-Modal Instruction-Tuning Dataset, Framework, and Benchmark 论文作者&#xff1a;Zhenfei Yin, Jiong Wang, Jianjian Cao, Zhelun Shi, Dingning Liu, Mukai Li, Lu Sheng, Lei Bai, Xiaoshui Huang, Zhiyong Wang, Jin…

视觉检测不合格品剔除FC(Smart PLC简单状态机编程应用)

视觉系统检测到不合格产品后&#xff0c;往往都需要控制我们的剔除电磁阀吹气剔除不合格产品&#xff0c;三菱PLC里的推荐编程方法&#xff0c;可以参考下面的链接文章&#xff1a; https://rxxw-control.blog.csdn.net/article/details/125027866https://rxxw-control.blog.c…

【算法每日一练]-图论(保姆级教程篇14 )#会议(模板题) #医院设置 #虫洞 #无序字母对 #旅行计划 #最优贸易

目录 今日知识点&#xff1a; 求数的重心先dfs出d[1]和cnt[i]&#xff0c;然后从1进行dp求解所有d[i] 两两点配对的建图方式&#xff0c;检查是否有环 无向图欧拉路径路径输出 topodp求以i为终点的游览城市数 建立分层图转化盈利问题成求最长路 会议&#xff08;模板题&a…

I.MX6ULL开发笔记(二)——硬件外设操作

0x01 点亮第一个RGB灯 在文章http://t.csdnimg.cn/EGWt9中有介绍Linux下文件目录&#xff0c;那么在Linux系统下&#xff0c;RGB灯也是一个设备&#xff0c;所以我们需要到/sys目录下去操作这个设备。 之后&#xff0c;我们进入到class目录&#xff0c;这里挂载着开发板上的外…

【数据仓库与联机分析处理】多维数据模型

目录 一、数据立方体 二、数据模型 &#xff08;一&#xff09;星形模型 &#xff08;二&#xff09;雪花模式 &#xff08;三&#xff09;事实星座模式 三、多维数据模型中的OLAP操作 &#xff08;一&#xff09;下钻 &#xff08;二&#xff09;上卷 &#xff08;三…

【GitHub】-design-pattern-extend(设计模式扩展)

写在前面 偶然间看到一篇文章 《Java 中保持扩展性的几种套路和实现》&#xff0c;写的不错&#xff0c;但是类图画的差了点儿意思。于是&#xff0c;自己动手画了画&#xff0c;对其中的内容作了一些调整&#xff0c;对包做了进一步划分&#xff0c;便于理解消化。以下是对Git…

第11章 GUI Page462~476 步骤二十三,二十四,二十五 Undo/Redo ③实现“Undo/Redo”菜单项

工程六 添加“编辑”菜单和子菜单 菜单ID分别为 idMenuEditUndo 和 idMenuEditRedo 热键&#xff08;快捷键&#xff09;分别为CtrlZ 和 CtrlShiftZ 变量名分别为 MenuItemEditUndo 和 MenuItemEditRedo 分别添加事件 ActionLink类增加成员函数 运行效果&#xff1a;“添加…