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

Removed const's before the return type on the methods, this isn't correct and produced warnings in linux.

This commit is contained in:
William Woodall 2011-04-18 16:40:37 -05:00
parent 4eac4bf8c6
commit cbe669f756
2 changed files with 28 additions and 28 deletions

View File

@ -148,7 +148,7 @@ public:
* *
* @return A boolean value that represents whether or not the serial port is open. * @return A boolean value that represents whether or not the serial port is open.
*/ */
const bool isOpen(); bool isOpen();
/** Closes the serial port and terminates threads. */ /** Closes the serial port and terminates threads. */
void close(); void close();
@ -163,7 +163,7 @@ public:
* *
* @return An integer representing the number of bytes read. * @return An integer representing the number of bytes read.
*/ */
const int read(char* buffer, int size = 1); int read(char* buffer, int size = 1);
/** Read size bytes from the serial port. /** Read size bytes from the serial port.
* If a timeout is set it may return less characters than requested. With no timeout * If a timeout is set it may return less characters than requested. With no timeout
@ -173,7 +173,7 @@ public:
* *
* @return A std::string containing the data read. * @return A std::string containing the data read.
*/ */
const std::string read(int size = 1); std::string read(int size = 1);
std::string read_until(char delim, size_t size = -1); std::string read_until(char delim, size_t size = -1);
std::string read_until(std::string delim, size_t size = -1); std::string read_until(std::string delim, size_t size = -1);
@ -186,7 +186,7 @@ public:
* *
* @return An integer representing the number of bytes written. * @return An integer representing the number of bytes written.
*/ */
const int write(char data[], int length); int write(char data[], int length);
/** Write a string to the serial port. /** Write a string to the serial port.
* *
@ -194,7 +194,7 @@ public:
* *
* @return An integer representing the number of bytes written to the serial port. * @return An integer representing the number of bytes written to the serial port.
*/ */
const int write(std::string data); int write(std::string data);
/** Sets the logic level of the RTS line. /** Sets the logic level of the RTS line.
* *
@ -212,13 +212,13 @@ public:
* *
* @return A boolean value that represents the current logic level of the CTS line. * @return A boolean value that represents the current logic level of the CTS line.
*/ */
const bool getCTS() const; bool getCTS() const;
/** Gets the status of the DSR line. /** Gets the status of the DSR line.
* *
* @return A boolean value that represents the current logic level of the DSR line. * @return A boolean value that represents the current logic level of the DSR line.
*/ */
const bool getDSR() const; bool getDSR() const;
/** Sets the serial port identifier. /** Sets the serial port identifier.
* *
@ -234,7 +234,7 @@ public:
* which would be something like 'COM1' on Windows and '/dev/ttyS0' * which would be something like 'COM1' on Windows and '/dev/ttyS0'
* on Linux. * on Linux.
*/ */
const std::string getPort() const; std::string getPort() const;
/** Sets the timeout for reads in seconds. /** Sets the timeout for reads in seconds.
* *
@ -256,7 +256,7 @@ public:
* zero (-1) will result in infinite blocking behaviour, i.e. the serial port will * zero (-1) will result in infinite blocking behaviour, i.e. the serial port will
* block until either size bytes have been read or an exception has occured. * block until either size bytes have been read or an exception has occured.
*/ */
const long getTimeoutMilliseconds() const; long getTimeoutMilliseconds() const;
/** Sets the baudrate for the serial port. /** Sets the baudrate for the serial port.
* *
@ -268,7 +268,7 @@ public:
* *
* @return An integer that sets the baud rate for the serial port. * @return An integer that sets the baud rate for the serial port.
*/ */
const int getBaudrate() const; int getBaudrate() const;
/** Sets the bytesize for the serial port. /** Sets the bytesize for the serial port.
* *
@ -288,7 +288,7 @@ public:
* *
* @throw InvalidBytesizeException * @throw InvalidBytesizeException
*/ */
const bytesize_t getBytesize() const; bytesize_t getBytesize() const;
/** Sets the parity for the serial port. /** Sets the parity for the serial port.
* *
@ -306,7 +306,7 @@ public:
* *
* @throw InvalidParityException * @throw InvalidParityException
*/ */
const parity_t getParity() const; parity_t getParity() const;
/** Sets the stopbits for the serial port. /** Sets the stopbits for the serial port.
* *
@ -324,7 +324,7 @@ public:
* *
* @throw InvalidStopbitsException * @throw InvalidStopbitsException
*/ */
const stopbits_t getStopbits() const; stopbits_t getStopbits() const;
/** Sets the flow control for the serial port. /** Sets the flow control for the serial port.
* *
@ -342,7 +342,7 @@ public:
* *
* @throw InvalidFlowcontrolException * @throw InvalidFlowcontrolException
*/ */
const flowcontrol_t getFlowcontrol() const; flowcontrol_t getFlowcontrol() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(Serial); DISALLOW_COPY_AND_ASSIGN(Serial);
void init(); void init();

View File

