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 http://gitorious.org/serial-port where you can get the latest version of my serial port classes.

About these ads

5 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.
    Thanks!

  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:

    Hi,
    thanks for your efforts and providing the code!

    Some comments and a question:

    The link to http://www.nabble.com/Simple-serial-port-demonstration-with-boost-asio-asynchronous-I-O-td19849520.html at http://www.webalice.it/fede.tft/serial_port/serial_port.html is not valid anymore. It seems it has changed to http://boost.2283326.n4.nabble.com/Simple-serial-port-demonstration-with-boost-asio-asynchronous-I-O-td2582657.html

    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

    Wo

  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() (http://www.cplusplus.com/reference/istream/istream/readsome) otherwise.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 30 other followers

%d bloggers like this: