Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
cmake_minimum_required(VERSION 2.8.3...3.10)
project(serial)
project(serial_cpp)

if(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
endif()

## Sources
set(serial_SRCS
set(serial_cpp_SRCS
src/serial.cc
include/serial/serial.h
include/serial/v8stdint.h
include/serial_cpp/serial.h
include/serial_cpp/v8stdint.h
)
if(APPLE)
# If OSX
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
list(APPEND serial_cpp_SRCS src/impl/unix.cc)
list(APPEND serial_cpp_SRCS src/impl/list_ports/list_ports_osx.cc)
elseif(UNIX)
# If unix
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
list(APPEND serial_cpp_SRCS src/impl/unix.cc)
list(APPEND serial_cpp_SRCS src/impl/list_ports/list_ports_linux.cc)
else()
# If windows
list(APPEND serial_SRCS src/impl/win.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
list(APPEND serial_cpp_SRCS src/impl/win.cc)
list(APPEND serial_cpp_SRCS src/impl/list_ports/list_ports_win.cc)
endif()

## Add serial library
add_library(${PROJECT_NAME} ${serial_SRCS})
add_library(${PROJECT_NAME} ${serial_cpp_SRCS})
if(APPLE)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
Expand All @@ -37,9 +37,9 @@ else()
endif()

## Uncomment for example
add_executable(serial_example examples/serial_example.cc)
add_dependencies(serial_example ${PROJECT_NAME})
target_link_libraries(serial_example ${PROJECT_NAME})
add_executable(serial_cpp_example examples/serial_cpp_example.cc)
add_dependencies(serial_cpp_example ${PROJECT_NAME})
target_link_libraries(serial_cpp_example ${PROJECT_NAME})

## Include headers
include_directories(include)
Expand All @@ -52,17 +52,17 @@ install(TARGETS ${PROJECT_NAME}
)

## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h
install(FILES include/serial_cpp/serial.h include/serial/v8stdint.h
DESTINATION include/serial)

## Install CMake config
install(FILES cmake/serialConfig.cmake
DESTINATION share/serial/cmake)
install(FILES cmake/serial_cppConfig.cmake
DESTINATION share/serial_cpp/cmake)


## Install package.xml
install(FILES package.xml
DESTINATION share/serial)
DESTINATION share/serial_cpp)

## Tests
include(CTest)
Expand Down
61 changes: 26 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,54 @@
# Serial Communication Library

[![Build Status](https://travis-ci.org/wjwwood/serial.svg?branch=master)](https://travis-ci.org/wjwwood/serial)*(Linux and OS X)* [![Build Status](https://ci.appveyor.com/api/projects/status/github/wjwwood/serial)](https://ci.appveyor.com/project/wjwwood/serial)*(Windows)*
# `serial_cpp` Serial Communication Library

This is a cross-platform library for interfacing with rs-232 serial like ports written in C++. It provides a modern C++ interface with a workflow designed to look and feel like PySerial, but with the speed and control provided by C++.

This library is in use in several robotics related projects and can be built and installed to the OS like most unix libraries with make and then sudo make install, but because it is a catkin project it can also be built along side other catkin projects in a catkin workspace.

Serial is a class that provides the basic interface common to serial libraries (open, close, read, write, etc..) and requires no extra dependencies. It also provides tight control over timeouts and control over handshaking lines.

### Documentation
Serial is a class that provides the basic interface common to serial libraries (open, close, read, write, etc..) and requires no extra dependencies. It also provides tight control over timeouts and control over handshaking lines.

Website: http://wjwwood.github.io/serial/
`serial_cpp` started as a friendly fork [`wjwwood/serial`](https://github.com/wjwwood/serial), see https://github.com/wjwwood/serial/issues/312 for more details.

API Documentation: http://wjwwood.github.io/serial/doc/1.1.0/index.html
> [!NOTE]
> Most projects in the [`ami-iit`](https://github.com/ami-iit) use the dash (`-`) as a separator inside names. This repo makes an exception as it is a derivation of a project originally started in the ROS community, where the use of underscore (`_`) is tipically used, and so the original mantainer asked to keep an underscore, see https://github.com/wjwwood/serial/issues/312#issuecomment-2773775993 .

### Dependencies

Required:
* [catkin](http://www.ros.org/wiki/catkin) - cmake and Python based buildsystem
* C++ compiler
* [cmake](http://www.cmake.org) - buildsystem
* [Python](http://www.python.org) - scripting language
* [empy](http://www.alcyone.com/pyos/empy/) - Python templating library
* [catkin_pkg](http://pypi.python.org/pypi/catkin_pkg/) - Runtime Python library for catkin

Optional (for documentation):
* [Doxygen](http://www.doxygen.org/) - Documentation generation tool
* [graphviz](http://www.graphviz.org/) - Graph visualization software

### Install

Get the code:

git clone https://github.com/wjwwood/serial.git
### Usage compiling from source

Build:
First compile the project:

make
~~~bash
git clone https://github.com/ami-iit/serial_cpp.git
cd serial_cpp
cmake -DCMAKE_BUILD_TYPE=Release -Bbuild -S. -DCMAKE_INSTALL_PREFIX=<desired_install_dir>
cmake --build build
cmake --install build
~~~

Build and run the tests:
### Development commands

make test
`serial_cpp` is a pure C++ project that can be installed on any system, as long as CMake is available. However, we use [`pixi`](https://pixi.sh) to simplify development, to run the tests (the same run in CI) in pixi, run:

Build the documentation:

make doc

Install:

make install
~~~
git clone https://github.com/ami-iit/serial_cpp.git
pixi run test
~~~

### License

[The MIT License](LICENSE)

### Authors
### Mantainers

William Woodall <wjwwood@gmail.com>
John Harrison <ash.gti@gmail.com>
* Silvio Traversaro ([@traversaro](https://github.com/traversaro))

### Contact
### Authors

William Woodall <william@osrfoundation.org>
* William Woodall <wjwwood@gmail.com>
* John Harrison <ash.gti@gmail.com>
6 changes: 3 additions & 3 deletions doc/serial.dox
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Want to use it with ROS(Robot Operating System)? No problem, it compiles as a un

Ready to jump in?
- Checkout our examples: \ref serial_example.cc
- Look at the main class documentation: \ref serial::Serial
- Look at the main class documentation: \ref serial_cpp::Serial

\section features Features
- Linux, Mac OS X, and Windows Support
- Easy to use interface (modeled after PySerial)
- Minimal dependencies (cmake)
- Complete timeout control \ref serial::Serial::setTimeout
- Complete timeout control \ref serial_cpp::Serial::setTimeout
- Check and set handshaking lines (CTS, DSR, RI, CD and RTS, DTR)
- Block for changes in handshaking lines (Linux and Windows)
- Flush I/O separately and block until all writing done
Expand All @@ -32,7 +32,7 @@ Ready to jump in?

\subsection building Compiling

Once you have gathered the dependencies, you need to checkout the software from github.com:
Once you have gathered the dependencies, you need to checkout the software from github.com:

<pre>
git clone git://github.com/wjwwood/serial.git
Expand Down
12 changes: 6 additions & 6 deletions examples/serial_example.cc → examples/serial_cpp_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <unistd.h>
#endif

#include "serial/serial.h"
#include <serial_cpp/serial.h>

using std::string;
using std::exception;
Expand All @@ -46,13 +46,13 @@ void my_sleep(unsigned long milliseconds) {

void enumerate_ports()
{
vector<serial::PortInfo> devices_found = serial::list_ports();
vector<serial_cpp::PortInfo> devices_found = serial_cpp::list_ports();

vector<serial::PortInfo>::iterator iter = devices_found.begin();
vector<serial_cpp::PortInfo>::iterator iter = devices_found.begin();

while( iter != devices_found.end() )
{
serial::PortInfo device = *iter++;
serial_cpp::PortInfo device = *iter++;

printf( "(%s, %s, %s)\n", device.port.c_str(), device.description.c_str(),
device.hardware_id.c_str() );
Expand Down Expand Up @@ -93,7 +93,7 @@ int run(int argc, char **argv)
#endif

// port, baudrate, timeout in milliseconds
serial::Serial my_serial(port, baud, serial::Timeout::simpleTimeout(1000));
serial_cpp::Serial my_serial(port, baud, serial_cpp::Timeout::simpleTimeout(1000));

cout << "Is the serial port open?";
if(my_serial.isOpen())
Expand Down Expand Up @@ -125,7 +125,7 @@ int run(int argc, char **argv)
}

// Test the timeout at 250ms
my_serial.setTimeout(serial::Timeout::max(), 250, 0, 250, 0);
my_serial.setTimeout(serial_cpp::Timeout::max(), 250, 0, 250, 0);
count = 0;
cout << "Timeout == 250ms, asking for 1 more byte than written." << endl;
while (count < 10) {
Expand Down
12 changes: 6 additions & 6 deletions include/serial/impl/unix.h → include/serial_cpp/impl/unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@
#ifndef SERIAL_IMPL_UNIX_H
#define SERIAL_IMPL_UNIX_H

#include "serial/serial.h"
#include "serial_cpp/serial.h"

#include <pthread.h>

namespace serial {
namespace serial_cpp {

using std::size_t;
using std::string;
using std::invalid_argument;

using serial::SerialException;
using serial::IOException;
using serial_cpp::SerialException;
using serial_cpp::IOException;

class MillisecondTimer {
public:
MillisecondTimer(const uint32_t millis);
MillisecondTimer(const uint32_t millis);
int64_t remaining();

private:
static timespec timespec_now();
timespec expiry;
};

class serial::Serial::SerialImpl {
class serial_cpp::Serial::SerialImpl {
public:
SerialImpl (const string &port,
unsigned long baudrate,
Expand Down
10 changes: 5 additions & 5 deletions include/serial/impl/win.h → include/serial_cpp/impl/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
#ifndef SERIAL_IMPL_WINDOWS_H
#define SERIAL_IMPL_WINDOWS_H

#include "serial/serial.h"
#include "serial_cpp/serial.h"

#include "windows.h"

namespace serial {
namespace serial_cpp {

using std::string;
using std::wstring;
using std::invalid_argument;

using serial::SerialException;
using serial::IOException;
using serial_cpp::SerialException;
using serial_cpp::IOException;

class serial::Serial::SerialImpl {
class serial_cpp::Serial::SerialImpl {
public:
SerialImpl (const string &port,
unsigned long baudrate,
Expand Down
Loading