ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

What is the best way for recieving data through serial port in hydro?

asked 2013-12-09 08:43:48 -0600

mr.karimi gravatar image

updated 2014-01-28 17:07:31 -0600

ngrennan gravatar image

What is the best way for recieving data through serial port in hydro? Does hydro supports cereal_port package?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-12-09 10:40:32 -0600

mjcarroll gravatar image

updated 2014-02-28 07:10:38 -0600

William gravatar image

If you are looking to write a device driver, then you probably just want a serial library. This depends on the language that you want to use.

For Python, I would use pyserial.

In C++, I would recommend @William's serial library. It has an API similar to pyserial, and it is cross-platform and well maintained. I have used it in several projects.

If you are looking to communicate with an Arduino or embedded linux, then stick to rosserial

edit flag offensive delete link more

Comments

Thank you very much! :)

mr.karimi gravatar image mr.karimi  ( 2013-12-12 20:34:35 -0600 )edit

excuse me , i write a simple program but it doesn't work! my program : #include "serial/serial.h" #include "ros/ros.h" int main(int argc,char **argv) { ros::init(argc,argv,"serial") ; ros::NodeHandle nh ; serial::Serial my_serial("dev/ttyUSB0",9600,serial::Timeout::simpleTimeout(1000),serial::eightbits,serial::parity_none,serial::stopbits_one,serial::flowcontrol_none); ROS_INFO_STREAM("Is Serial Port Open?"); if(my_serial.isOpen()) ROS_INFO_STREAM("Yes"); else ROS_INFO_STREAM("No"); } and I got these errors : CMakeFiles/serial.dir/serial.cpp.o: In function `main': /home/mohammad/ros_workspace/serial_test3/serial.cpp:8: undefined reference to `serial::Serial::Serial(std::string const&, unsigned int, serial::Timeout, serial::bytesize_t, serial::parity_t, serial::stopbits_t, serial::flowcontrol_t)' /home/mohammad/ros_workspace/serial_test3/serial.cpp:10: undefined reference to `serial::Serial::isOpen() const' /home/mohammad/ros_workspace/serial_tes

mr.karimi gravatar image mr.karimi  ( 2013-12-13 04:42:17 -0600 )edit

i think i should add a link to serial library but i don't know how!

mr.karimi gravatar image mr.karimi  ( 2013-12-13 05:18:48 -0600 )edit

You likely need to add the serial library to your package.xml and CMakeLists.txt file, so that you can find it in your package. Here is an example of a motor controller driver using the serial library: https://github.com/wjwwood/ax2550

mjcarroll gravatar image mjcarroll  ( 2013-12-13 09:20:50 -0600 )edit

I'm sorry for my delay(I got a bad cold!) I wrote another program but when i compiled it with catkin_make , it wrote this message in red color : "Linking CXX executable /home/mohammad/ros_workspace/devel/lib/first_test/serial " is it an error? and when i write "rosrun first_test serial" , it says : "[rosrun] Couldn't find executable named serial below /home/mohammad/ros_workspace/src/first_test "

mr.karimi gravatar image mr.karimi  ( 2013-12-19 06:50:22 -0600 )edit

and please see my CMakeList.txt file , is it correct? " cmake_minimum_required(VERSION 2.8.3) project(first_test) find_package(catkin REQUIRED roscpp serial) catkin_package( INCLUDE_DIRS LIBRARIES first_test CATKIN_DEPENDS serial ) include_directories(include ${catkin_INCLUDE_DIRS}) add_executable(serial serial.cpp) target_link_libraries(serial ${catkin_LIBRARIES} ${serial_LIBRARIES}) "

mr.karimi gravatar image mr.karimi  ( 2013-12-19 06:54:17 -0600 )edit

now it doesn't show that message but when i want to run it , this message shows : [rosrun] Couldn't find executable named serial below /home/mohammad/ros_workspace/src/first_test "

mr.karimi gravatar image mr.karimi  ( 2013-12-19 08:55:08 -0600 )edit

Finally I did it! Thank you very much , it was very helpful! :)

mr.karimi gravatar image mr.karimi  ( 2013-12-21 17:26:52 -0600 )edit
4

answered 2013-12-09 10:30:23 -0600

updated 2013-12-09 10:31:10 -0600

rosserial, depending on what you're doing.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-12-09 08:43:48 -0600

Seen: 1,207 times

Last updated: Feb 28 '14