Goby v2
serial_client.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 // credit for much of this goes to Jeff Gray-3 (http://www.nabble.com/Simple-serial-port-demonstration-with-boost-asio-asynchronous-I-O-p19849520.html)
24 
25 #ifndef SerialClient20091211H
26 #define SerialClient20091211H
27 
28 #include "client_base.h"
29 
30 namespace goby
31 {
32 namespace util
33 {
35 class SerialClient : public LineBasedClient<boost::asio::serial_port>
36 {
37  public:
43  SerialClient(const std::string& name = "", unsigned baud = 9600,
44  const std::string& delimiter = "\r\n");
45 
46  ~SerialClient() {}
47 
49  void set_name(const std::string& name) { name_ = name; }
51  void set_baud(unsigned baud) { baud_ = baud; }
52 
54  std::string name() const { return name_; }
55 
57  unsigned baud() const { return baud_; }
58 
59  boost::asio::serial_port& socket() { return serial_port_; }
61  std::string local_endpoint() { return name_; }
63  std::string remote_endpoint() { return ""; }
64 
65  private:
66  bool start_specific();
67 
68  private:
69  boost::asio::serial_port serial_port_; // the serial port this instance is connected to
70  std::string name_;
71  unsigned baud_;
72 };
73 } // namespace util
74 } // namespace goby
75 #endif
provides a basic client for line by line text based communications over a 8N1 tty (such as an RS-232 ...
Definition: serial_client.h:35
SerialClient(const std::string &name="", unsigned baud=9600, const std::string &delimiter="\r\n")
create a serial client
void set_baud(unsigned baud)
baud rate, e.g. 4800
Definition: serial_client.h:51
std::string name() const
serial port name, e.g. "/dev/ttyS0"
Definition: serial_client.h:54
std::string local_endpoint()
our serial port, e.g. "/dev/ttyUSB1"
Definition: serial_client.h:61
void set_name(const std::string &name)
set serial port name, e.g. "/dev/ttyS0"
Definition: serial_client.h:49
std::string remote_endpoint()
who knows where the serial port goes?! (empty string)
Definition: serial_client.h:63
unsigned baud() const
baud rate, e.g. 4800
Definition: serial_client.h:57
The global namespace for the Goby project.