@ -183,7 +183,7 @@ void Serial::open() {
} }
} }
const bool Serial::isOpen() { bool Serial::isOpen() {
if(this->serial_port != NULL) if(this->serial_port != NULL)
return this->serial_port->is_open(); return this->serial_port->is_open();
return false; return false;
@ -201,7 +201,7 @@ void Serial::close() {
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));
const int Serial::read(char* buffer, int size) { int Serial::read(char* buffer, int size) {
this->reading = true; this->reading = true;
if(this->nonblocking) {// Do not wait for data if(this->nonblocking) {// Do not wait for data
this->serial_port->async_read_some(boost::asio::buffer(buffer, size), this->serial_port->async_read_some(boost::asio::buffer(buffer, size),
@ -232,7 +232,7 @@ const int Serial::read(char* buffer, int size) {
return this->bytes_read; return this->bytes_read;
} }
const std::string Serial::read(int size) { std::string Serial::read(int size) {
char *serial_buffer = new char[size]; char *serial_buffer = new char[size];
int bytes_read_ = this->read(serial_buffer, size); int bytes_read_ = this->read(serial_buffer, size);
std::string return_str(serial_buffer, (std::size_t)bytes_read_); std::string return_str(serial_buffer, (std::size_t)bytes_read_);
@ -285,11 +285,11 @@ void Serial::timeout_callback(const boost::system::error_code& error) {
} }
} }
const int Serial::write(char data[], int length) { int Serial::write(char data[], int length) {
return boost::asio::write(*this->serial_port, boost::asio::buffer(data, length), boost::asio::transfer_all()); return boost::asio::write(*this->serial_port, boost::asio::buffer(data, length), boost::asio::transfer_all());
} }
const int Serial::write(std::string data) { int Serial::write(std::string data) {
char *cstr = new char[data.size()+1]; char *cstr = new char[data.size()+1];
std::strcpy(cstr, data.c_str()); std::strcpy(cstr, data.c_str());
int bytes_wrote = this->write(cstr, data.length()); int bytes_wrote = this->write(cstr, data.length());
@ -305,12 +305,12 @@ void Serial::setDTR(bool level) {
this->serial_port->set_option(DTRControl(level)); this->serial_port->set_option(DTRControl(level));
} }
const bool Serial::getCTS() const { bool Serial::getCTS() const {
throw(boost::asio::error::operation_not_supported); throw(boost::asio::error::operation_not_supported);
return false; return false;
} }
const bool Serial::getDSR() const { bool Serial::getDSR() const {
throw(boost::asio::error::operation_not_supported); throw(boost::asio::error::operation_not_supported);
return false; return false;
} }
@ -319,7 +319,7 @@ void Serial::setPort(std::string port) {
this->port = port; this->port = port;
} }
const std::string Serial::getPort() const { std::string Serial::getPort() const {
return this->port; return this->port;
} }
@ -339,7 +339,7 @@ void Serial::setTimeoutMilliseconds(long timeout) {
this->nonblocking = false; this->nonblocking = false;
} }
const long Serial::getTimeoutMilliseconds() const { long Serial::getTimeoutMilliseconds() const {
return this->timeout.total_milliseconds(); return this->timeout.total_milliseconds();
} }
@ -347,7 +347,7 @@ void Serial::setBaudrate(int baudrate) {
this->baudrate = boost::asio::serial_port_base::baud_rate(baudrate); this->baudrate = boost::asio::serial_port_base::baud_rate(baudrate);
} }
const int Serial::getBaudrate() const { int Serial::getBaudrate() const {
return this->baudrate.value(); return this->baudrate.value();
} }
@ -371,7 +371,7 @@ void Serial::setBytesize(bytesize_t bytesize) {
} }
} }
const bytesize_t Serial::getBytesize() const { bytesize_t Serial::getBytesize() const {
return bytesize_t(this->bytesize.value()); return bytesize_t(this->bytesize.value());
} }
@ -392,7 +392,7 @@ void Serial::setParity(parity_t parity) {
} }
} }
const parity_t Serial::getParity() 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(PARITY_NONE); return parity_t(PARITY_NONE);
@ -422,7 +422,7 @@ void Serial::setStopbits(stopbits_t stopbits) {
} }
} }
const stopbits_t Serial::getStopbits() const { stopbits_t Serial::getStopbits() const {
switch(this->stopbits.value()) { switch(this->stopbits.value()) {
case boost::asio::serial_port_base::stop_bits::one: case boost::asio::serial_port_base::stop_bits::one:
return stopbits_t(STOPBITS_ONE); return stopbits_t(STOPBITS_ONE);
@ -452,7 +452,7 @@ void Serial::setFlowcontrol(flowcontrol_t flowcontrol) {
} }
} }
const flowcontrol_t Serial::getFlowcontrol() const { flowcontrol_t Serial::getFlowcontrol() const {
switch(this->flowcontrol.value()) { switch(this->flowcontrol.value()) {
case boost::asio::serial_port_base::flow_control::none: case boost::asio::serial_port_base::flow_control::none:
return flowcontrol_t(FLOWCONTROL_NONE); return flowcontrol_t(FLOWCONTROL_NONE);