From cbcca7c83745fedd75afb7a0a27ee5c4112435c2 Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Mon, 6 Jan 2020 11:15:17 -0800 Subject: [PATCH 1/9] Install serial library to a portable location. (#216) --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1474ad..4927020 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ include_directories(include) install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} ) ## Install headers From 9e331e7977f98e7e007e1bc3e8951413a7e0ec70 Mon Sep 17 00:00:00 2001 From: Chenchen Date: Fri, 11 Jun 2021 05:49:29 +0800 Subject: [PATCH 2/9] fix invalid memory access when eol size >1 (#220) Co-authored-by: chenguojun --- src/serial.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/serial.cc b/src/serial.cc index 37b5d70..a9e6f84 100755 --- a/src/serial.cc +++ b/src/serial.cc @@ -188,6 +188,7 @@ Serial::readline (string &buffer, size_t size, string eol) if (bytes_read == 0) { break; // Timeout occured on reading 1 byte } + if(read_so_far < eol_len) continue; if (string (reinterpret_cast (buffer_ + read_so_far - eol_len), eol_len) == eol) { break; // EOL found @@ -229,6 +230,7 @@ Serial::readlines (size_t size, string eol) } break; // Timeout occured on reading 1 byte } + if(read_so_far < eol_len) continue; if (string (reinterpret_cast (buffer_ + read_so_far - eol_len), eol_len) == eol) { // EOL found From 7439db1228997916659afd82284b9094e11126eb Mon Sep 17 00:00:00 2001 From: Hannes Kamecke Date: Thu, 10 Jun 2021 23:57:28 +0200 Subject: [PATCH 3/9] Fix windows com port prefix (#179) The check in `_prefix_port_if_needed` does not work, as it's currently comparing the whole input string to the prefix. As a consequence, port strings will be prefixed, even if they're already prefixed. This commit changes the call to `wstring::compare` to use an overload that compares a substring of the input string only. --- src/impl/win.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl/win.cc b/src/impl/win.cc index 786f4f6..889e06f 100644 --- a/src/impl/win.cc +++ b/src/impl/win.cc @@ -24,7 +24,7 @@ inline wstring _prefix_port_if_needed(const wstring &input) { static wstring windows_com_port_prefix = L"\\\\.\\"; - if (input.compare(windows_com_port_prefix) != 0) + if (input.compare(0, windows_com_port_prefix.size(), windows_com_port_prefix) != 0) { return windows_com_port_prefix + input; } From a93fc844d9ff58d26c1bbd93cf3b799b57cd13ee Mon Sep 17 00:00:00 2001 From: Atomie CHEN Date: Fri, 11 Jun 2021 05:57:40 +0800 Subject: [PATCH 4/9] Solve issue Custom Baudrate OSX #139 of original repo; inspired by PySerial source code and #57 of github.com/npat-efault/picocom, we need to set custom baudrate after calling tcsetattr; tested on macOS Mojave 10.14.4 (#218) --- src/impl/unix.cc | 65 ++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/impl/unix.cc b/src/impl/unix.cc index 4309aa6..b656a56 100755 --- a/src/impl/unix.cc +++ b/src/impl/unix.cc @@ -304,36 +304,6 @@ Serial::SerialImpl::reconfigurePort () #endif default: custom_baud = true; - // OS X support -#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4) - // Starting with Tiger, the IOSSIOSPEED ioctl can be used to set arbitrary baud rates - // other than those specified by POSIX. The driver for the underlying serial hardware - // ultimately determines which baud rates can be used. This ioctl sets both the input - // and output speed. - speed_t new_baud = static_cast (baudrate_); - if (-1 == ioctl (fd_, IOSSIOSPEED, &new_baud, 1)) { - THROW (IOException, errno); - } - // Linux Support -#elif defined(__linux__) && defined (TIOCSSERIAL) - struct serial_struct ser; - - if (-1 == ioctl (fd_, TIOCGSERIAL, &ser)) { - THROW (IOException, errno); - } - - // set custom divisor - ser.custom_divisor = ser.baud_base / static_cast (baudrate_); - // update flags - ser.flags &= ~ASYNC_SPD_MASK; - ser.flags |= ASYNC_SPD_CUST; - - if (-1 == ioctl (fd_, TIOCSSERIAL, &ser)) { - THROW (IOException, errno); - } -#else - throw invalid_argument ("OS does not currently support custom bauds"); -#endif } if (custom_baud == false) { #ifdef _BSD_SOURCE @@ -443,6 +413,41 @@ Serial::SerialImpl::reconfigurePort () // activate settings ::tcsetattr (fd_, TCSANOW, &options); + // apply custom baud rate, if any + if (custom_baud == true) { + // OS X support +#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4) + // Starting with Tiger, the IOSSIOSPEED ioctl can be used to set arbitrary baud rates + // other than those specified by POSIX. The driver for the underlying serial hardware + // ultimately determines which baud rates can be used. This ioctl sets both the input + // and output speed. + speed_t new_baud = static_cast (baudrate_); + // PySerial uses IOSSIOSPEED=0x80045402 + if (-1 == ioctl (fd_, IOSSIOSPEED, &new_baud, 1)) { + THROW (IOException, errno); + } + // Linux Support +#elif defined(__linux__) && defined (TIOCSSERIAL) + struct serial_struct ser; + + if (-1 == ioctl (fd_, TIOCGSERIAL, &ser)) { + THROW (IOException, errno); + } + + // set custom divisor + ser.custom_divisor = ser.baud_base / static_cast (baudrate_); + // update flags + ser.flags &= ~ASYNC_SPD_MASK; + ser.flags |= ASYNC_SPD_CUST; + + if (-1 == ioctl (fd_, TIOCSSERIAL, &ser)) { + THROW (IOException, errno); + } +#else + throw invalid_argument ("OS does not currently support custom bauds"); +#endif + } + // Update byte_time_ based on the new settings. uint32_t bit_time_ns = 1e9 / baudrate_; byte_time_ns_ = bit_time_ns * (1 + bytesize_ + parity_ + stopbits_); From 57f72772a93d6cc8afcd0a6f67d999ff2ca29dd4 Mon Sep 17 00:00:00 2001 From: Matthias Behr Date: Fri, 11 Jun 2021 00:13:58 +0200 Subject: [PATCH 5/9] Add EINTR handling to SerialImpl::write (#233) EINTR can still happen on write. Don't throw the exception in that case but retry. In case of other errors add more details to the SerialException. --- src/impl/unix.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/impl/unix.cc b/src/impl/unix.cc index b656a56..a40b0fa 100755 --- a/src/impl/unix.cc +++ b/src/impl/unix.cc @@ -665,14 +665,27 @@ Serial::SerialImpl::write (const uint8_t *data, size_t length) // This will write some ssize_t bytes_written_now = ::write (fd_, data + bytes_written, length - bytes_written); + + // even though pselect returned readiness the call might still be + // interrupted. In that case simply retry. + if (bytes_written_now == -1 && errno == EINTR) { + continue; + } + // write should always return some data as select reported it was // ready to write when we get to this point. if (bytes_written_now < 1) { // Disconnected devices, at least on Linux, show the // behavior that they are always ready to write immediately // but writing returns nothing. - throw SerialException ("device reports readiness to write but " - "returned no data (device disconnected?)"); + std::stringstream strs; + strs << "device reports readiness to write but " + "returned no data (device disconnected?)"; + strs << " errno=" << errno; + strs << " bytes_written_now= " << bytes_written_now; + strs << " bytes_written=" << bytes_written; + strs << " length=" << length; + throw SerialException(strs.str().c_str()); } // Update bytes_written bytes_written += static_cast (bytes_written_now); From 9fc9e81fc1676215a7fef5b07fee3fa638eda525 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 10 Jun 2021 15:14:20 -0700 Subject: [PATCH 6/9] Remove Boost dependency (#235) It wasn't being used so there's no need to depend on it. Signed-off-by: Jacob Perron --- README.md | 3 --- package.xml | 2 -- tests/CMakeLists.txt | 2 +- tests/unix_serial_tests.cc | 2 -- 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 3f99507..d17f7b1 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,6 @@ Required: * [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 tests): -* [Boost](http://www.boost.org/) - Boost C++ librairies - Optional (for documentation): * [Doxygen](http://www.doxygen.org/) - Documentation generation tool * [graphviz](http://www.graphviz.org/) - Graph visualization software diff --git a/package.xml b/package.xml index 27781e1..959f9b8 100644 --- a/package.xml +++ b/package.xml @@ -21,6 +21,4 @@ catkin - boost - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e52a4d3..ac9a421 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,6 @@ if(UNIX) catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc) - target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES}) + target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) if(NOT APPLE) target_link_libraries(${PROJECT_NAME}-test util) endif() diff --git a/tests/unix_serial_tests.cc b/tests/unix_serial_tests.cc index 26ffde2..c34868a 100644 --- a/tests/unix_serial_tests.cc +++ b/tests/unix_serial_tests.cc @@ -20,8 +20,6 @@ void loop() #include #include "gtest/gtest.h" -#include - // Use FRIEND_TEST... its not as nasty, thats what friends are for // // OMG this is so nasty... // #define private public From ed9f89ca31ab27c99f3f9a0e188d82ec792242c5 Mon Sep 17 00:00:00 2001 From: Robin Krens <51459952+robinkrens@users.noreply.github.com> Date: Fri, 11 Jun 2021 00:14:48 +0200 Subject: [PATCH 7/9] Add support for serial bluetooth ports on Linux (#237) Added search blob /dev/rfcomm*. rfcomm* is a commonly used naming convention for bluetooth ports on linux --- src/impl/list_ports/list_ports_linux.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/impl/list_ports/list_ports_linux.cc b/src/impl/list_ports/list_ports_linux.cc index 9779d5e..db2afb2 100644 --- a/src/impl/list_ports/list_ports_linux.cc +++ b/src/impl/list_ports/list_ports_linux.cc @@ -305,6 +305,7 @@ serial::list_ports() search_globs.push_back("/dev/ttyUSB*"); search_globs.push_back("/dev/tty.*"); search_globs.push_back("/dev/cu.*"); + search_globs.push_back("/dev/rfcomm*"); vector devices_found = glob( search_globs ); From 33e5a31ab77011504c8e37d7e9c3b9fa4229e625 Mon Sep 17 00:00:00 2001 From: Maicol Castro <60545998+guilhermerk@users.noreply.github.com> Date: Thu, 10 Jun 2021 19:15:44 -0300 Subject: [PATCH 8/9] Fix broken links (#244) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d17f7b1..5e043c2 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Serial is a class that provides the basic interface common to serial libraries ( ### Documentation -Website: http://wjwwood.github.com/serial/ +Website: http://wjwwood.github.io/serial/ -API Documentation: http://wjwwood.github.com/serial/doc/1.1.0/index.html +API Documentation: http://wjwwood.github.io/serial/doc/1.1.0/index.html ### Dependencies From 69e0372cf0d3796e84ce9a09aff1d74496f68720 Mon Sep 17 00:00:00 2001 From: Eric Fontaine Date: Tue, 8 Mar 2022 19:16:57 -0500 Subject: [PATCH 9/9] Move License text to separate LICENSE file (#261) --- LICENSE | 7 +++++++ README.md | 10 +--------- 2 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bd087f8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2012 William Woodall, John Harrison + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 5e043c2..c5d8d0b 100644 --- a/README.md +++ b/README.md @@ -51,15 +51,7 @@ Install: ### License -The MIT License - -Copyright (c) 2012 William Woodall, John Harrison - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +[The MIT License](LICENSE) ### Authors