Serial port classes moved to Gitorious

When I first published this article about using serial port with C++ I didn’t expect it to become one of the main reasons people visit my website. Over time, thanks to many comments, bug reports and suggestion, the serial port classes have been modified significantly, to the point that releasing them in a .tar.gz file is no longer a good idea. I’ve therefore decided to create a git repository at where you can get the latest version of my serial port classes.


7 Responses to “Serial port classes moved to Gitorious”

  1. bluehash Says:

    Thanks for your work:)

  2. James Says:

    Thanks very much for your excellent and most useful classes =]
    I just have a question regarding the callback version. I am currently having issues getting multithreaded mutexs to work as I would like, and I have just visited the original article again and noticed that you said “This is why proper mutexing for synchronization might be required.”
    Are there any code examples showing proper implementation with mutexs? Just FYI, I am implementing the serial to communicate with a microcontroller, but I already have a second thread, depended on the results of communication.

  3. fedetft Says:

    I don’t have code examples, but the idea is that the callback is called from a backgroud thread, so if the callback modifies some data structures in your code, such as doing a push_back() of the received data in a vector to store received lines, you have to lock a mutex in the callback (and also in the code from your main thread that accesses that vector) to prevent race conditions.

  4. luan78zao Says:

    thanks for your efforts and providing the code!

    Some comments and a question:

    The link to at is not valid anymore. It seems it has changed to

    In the gitorius repository, in the iostreams code, in main.cpp a “}” is missing somewhere (probably in the “try” block, at least, my compiler is complaining.
    I inserted it before the first catch statement.

    However, I have a problem communicating with my device which executes the commands only every second time I run the code: I just copy/pasted your iostreams example into Codelite, changed the “Hello World” into somethig my device understands, compiled and ran the stuff. Also, it seems that the device is receiving the data only when a timeout happens (when I set the timeout to 10s, the instructions are executed 10s after starting the program), and I do not receive any reply from my device. With a terminal program (GTK-term), communication works.

    I am sending stuff like “/14WR\r” (an init command, I changed the endl into “\r”) and expect to receive replies like “/0′” (the device expects CR at the end of an instruction and is replying with CRLF).

    If of any importance, I am working with Xubuntu 14.04 LTE, Codelite 6.0, boost 1.54 and connect the device via /dev/ttyUSB0 and and HL-340 USB to serial converter which is recognized by the kernel automatically.

    Many thanks and all the best


  5. fedetft Says:

    Thanks for the comment, I fixed the missing } bug, apparently the old GCC failed to notice it and compiled the code anyway.

    For the timeout prblem, it may be a buffering issue. If the incoming data is not properly terminated (through \n or \r\n) try using the istream read() function if you know the exact number of bytes of the message, or readsome() ( otherwise.

  6. Olivier Says:

    thank you so much for all your efforts and the great code, though I’m having some issues getting the classes from and it seemed like it migrated somewhere else and I can’t find it in the new place. If you know the new location of the source files could you please send me an email with the link and/or update the article with the new link?

    Thanks again, your article has been a great help for my project!

  7. fedetft Says:

    Yes, gitorious disappearing was a bad news for me. I’ll make a post someday about where I moved my stuff (short answer, partly on a private git server on, and partly on github). The serial port classes end up on github, here:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: