mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69e0372cf0 | ||
|
|
33e5a31ab7 | ||
|
|
ed9f89ca31 | ||
|
|
9fc9e81fc1 | ||
|
|
57f72772a9 | ||
|
|
a93fc844d9 | ||
|
|
7439db1228 | ||
|
|
9e331e7977 | ||
|
|
cbcca7c837 | ||
|
|
683e12d2f6 | ||
|
|
fba8d81b5d | ||
|
|
2ef29d7b10 | ||
|
|
5a354eaab7 | ||
|
|
bdba3a80ad | ||
|
|
17e3223e68 | ||
|
|
764fab8b5e | ||
|
|
235a5f716d | ||
|
|
534141aa8f | ||
|
|
ce085ce88c | ||
|
|
d3713af096 | ||
|
|
827c4a784d | ||
|
|
771e62c220 | ||
|
|
02dfff7883 | ||
|
|
4d69fb2e41 | ||
|
|
c16faab6ea | ||
|
|
d76b7d6b7f | ||
|
|
2d416f1560 | ||
|
|
22dce33fa4 | ||
|
|
e12d81eadf | ||
|
|
c5b4bbd181 | ||
|
|
98f1c31e81 | ||
|
|
ef7f77d411 | ||
|
|
402657574c | ||
|
|
a81087ec85 | ||
|
|
9b80fc3fbf | ||
|
|
c57285f30a | ||
|
|
cd5053cb32 | ||
|
|
6144d579af | ||
|
|
1580f10d39 | ||
|
|
99e57e633c | ||
|
|
b8320d31a7 |
@ -2,11 +2,9 @@ os:
|
||||
- linux
|
||||
- osx
|
||||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
install:
|
||||
- make install_deps
|
||||
- source setup.bash
|
||||
script:
|
||||
- make && make test
|
||||
- mkdir build && cd build && cmake .. -DPYTHON_EXECUTABLE=$(which python2) && make && make tests && make run_tests
|
||||
- catkin_test_results .
|
||||
|
||||
@ -11,6 +11,8 @@ endif()
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
# If Linux, add rt and pthread
|
||||
set(rt_LIBRARIES rt)
|
||||
set(pthread_LIBRARIES pthread)
|
||||
catkin_package(
|
||||
LIBRARIES ${PROJECT_NAME}
|
||||
INCLUDE_DIRS include
|
||||
@ -66,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
|
||||
|
||||
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -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.
|
||||
12
Makefile
12
Makefile
@ -8,14 +8,17 @@ ifeq ($(UNAME),Darwin)
|
||||
brew tap ros/deps
|
||||
brew update
|
||||
brew outdated boost || brew upgrade boost || brew install boost
|
||||
sudo pip install rosinstall_generator wstool rosdep empy catkin_pkg
|
||||
sudo rosdep init
|
||||
brew outdated python || brew upgrade python || brew install python
|
||||
sudo -H python2 -m pip install -U pip setuptools
|
||||
sudo -H python2 -m pip install --force-reinstall --no-deps -U pip
|
||||
sudo -H python2 -m pip install rosinstall_generator wstool rosdep empy catkin_pkg
|
||||
sudo -H rosdep init
|
||||
rosdep update
|
||||
mkdir catkin_ws
|
||||
cd catkin_ws && rosinstall_generator catkin --rosdistro hydro --tar > catkin.rosinstall
|
||||
cd catkin_ws && wstool init src catkin.rosinstall
|
||||
cd catkin_ws && rosdep install --from-paths src --ignore-src -y
|
||||
cd catkin_ws && ./src/catkin/bin/catkin_make install
|
||||
cd catkin_ws && python2 ./src/catkin/bin/catkin_make -DPYTHON_EXECUTABLE=`which python2` install
|
||||
echo "source catkin_ws/install/setup.bash" > setup.bash
|
||||
else
|
||||
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list'
|
||||
@ -28,9 +31,6 @@ endif
|
||||
install:
|
||||
cd build && make install
|
||||
|
||||
uninstall:
|
||||
cd build && make uninstall
|
||||
|
||||
serial:
|
||||
@mkdir -p build
|
||||
cd build && cmake $(CMAKE_FLAGS) ..
|
||||
|
||||
25
README.md
25
README.md
@ -10,18 +10,23 @@ 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
|
||||
|
||||
Required:
|
||||
* [catkin](http://www.ros.org/wiki/catkin) - cmake and Python based buildsystem
|
||||
* [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:
|
||||
@ -38,27 +43,15 @@ Build and run the tests:
|
||||
|
||||
Build the documentation:
|
||||
|
||||
make docs
|
||||
make doc
|
||||
|
||||
Install:
|
||||
|
||||
make install
|
||||
|
||||
Uninstall:
|
||||
|
||||
make uninstall
|
||||
|
||||
### 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
|
||||
|
||||
|
||||
2492
doc/Doxyfile
2492
doc/Doxyfile
File diff suppressed because it is too large
Load Diff
@ -55,10 +55,4 @@ To install simply:
|
||||
sudo make install
|
||||
</pre>
|
||||
|
||||
To uninstall simply:
|
||||
|
||||
<pre>
|
||||
sudo make uninstall
|
||||
</pre>
|
||||
|
||||
*/
|
||||
@ -450,6 +450,8 @@ public:
|
||||
* reading or writing is complete, when a timeout occurs, or when an
|
||||
* exception occurs.
|
||||
*
|
||||
* A timeout of 0 enables non-blocking mode.
|
||||
*
|
||||
* \param timeout A serial::Timeout struct containing the inter byte
|
||||
* timeout, and the read and write timeout constants and multipliers.
|
||||
*
|
||||
@ -486,7 +488,7 @@ public:
|
||||
* 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000,
|
||||
* 57600, 115200
|
||||
* Some other baudrates that are supported by some comports:
|
||||
* 128000, 153600, 230400, 256000, 460800, 921600
|
||||
* 128000, 153600, 230400, 256000, 460800, 500000, 921600
|
||||
*
|
||||
* \param baudrate An integer that sets the baud rate for the serial port.
|
||||
*
|
||||
@ -717,7 +719,7 @@ public:
|
||||
virtual ~IOException() throw() {}
|
||||
IOException (const IOException& other) : line_(other.line_), e_what_(other.e_what_), errno_(other.errno_) {}
|
||||
|
||||
int getErrorNumber () { return errno_; }
|
||||
int getErrorNumber () const { return errno_; }
|
||||
|
||||
virtual const char* what () const throw () {
|
||||
return e_what_.c_str();
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
<name>serial</name>
|
||||
<version>1.2.1</version>
|
||||
<description>
|
||||
Serial is a cross-platform, simple to use library for using serial ports on computers. This library provides a C++, object oriented interface for interacting with RS-232 like devices on Linux and Windows.
|
||||
Serial is a cross-platform, simple to use library for using serial ports on computers.
|
||||
This library provides a C++, object oriented interface for interacting with RS-232
|
||||
like devices on Linux and Windows.
|
||||
</description>
|
||||
|
||||
<maintainer email="william@osrfoundation.org">William Woodall</maintainer>
|
||||
@ -19,6 +21,4 @@
|
||||
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
|
||||
<test_depend>boost</test_depend>
|
||||
|
||||
</package>
|
||||
|
||||
@ -11,14 +11,12 @@
|
||||
{
|
||||
"sublimeclang_options":
|
||||
[
|
||||
"-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
|
||||
"-I/usr/local/include",
|
||||
"-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include",
|
||||
"-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
|
||||
"-I/usr/include",
|
||||
"-I/usr/local/include",
|
||||
"-I${folder:${project_path:serial.sublime-project}}/include",
|
||||
"-I/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1",
|
||||
"-I/usr/local/include",
|
||||
"-I/Library/Developer/CommandLineTools/usr/bin/../lib/clang/6.1.0/include",
|
||||
"-I/Library/Developer/CommandLineTools/usr/include",
|
||||
"-I/usr/include"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<string> devices_found = glob( search_globs );
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ MillisecondTimer::MillisecondTimer (const uint32_t millis)
|
||||
int64_t tv_nsec = expiry.tv_nsec + (millis * 1e6);
|
||||
if (tv_nsec >= 1e9) {
|
||||
int64_t sec_diff = tv_nsec / static_cast<int> (1e9);
|
||||
expiry.tv_nsec = tv_nsec - static_cast<int> (1e9 * sec_diff);
|
||||
expiry.tv_nsec = tv_nsec % static_cast<int>(1e9);
|
||||
expiry.tv_sec += sec_diff;
|
||||
} else {
|
||||
expiry.tv_nsec = tv_nsec;
|
||||
@ -85,13 +85,13 @@ MillisecondTimer::timespec_now ()
|
||||
# ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||
clock_get_time(cclock, &mts);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
time.tv_sec = mts.tv_sec;
|
||||
time.tv_nsec = mts.tv_nsec;
|
||||
# else
|
||||
clock_gettime(CLOCK_REALTIME, &time);
|
||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||
# endif
|
||||
return time;
|
||||
}
|
||||
@ -269,6 +269,9 @@ Serial::SerialImpl::reconfigurePort ()
|
||||
#ifdef B460800
|
||||
case 460800: baud = B460800; break;
|
||||
#endif
|
||||
#ifdef B500000
|
||||
case 500000: baud = B500000; break;
|
||||
#endif
|
||||
#ifdef B576000
|
||||
case 576000: baud = B576000; break;
|
||||
#endif
|
||||
@ -301,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<speed_t> (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<int> (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
|
||||
@ -440,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<speed_t> (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<int> (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_);
|
||||
@ -617,12 +625,17 @@ Serial::SerialImpl::write (const uint8_t *data, size_t length)
|
||||
total_timeout_ms += timeout_.write_timeout_multiplier * static_cast<long> (length);
|
||||
MillisecondTimer total_timeout(total_timeout_ms);
|
||||
|
||||
bool first_iteration = true;
|
||||
while (bytes_written < length) {
|
||||
int64_t timeout_remaining_ms = total_timeout.remaining();
|
||||
if (timeout_remaining_ms <= 0) {
|
||||
// Only consider the timeout if it's not the first iteration of the loop
|
||||
// otherwise a timeout of 0 won't be allowed through
|
||||
if (!first_iteration && (timeout_remaining_ms <= 0)) {
|
||||
// Timed out
|
||||
break;
|
||||
}
|
||||
first_iteration = false;
|
||||
|
||||
timespec timeout(timespec_from_ms(timeout_remaining_ms));
|
||||
|
||||
FD_ZERO (&writefds);
|
||||
@ -652,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<size_t> (bytes_written_now);
|
||||
|
||||
@ -24,10 +24,11 @@ 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;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
Serial::SerialImpl::SerialImpl (const string &port, unsigned long baudrate,
|
||||
@ -38,10 +39,10 @@ Serial::SerialImpl::SerialImpl (const string &port, unsigned long baudrate,
|
||||
baudrate_ (baudrate), parity_ (parity),
|
||||
bytesize_ (bytesize), stopbits_ (stopbits), flowcontrol_ (flowcontrol)
|
||||
{
|
||||
read_mutex = CreateMutex(NULL, false, NULL);
|
||||
write_mutex = CreateMutex(NULL, false, NULL);
|
||||
if (port_.empty () == false)
|
||||
open ();
|
||||
read_mutex = CreateMutex(NULL, false, NULL);
|
||||
write_mutex = CreateMutex(NULL, false, NULL);
|
||||
}
|
||||
|
||||
Serial::SerialImpl::~SerialImpl ()
|
||||
@ -73,15 +74,15 @@ Serial::SerialImpl::open ()
|
||||
0);
|
||||
|
||||
if (fd_ == INVALID_HANDLE_VALUE) {
|
||||
DWORD errno_ = GetLastError();
|
||||
DWORD create_file_err = GetLastError();
|
||||
stringstream ss;
|
||||
switch (errno_) {
|
||||
switch (create_file_err) {
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
// Use this->getPort to convert to a std::string
|
||||
ss << "Specified port, " << this->getPort() << ", does not exist.";
|
||||
THROW (IOException, ss.str().c_str());
|
||||
default:
|
||||
ss << "Unknown error opening the serial port: " << errno;
|
||||
ss << "Unknown error opening the serial port: " << create_file_err;
|
||||
THROW (IOException, ss.str().c_str());
|
||||
}
|
||||
}
|
||||
@ -238,19 +239,19 @@ Serial::SerialImpl::reconfigurePort ()
|
||||
// setup flowcontrol
|
||||
if (flowcontrol_ == flowcontrol_none) {
|
||||
dcbSerialParams.fOutxCtsFlow = false;
|
||||
dcbSerialParams.fRtsControl = 0x00;
|
||||
dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE;
|
||||
dcbSerialParams.fOutX = false;
|
||||
dcbSerialParams.fInX = false;
|
||||
}
|
||||
if (flowcontrol_ == flowcontrol_software) {
|
||||
dcbSerialParams.fOutxCtsFlow = false;
|
||||
dcbSerialParams.fRtsControl = 0x00;
|
||||
dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE;
|
||||
dcbSerialParams.fOutX = true;
|
||||
dcbSerialParams.fInX = true;
|
||||
}
|
||||
if (flowcontrol_ == flowcontrol_hardware) {
|
||||
dcbSerialParams.fOutxCtsFlow = true;
|
||||
dcbSerialParams.fRtsControl = 0x03;
|
||||
dcbSerialParams.fRtsControl = RTS_CONTROL_HANDSHAKE;
|
||||
dcbSerialParams.fOutX = false;
|
||||
dcbSerialParams.fInX = false;
|
||||
}
|
||||
@ -314,14 +315,14 @@ Serial::SerialImpl::available ()
|
||||
}
|
||||
|
||||
bool
|
||||
Serial::SerialImpl::waitReadable (uint32_t timeout)
|
||||
Serial::SerialImpl::waitReadable (uint32_t /*timeout*/)
|
||||
{
|
||||
THROW (IOException, "waitReadable is not implemented on Windows.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
Serial::SerialImpl::waitByteTimes (size_t count)
|
||||
Serial::SerialImpl::waitByteTimes (size_t /*count*/)
|
||||
{
|
||||
THROW (IOException, "waitByteTimes is not implemented on Windows.");
|
||||
}
|
||||
@ -470,17 +471,23 @@ Serial::SerialImpl::flush ()
|
||||
void
|
||||
Serial::SerialImpl::flushInput ()
|
||||
{
|
||||
THROW (IOException, "flushInput is not supported on Windows.");
|
||||
if (is_open_ == false) {
|
||||
throw PortNotOpenedException("Serial::flushInput");
|
||||
}
|
||||
PurgeComm(fd_, PURGE_RXCLEAR);
|
||||
}
|
||||
|
||||
void
|
||||
Serial::SerialImpl::flushOutput ()
|
||||
{
|
||||
THROW (IOException, "flushOutput is not supported on Windows.");
|
||||
if (is_open_ == false) {
|
||||
throw PortNotOpenedException("Serial::flushOutput");
|
||||
}
|
||||
PurgeComm(fd_, PURGE_TXCLEAR);
|
||||
}
|
||||
|
||||
void
|
||||
Serial::SerialImpl::sendBreak (int duration)
|
||||
Serial::SerialImpl::sendBreak (int /*duration*/)
|
||||
{
|
||||
THROW (IOException, "sendBreak is not supported on Windows.");
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* Copyright 2012 William Woodall and John Harrison */
|
||||
#include <algorithm>
|
||||
|
||||
#if !defined(_WIN32) && !defined(__OpenBSD__)
|
||||
#if !defined(_WIN32) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
|
||||
@ -132,7 +132,16 @@ Serial::read (std::vector<uint8_t> &buffer, size_t size)
|
||||
{
|
||||
ScopedReadLock lock(this->pimpl_);
|
||||
uint8_t *buffer_ = new uint8_t[size];
|
||||
size_t bytes_read = this->pimpl_->read (buffer_, size);
|
||||
size_t bytes_read = 0;
|
||||
|
||||
try {
|
||||
bytes_read = this->pimpl_->read (buffer_, size);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
delete[] buffer_;
|
||||
throw;
|
||||
}
|
||||
|
||||
buffer.insert (buffer.end (), buffer_, buffer_+bytes_read);
|
||||
delete[] buffer_;
|
||||
return bytes_read;
|
||||
@ -143,7 +152,14 @@ Serial::read (std::string &buffer, size_t size)
|
||||
{
|
||||
ScopedReadLock lock(this->pimpl_);
|
||||
uint8_t *buffer_ = new uint8_t[size];
|
||||
size_t bytes_read = this->pimpl_->read (buffer_, size);
|
||||
size_t bytes_read = 0;
|
||||
try {
|
||||
bytes_read = this->pimpl_->read (buffer_, size);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
delete[] buffer_;
|
||||
throw;
|
||||
}
|
||||
buffer.append (reinterpret_cast<const char*>(buffer_), bytes_read);
|
||||
delete[] buffer_;
|
||||
return bytes_read;
|
||||
@ -172,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<const char*>
|
||||
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
|
||||
break; // EOL found
|
||||
@ -213,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<const char*>
|
||||
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
|
||||
// EOL found
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
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()
|
||||
|
||||
if(NOT APPLE) # these tests are unreliable on macOS
|
||||
catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc)
|
||||
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@ -20,8 +20,6 @@ void loop()
|
||||
#include <string>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
// Use FRIEND_TEST... its not as nasty, thats what friends are for
|
||||
// // OMG this is so nasty...
|
||||
// #define private public
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
<RootNamespace>serial</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PlatformToolset Condition="'$(PlatformToolset)' == '' and '$(VisualStudioVersion)' == '14.0'">v140_xp</PlatformToolset>
|
||||
<PlatformToolset Condition="'$(PlatformToolset)' == '' and '$(VisualStudioVersion)' == '12.0'">v120_xp</PlatformToolset>
|
||||
<PlatformToolset Condition="'$(PlatformToolset)' == '' and '$(VisualStudioVersion)' == '11.0'">v110_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
@ -70,7 +71,7 @@
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@ -84,7 +85,7 @@
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@ -100,7 +101,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@ -118,7 +119,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
||||
@ -23,6 +23,7 @@
|
||||
<RootNamespace>test_serial</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PlatformToolset Condition="'$(PlatformToolset)' == '' and '$(VisualStudioVersion)' == '14.0'">v140_xp</PlatformToolset>
|
||||
<PlatformToolset Condition="'$(PlatformToolset)' == '' and '$(VisualStudioVersion)' == '12.0'">v120_xp</PlatformToolset>
|
||||
<PlatformToolset Condition="'$(PlatformToolset)' == '' and '$(VisualStudioVersion)' == '11.0'">v110_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
@ -70,7 +71,7 @@
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@ -81,7 +82,7 @@
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@ -94,7 +95,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
@ -109,7 +110,7 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>..\..\..\serial\include</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user