wjwwood / serial

Cross-platform, Serial Port library written in C++
http://wjwwood.github.com/serial/
MIT License
2.11k stars 1.03k forks source link

fatal error: serial/serial.h: no such file or directory in ros #207

Closed Massyp closed 3 years ago

Massyp commented 5 years ago

Hello evrybody,

I'm using ROS kenetic and I'm trying to read data from serial port of my laptop. For this I use the code below and I use the header file serial.h to instantiate my serial object. When I execute Catkin_make it return' me this error :

/home/stage/catkin_ws/src/mon_noeud/src/Imu_node.cpp:2:27: fatal error: serial/serial.h: No such file or directory compilation terminated. mon_noeud/CMakeFiles/Imu_node.dir/build.make:62: recipe for target 'mon_noeud/CMakeFiles/Imu_node.dir/src/Imu_node.cpp.o' failed make[2]: ** [mon_noeud/CMakeFiles/Imu_node.dir/src/Imu_node.cpp.o] Error 1 CMakeFiles/Makefile2:3488: recipe for target 'mon_noeud/CMakeFiles/Imu_node.dir/all' failed make[1]: [mon_noeud/CMakeFiles/Imu_node.dir/all] Error 2 Makefile:138: recipe for target 'all' failed make: * [all] Error 2

I hope someone can help me with this ` #include <ros/ros.h>

include <serial/serial.h>

    #include <std_msgs/String.h>
    #include <std_msgs/Empty.h>

serial::Serial ser;

int main(int argc, char** argv){

ros::init(argc,argc,"Imu_node");
ros::NodeHandle nh;
ros::Publisher read_port = nh.advertise<std_msgs::String>("read", 1000);
ros::Rate loop_rate(200);

try 
{
    ser.setPort("/dev/ttyACM0");
    ser.setBaudrate(9600);
    serial::Timeout to = serial::Timeout::simpleTimeout(1000);
    ser.setTimeout(to);
    ser.open();
 }
 catch (serial::IOException& e)
 {
   ROS_ERROR_STREAM("Unable to open port ");
    return -1;
 }

 if(ser.isOpen()){
     ROS_INFO_STREAM("serial port initialized");
} 
else{
       return -1;
       }

 while(ros::ok()){

 if(ser.available()){
     ROS_INFO_STREAM("reading from serial port ");
     std_msgs::String result;
     result.data = ser.read(ser.available());
    ROS_INFO_STREAM("Read: " << result.data);
    read_pub.publish(result);

                   }

     ros::spinOnce();
     r.sleep();
                } 

 }`

the following code is the cmakelist.txt code, I don't knew how to add the serial dependence to this list : `cmake_minimum_required(VERSION 2.8.3) project(mon_noeud) find_package(catkin REQUIRED COMPONENTS message_generation message_runtime roscpp rospy )

include_directories( include ${catkin_INCLUDE_DIRS}) add_executable(Imu_node src/Imu_node.cpp) target_link_libraries(Imu_node ${catkin_LIBRARIES}) add_dependencies(Imu_node mon_noeud_generate_messages_cpp)`

and this one for the package.xml :

` mon_noeud0.0.0The mon_noeud packagestageTODO

catkinmessage_generationmessage_generationroscpprospyroscpprospymessage_runtimeroscpprospy`
wjwwood commented 3 years ago

I'm going to close this because it is old, but please comment and I can reopen if needed.