2012-01-10 15:08:57 -06:00
|
|
|
#include "serial/serial.h"
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include "serial/impl/win.h"
|
|
|
|
|
#else
|
|
|
|
|
#include "serial/impl/unix.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-01-11 23:07:58 -06:00
|
|
|
using namespace serial;
|
|
|
|
|
|
2012-01-10 15:08:57 -06:00
|
|
|
Serial::Serial (const std::string &port, int baudrate,
|
|
|
|
|
long timeout, bytesize_t bytesize,
|
|
|
|
|
parity_t parity, stopbits_t stopbits,
|
|
|
|
|
flowcontrol_t flowcontrol)
|
|
|
|
|
{
|
2012-01-11 23:07:58 -06:00
|
|
|
pimpl = new Serial_pimpl(port,baudrate,timeout,bytesize,parity,stopbits,
|
|
|
|
|
flowcontrol);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Serial::~Serial () {
|
2012-01-11 23:07:58 -06:00
|
|
|
delete pimpl;
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::open () {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->open ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::close () {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->close ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
bool
|
|
|
|
|
Serial::isOpen () {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->isOpen ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
2012-01-11 23:07:58 -06:00
|
|
|
Serial::read (unsigned char* buffer, size_t size) {
|
|
|
|
|
return this->pimpl->read (buffer, size);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
2012-01-11 23:07:58 -06:00
|
|
|
Serial::read (size_t size) {
|
|
|
|
|
return this->pimpl->read (size);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
2012-01-11 23:07:58 -06:00
|
|
|
Serial::read (std::string &buffer, size_t size) {
|
|
|
|
|
return this->pimpl->read (buffer, size);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
Serial::write (unsigned char* data, size_t length) {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->write (data, length);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
Serial::write (const std::string &data) {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->write (data);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::setPort (const std::string &port) {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->setPort (port);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
Serial::getPort () const {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->getPort ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::setTimeout (long timeout) {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->setTimeout (timeout);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long
|
|
|
|
|
Serial::getTimeout () const {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->getTimeout ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::setBaudrate (int baudrate) {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->setBaudrate (baudrate);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
Serial::getBaudrate () const {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->getBaudrate ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::setBytesize (bytesize_t bytesize) {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->setBytesize (bytesize);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytesize_t
|
|
|
|
|
Serial::getBytesize () const {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->getBytesize ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::setParity (parity_t parity) {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->setParity (parity);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parity_t
|
|
|
|
|
Serial::getParity () const {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->getParity ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::setStopbits (stopbits_t stopbits) {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->setStopbits (stopbits);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stopbits_t
|
|
|
|
|
Serial::getStopbits () const {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->getStopbits ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Serial::setFlowcontrol (flowcontrol_t flowcontrol) {
|
2012-01-11 23:07:58 -06:00
|
|
|
this->pimpl->setFlowcontrol (flowcontrol);
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flowcontrol_t
|
|
|
|
|
Serial::getFlowcontrol () const {
|
2012-01-11 23:07:58 -06:00
|
|
|
return this->pimpl->getFlowcontrol ();
|
2012-01-10 15:08:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|