Archive for the 'Code' Category

Confessions, consessions and depression

I give up.  After years of fighting everyone in my department I give up.  They win.  What am I talking about?  Which operating system to write code on.  At UAF you start of using Visual Studio, much to the dismay of many students.  Creating small single file projects with MSVS is like killing flies with a bazooka; it may get the job done but there is a lot of collateral damage.  And I am tired of picking up the pieces.

All the tools available, particularly the  ones related to my thesis, either “work” on Windows, theoretically work on Windows, or openly flame Windows.

So starting this weekend I am going to install Linux (Ubuntu most likely) and refresh myself in the ways of gcc.  Sigh.

Boost Asio Serial_Port Demo

So I’ve recently started playing with hardware more.  This necessitated learning how to communicate my C++ with the actual hardware.  The de facto method for this for decades has been the RS232 serial port.  But how to actually use this to talk with code?

In Unix you can directly talk to dev/ttyS0 or wherever the device is located.  Windows gives you some com stuff to talk to it.  But is there a way to do it cross platform?

Of course there is, otherwise I wouldn’t write about it.  Enter Boost, the pivotal C++ library.  In Boost::Asio (ASynchronous Input/Output) there exists a serial_port class.  Seems to be good enough, all that is left is to get it to work.  Easier said than done.  There are basically no examples and the doc’s aren’t very helpful (weren’t to me at least).

So here is a small program that covers most of what a serial_port class needs to do.  You set the parameters before the program starts (certain os’s have limits built in, like you must set the baud rate beforehand etc).  The hardware this talks to takes a baud rate of 19200, 8 bits of data, no parity, and 1 stop bit.  My test board only read input so the example doesn’t take input yet.  Check the comments for more details, the license is at the top of the file.

Due to the stupidity of WordPress the code format kept getting eaten so you have to download the file instead.

Link to file: boost_serial_port_demo.cpp