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

文章目录

  • 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_GUISHASHIDI_GUI{
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = Demo_SerialPortSOURCES += main.cpp \mainwindow.cppFORMS += \mainwindow.uiHEADERS += \mainwindow.h} else {
TARGET = Demo_SerialPort_ConsoleCONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qtHEADERS += \jsserialport.hSOURCES += main.cpp \jsserialport.cpp
}TEMPLATE = appDEFINES += _UNICODEinclude($$PWD/CSerialPort/CSerialPort.pri)win32*: {#about windows regLIBS += $$PWD/CSerialPort/windows/x86/advapi32.lib#about windows setupapiLIBS += $$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);// 设置DTRvoid setDTR(bool isDTR);// 设置RTSvoid 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;    // 0xA1unsigned char m_secondChar = 177;   // 0xB1unsigned char m_thirdChar = 50;     // 0x32int 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 WIN32this->openSerialPort("COM3", 115200, itas109::ParityNone,itas109::DataBits8, itas109::StopOne);
#elsethis->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 COMPONENTSroscpprospystd_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.mzph.cn/news/602637.shtml

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

相关文章

设计模式之单例模式的懒饿汉

懒汉式 说白了就是你不叫我我不动&#xff0c;你叫我我才动。 类初始化模式&#xff0c;也叫延迟占位模式。在单例类的内部由一个私有静态内部类来持有这个单例类的实例。因为在 JVM 中&#xff0c;对类的加载和类初始化&#xff0c;由虚拟机保证线程安全。 public class Singl…

cesium键盘控制模型

效果&#xff1a; 由于对添加模型和更新位置api进行二次了封装&#xff0c;下面提供思路 1.添加模型 const person reactive({modelTimer: null,position: {lon: 104.07274,lat: 30.57899,alt: 1200,heading: 0,pitch: 0,roll: 0,}, }); window.swpcesium.addEntity.addMo…

SSH 无密登录配置

1)配置 ssh (1)基本语法 ssh 另一台电脑的 IP 地址 (2)ssh 连接时出现 Host key verification failed 的解决方法 [yuxuan@yuxuan102 ~]$ ssh yuxuan103 ➢ 如果出现如下内容 Are you sure you want to continue connecting (yes/no)? ➢ 输入 yes,并回车 (3)退回到 …

简单 Web Server 程序的设计与实现 (2024)

1.题目描述 Web 服务是 Internet 最方便与受用户欢迎的服务类型&#xff0c;它的影响力也远远超出了专业技术范畴&#xff0c; 已广泛应用于电子商务、远程教育、远程医疗与信息服务等领域&#xff0c;并且有继续扩大的趋势。目前很多 的 Internet 应用都是基于 Web 技术的&…

Linux驱动学习—中断

1、中断基础概念 1.1 什么是中断 CPU在正常运行期间&#xff0c;由外部或者内部引起的时间&#xff0c;让CPU停下当前正在运行的程序&#xff0c;转而去执行触发他的中断所对应的程序&#xff0c;这就是中断。 响应中断的过程&#xff1a; <1>中断请求 <2>中断…

三、C语言中的分支与循环—for循环 (6)

本章分支结构的学习内容如下&#xff1a; 三、C语言中的分支与循环—if语句 (1) 三、C语言中的分支与循环—关系操作符 (2) 三、C语言中的分支与循环—条件操作符 与逻辑操作符(3) 三、C语言中的分支与循环—switch语句&#xff08;4&#xff09;分支结构 完 本章循环结构的…

JavaScript基本语法

文章目录 1. JavaScript 是什么1.1 JavaScript 和 HTML 和 CSS 之间的关系1.2 JavaScript 运行过程1.3 JavaScript 的组成 2. JavaScript 的书写形式2.1 行内式2.2 内嵌式2.3 外部式 3. 变量的使用3.1 静态变量和动态变量 4. 基本数据类型4.1 undefined 未定义数据类型4.2 null…

2.3_6 用信号量实现进程互斥、同步、前驱关系

2.3_6 用信号量实现进程互斥、同步、前驱关系 #mermaid-svg-fj0wp6tJGfadcT8h {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-fj0wp6tJGfadcT8h .error-icon{fill:#552222;}#mermaid-svg-fj0wp6tJGfadcT8h .error-t…

ENVI 各版本安装指南

ENVI下载链接 https://pan.baidu.com/s/1APpjHHSsrXMaCcJUQGmFBA?pwd0531 1.鼠标右击【ENVI 5.6(64bit&#xff09;】压缩包&#xff08;win11及以上系统需先点击“显示更多选项”&#xff09;选择【解压到 ENVI 5.6(64bit&#xff09;】。 2.打开解压后的文件夹&#xff0c…

mysql基础-数据操作之增删改

目录 1.新增数据 1.1单条数据新增 1.2多条数据新增 1.3查询数据新增 2.更新 2.1单值更新 2.2多值更新 2.3批量更新 2.3.1 批量-单条件更新 2.3.2批量-多条件更新 2.4 插入或更新 2.5 联表更新 3.删除 本次分享一下数据库的DML操作语言。 操作表的数据结构&#xf…

Explain详解与索引最佳实践

听课问题(听完课自己查资料) type中常用类型详细解释 null <- system <- const <- er_ref <- ref <- range <- index <- all Explain 各列解释 EXPLAIN SELECT* FROMactorLEFT JOIN film_actor ON actor_id actor.id; 1. id 代表执行的先后顺序 比如…

Python笔记01-你好Python

文章目录 Python简介环境安装Hello world开发工具 Python简介 python的诞生 1989年&#xff0c;为了打发圣诞节假期&#xff0c;Gudio van Rossum吉多 范罗苏姆&#xff08;龟叔&#xff09;决心开发一个新的解释程序&#xff08;Python雏形&#xff09; 1991年&#xff0c;第…

深度学习|交叉熵

文章目录 什么是交叉熵如何构造信息量的函数关于 C 1 C_1 C1​参数的选择关于 C 2 C_2 C2​参数的选择 一个系统的熵如何比较两个系统的熵交叉熵在神经网络中的应用参考 什么是交叉熵 熵是用来衡量一个系统的混乱程度&#xff0c;混乱程度也其实代表着整个系统内部的不确定性。…

听GPT 讲Rust源代码--compiler(15)

File: rust/compiler/rustc_arena/src/lib.rs 在Rust源代码中&#xff0c;rustc_arena/src/lib.rs文件定义了TypedArena&#xff0c;ArenaChunk&#xff0c;DroplessArena和Arena结构体&#xff0c;以及一些与内存分配和容器操作相关的函数。 cold_path<F: FnOnce,drop,new,…

解决 POST http://x.x.x.x:8000/aaa/ net::ERR_CONNECTION_TIMED_OUT

记录一下我遇到的问题和解决办法 我的项目前后端分离&#xff0c;在前端用的vue访问后端时连接不上后端&#xff0c;一切操作都触发不了后端&#xff0c;数据也传不到后端去&#xff1b; 原因&#xff1a;url有问题&#xff0c;url地址写的不是本机&#xff0c;所以导致连接超…

UE5.1_UMG序列帧动画制作

UE5.1_UMG序列帧动画制作 UMG序列帧动画制作相对比较简单&#xff0c;不像视频帧需要创建媒体播放器那么复杂&#xff0c;以下简要说明&#xff1a; 1. 事件函数 2. 准备序列帧装入数组 3. 构造调用事件函数 4. 预览 序列帧UMG0105 5. 完成&#xff01;按需配置即可。

MySQL之数据类型建表以及约束

SELECT(查询) 查询操作用于从数据库中检索数据 查询可以基于不同的条件&#xff0c;如字段值、范围、排序等 查询结果可以返回单个记录或多个记录 查询指定列 select 列名 from 表名 列名&#xff1a;代表从指定的列名中查找 , 如果是查找对应的多列&#xff0c;则用英文…

【鸿蒙4.0】安装DevEcoStudio

1.下载安装包 HUAWEI DevEco Studio和SDK下载和升级 | HarmonyOS开发者华为鸿蒙DevEco Studio是面向全场景的一站式集成开发环境,&#xff0c;在鸿蒙官网下载或升级操作系统开发工具DevEco Studio最新版本&#xff0c;SDK配置和下载&#xff0c;2.1支持Mac、Windows操作系统。…

华为MDC610接口说明

1、MDC610对外功能接口 2、1、MDC610硬件技术规格

新火种AI|三星打响“AI手机”第一枪,2024会是AI终端元年吗?

作者&#xff1a;文子 编辑&#xff1a;小迪 AI手机&#xff0c;距离取代传统手机不远了。 三星新年第一炸&#xff0c;AI手机重磅来袭 2024年才刚刚开始&#xff0c;手机行业就迎来第一个王炸。 作为常年盘踞销量全球前三的品牌&#xff0c;三星突然宣布&#xff0c;将在北…