1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

Merge branch 'master' of github.com:wjwwood/serial

Conflicts:
	include/serial.h
	src/serial.cpp
This commit is contained in:
John Harrison 2011-03-24 10:17:02 -05:00
commit 619fd31dd4
2 changed files with 26 additions and 8 deletions

View File

@ -54,6 +54,19 @@
TypeName(const TypeName&); \ TypeName(const TypeName&); \
void operator=(const TypeName&) void operator=(const TypeName&)
// If on Windows undefine the PARITY_* defines that are in winbase.h
#ifdef PARTIY_NONE
#undef PARITY_NONE
#endif
#ifdef PARTIY_ODD
#undef PARITY_ODD
#endif
#ifdef PARTIY_EVEN
#undef PARITY_EVEN
#endif
// DEFINES // DEFINES
#ifndef DEFAULT_BAUDRATE #ifndef DEFAULT_BAUDRATE
#define DEFAULT_BAUDRATE 9600 #define DEFAULT_BAUDRATE 9600

View File

@ -159,6 +159,8 @@ void Serial::init() {
Serial::~Serial() { Serial::~Serial() {
this->close(); this->close();
if(this->timeout != NULL)
delete this->timeout;
} }
void Serial::open() { void Serial::open() {
@ -185,8 +187,11 @@ void Serial::open() {
void Serial::close() { void Serial::close() {
// Cancel the current timeout timer and async reads // Cancel the current timeout timer and async reads
this->timeout_timer.cancel(); this->timeout_timer.cancel();
this->serial_port->cancel(); if(this->serial_port != NULL) {
this->serial_port->close(); this->serial_port->cancel();
this->serial_port->close();
delete this->serial_port;
}
} }
static const boost::posix_time::time_duration timeout_zero_comparison(boost::posix_time::milliseconds(0)); static const boost::posix_time::time_duration timeout_zero_comparison(boost::posix_time::milliseconds(0));
@ -326,13 +331,13 @@ const bytesize_t Serial::getBytesize() const {
void Serial::setParity(parity_t parity) { void Serial::setParity(parity_t parity) {
switch(parity) { switch(parity) {
case NONE: case PARITY_NONE:
this->parity = boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none); this->parity = boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none);
break; break;
case ODD: case PARITY_ODD:
this->parity = boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::odd); this->parity = boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::odd);
break; break;
case EVEN: case PARITY_EVEN:
this->parity = boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::even); this->parity = boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::even);
break; break;
default: default:
@ -344,11 +349,11 @@ void Serial::setParity(parity_t parity) {
const parity_t Serial::getParity() const { const parity_t Serial::getParity() const {
switch(this->parity.value()) { switch(this->parity.value()) {
case boost::asio::serial_port_base::parity::none: case boost::asio::serial_port_base::parity::none:
return parity_t(NONE); return parity_t(PARITY_NONE);
case boost::asio::serial_port_base::parity::odd: case boost::asio::serial_port_base::parity::odd:
return parity_t(ODD); return parity_t(PARITY_ODD);
case boost::asio::serial_port_base::parity::even: case boost::asio::serial_port_base::parity::even:
return parity_t(EVEN); return parity_t(PARITY_EVEN);
default: default:
throw(InvalidParityException(this->parity.value())); throw(InvalidParityException(this->parity.value()));
} }