Skip to content

Commit

Permalink
updated cmakelists and added SendString function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwatkins committed Aug 18, 2017
1 parent d7eab07 commit 90c3176
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/serial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 2.8.3)
project(serial)

find_package(catkin REQUIRED COMPONENTS)

catkin_package(
INCLUDE_DIRS include
LIBRARIES serial
)

## Check C++11 / C++0x
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
Expand Down
8 changes: 4 additions & 4 deletions src/serial/include/serial/SerialPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>

#include <boost/asio/serial_port.hpp>
#include <boost/asio.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/bind.hpp>

const int blockTimeMS = 10;

class SerialPort {
private:
boost::asio::io_service io;
boost::asio::serial_port *port;
public:
SerialPort();

int connect ();
int connect (char * device, int baud);
int connect (std::string device, int baud);
void disconnect(void);

int sendArray(unsigned char *buffer, int len);
int sendString(std::string msg);
int getArray (unsigned char *buffer, int len);
};



#endif /* SERIALPORT_H_ */
1 change: 1 addition & 0 deletions src/serial/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="emfinger@isis.vanderbilt.edu">William Emfinger</maintainer>
<maintainer email="pkumar@isis.vanderbilt.edu">Pranav Srinivas Kumar</maintainer>
<maintainer email="dexter.a.watkins@vanderbilt.edu"> Dexter Watkins </maintainer>

<!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
Expand Down
24 changes: 12 additions & 12 deletions src/serial/src/serial/SerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@

#include "serial/SerialPort.h"


SerialPort::SerialPort() {
port = new boost::asio::serial_port(io);
}

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

int SerialPort::connect(char *device, int baud) {
port->open(device);
int SerialPort::connect(std::string device, int baud) {
port->open((char *) device.c_str());
port->set_option(boost::asio::serial_port_base::baud_rate(baud));
return 1;
}

void SerialPort::disconnect(void)
{
void SerialPort::disconnect(void){
port->close();
}

int SerialPort::sendArray(unsigned char *buffer, int len) {
int n = boost::asio::write( *port,
boost::asio::buffer(buffer,len));
boost::asio::buffer(buffer,len));
return n;
}

int SerialPort::getArray (unsigned char *buffer, int len)
{
int SerialPort::sendString(std::string msg){
std::string tmp = msg + "\n";
SerialPort::sendArray((unsigned char *) tmp.c_str(), tmp.length());
}

int SerialPort::getArray (unsigned char *buffer, int len){
char rcvChar;
int i = 0;
while ( i < len && boost::asio::read( *port, boost::asio::buffer(&rcvChar,1) ) == 1 )
buffer[i++] = rcvChar;
return i;
}


0 comments on commit 90c3176

Please sign in to comment.