Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
util/liblinebasedcomms/serial_client.cpp
00001 // copyright 2009, 2010 t. schneider tes@mit.edu
00002 // 
00003 // this file is part of comms, a library for handling various communications.
00004 //
00005 // This program is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This software is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #include <iostream>
00019 
00020 #include <boost/thread.hpp>
00021 
00022 #include "serial_client.h"
00023 
00024 
00025 goby::util::SerialClient::SerialClient(const std::string& name,
00026                                        unsigned baud,
00027                                        const std::string& delimiter)
00028     : LineBasedClient<boost::asio::serial_port>(delimiter),
00029       serial_port_(io_service_),
00030       name_(name),
00031       baud_(baud)
00032 {
00033 }
00034 
00035 bool goby::util::SerialClient::start_specific()
00036 {
00037     try
00038     {
00039         serial_port_.open(name_);
00040     }
00041     catch(std::exception& e)
00042     {
00043         serial_port_.close();
00044         return false;
00045     }
00046     
00047     serial_port_.set_option(boost::asio::serial_port_base::baud_rate(baud_));
00048 
00049     // no flow control
00050     serial_port_.set_option(boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none));
00051 
00052     // 8N1
00053     serial_port_.set_option(boost::asio::serial_port_base::character_size(8));
00054     serial_port_.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none));
00055     serial_port_.set_option(boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one));
00056     
00057     return true;    
00058 }
00059 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends