-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated serial library from lib-dynamixel.
- Loading branch information
William Emfinger
committed
Apr 17, 2016
1 parent
338b1d6
commit 0eeab97
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(serial) | ||
|
||
## Check C++11 / C++0x | ||
include(CheckCXXCompilerFlag) | ||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) | ||
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) | ||
if(COMPILER_SUPPORTS_CXX11) | ||
set(CMAKE_CXX_FLAGS "-std=c++11") | ||
elseif(COMPILER_SUPPORTS_CXX0X) | ||
set(CMAKE_CXX_FLAGS "-std=c++0x") | ||
else() | ||
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") | ||
endif() | ||
|
||
include_directories(include) | ||
add_library(serial | ||
src/dynamixel/SerialPort.cpp) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef SERIALPORT_H_ | ||
#define SERIALPORT_H_ | ||
|
||
#include <stdio.h> | ||
#include <termios.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
#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); | ||
void disconnect(void); | ||
|
||
int sendArray(unsigned char *buffer, int len); | ||
int getArray (unsigned char *buffer, int len); | ||
}; | ||
|
||
|
||
#endif /* SERIALPORT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<package> | ||
<name>serial</name> | ||
<version>1.0.0</version> | ||
<description>Package for interfacing with serial devices.</description> | ||
|
||
<!-- One maintainer tag required, multiple allowed, one person per tag --> | ||
<!-- Example: --> | ||
<!-- <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> | ||
|
||
<!-- One license tag required, multiple allowed, one license per tag --> | ||
<!-- Commonly used license strings: --> | ||
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --> | ||
<license>MIT</license> | ||
<buildtool_depend>catkin</buildtool_depend> | ||
<export> | ||
</export> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <string.h> | ||
#include <sys/ioctl.h> | ||
|
||
#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); | ||
port->set_option(boost::asio::serial_port_base::baud_rate(baud)); | ||
return 1; | ||
} | ||
|
||
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)); | ||
return n; | ||
} | ||
|
||
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; | ||
} | ||
|