Ask Your Question

Python or C++ for serial communication

asked 2012-04-15 07:51:36 -0500

mrtc gravatar image

updated 2014-01-28 17:11:58 -0500

ngrennan gravatar image

I've created a node which uses the PySerial library to communicate with an XBee module wirelessly. The only occasional issue I encounter is dropped communication, which I resolved by just setting the node to auto-respawn in the launch file.

It did get me thinking though. I'm not a programming expert so I'm not sure what sort of overhead behind the scenes I'm encountering when I use python to perform serial communication.

My question is would it be better in the long run to use C++ for serial communication (ie would computations be faster, more reliable, etc.) over Python?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-04-15 08:17:14 -0500

Kevin gravatar image

I prefer C/C++, but I don't think it really matters for serial comm. If you are comfortable with Python and it does what you want, then I would stick with it. If you really want to learn C/C++ then go for it. It really depends on what you want to do. My understanding is Python is already highly optimized, so I doubt you are really missing anything.

edit flag offensive delete link more


That's great to hear. I think I got a good handle on C/C++ but why reinvent the wheel right?

mrtc gravatar image mrtc  ( 2012-04-16 04:48:21 -0500 )edit

If you use C++, I strongly suggest using boost::asio for serial communication. It is not the easiest library to use, but it saves you from reinventing the entire wheel (i.e. setting up the serial port). In any case, you can't go wrong going with PySerial.

mkoval gravatar image mkoval  ( 2012-04-16 10:23:44 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-04-15 07:51:36 -0500

Seen: 1,756 times

Last updated: Apr 15 '12