Skip to content

Commit 90c3176

Browse files
author
Dwatkins
committed
updated cmakelists and added SendString function
1 parent d7eab07 commit 90c3176

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

src/serial/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(serial)
33

4+
find_package(catkin REQUIRED COMPONENTS)
5+
6+
catkin_package(
7+
INCLUDE_DIRS include
8+
LIBRARIES serial
9+
)
10+
411
## Check C++11 / C++0x
512
include(CheckCXXCompilerFlag)
613
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)

src/serial/include/serial/SerialPort.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55
#include <termios.h>
66
#include <fcntl.h>
77
#include <unistd.h>
8+
#include <string>
89

910
#include <boost/asio/serial_port.hpp>
1011
#include <boost/asio.hpp>
1112
#include <boost/asio/deadline_timer.hpp>
1213
#include <boost/bind.hpp>
1314

14-
const int blockTimeMS = 10;
15-
1615
class SerialPort {
1716
private:
1817
boost::asio::io_service io;
1918
boost::asio::serial_port *port;
2019
public:
2120
SerialPort();
2221

23-
int connect ();
24-
int connect (char * device, int baud);
22+
int connect (std::string device, int baud);
2523
void disconnect(void);
2624

2725
int sendArray(unsigned char *buffer, int len);
26+
int sendString(std::string msg);
2827
int getArray (unsigned char *buffer, int len);
2928
};
3029

3130

31+
3232
#endif /* SERIALPORT_H_ */

src/serial/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
1010
<maintainer email="[email protected]">William Emfinger</maintainer>
1111
<maintainer email="[email protected]">Pranav Srinivas Kumar</maintainer>
12+
<maintainer email="[email protected]"> Dexter Watkins </maintainer>
1213

1314
<!-- One license tag required, multiple allowed, one license per tag -->
1415
<!-- Commonly used license strings: -->

src/serial/src/serial/SerialPort.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@
33

44
#include "serial/SerialPort.h"
55

6+
67
SerialPort::SerialPort() {
78
port = new boost::asio::serial_port(io);
89
}
910

10-
int SerialPort::connect() {
11-
port->open("/dev/ttyO5");
12-
port->set_option(boost::asio::serial_port_base::baud_rate(9600));
13-
return 1;
14-
}
1511

16-
int SerialPort::connect(char *device, int baud) {
17-
port->open(device);
12+
int SerialPort::connect(std::string device, int baud) {
13+
port->open((char *) device.c_str());
1814
port->set_option(boost::asio::serial_port_base::baud_rate(baud));
1915
return 1;
2016
}
2117

22-
void SerialPort::disconnect(void)
23-
{
18+
void SerialPort::disconnect(void){
2419
port->close();
2520
}
2621

2722
int SerialPort::sendArray(unsigned char *buffer, int len) {
2823
int n = boost::asio::write( *port,
29-
boost::asio::buffer(buffer,len));
24+
boost::asio::buffer(buffer,len));
3025
return n;
3126
}
3227

33-
int SerialPort::getArray (unsigned char *buffer, int len)
34-
{
28+
int SerialPort::sendString(std::string msg){
29+
std::string tmp = msg + "\n";
30+
SerialPort::sendArray((unsigned char *) tmp.c_str(), tmp.length());
31+
}
32+
33+
int SerialPort::getArray (unsigned char *buffer, int len){
3534
char rcvChar;
3635
int i = 0;
3736
while ( i < len && boost::asio::read( *port, boost::asio::buffer(&rcvChar,1) ) == 1 )
3837
buffer[i++] = rcvChar;
3938
return i;
4039
}
4140

41+

0 commit comments

Comments
 (0)