#include <AsyncSerial.h>
#include <stdio.h> #include <iostream> #include <cstdlib> #include <AsyncCppApplication.h> #include <AsyncSerial.h> using namespace std; using namespace Async; class MyClass : public SigC::Object { public: MyClass(void) { serial = new Serial("/dev/ttyS0"); serial->charactersReceived.connect( slot(*this, &MyClass::onCharactersReceived)); if (!serial->open()) { perror("Open serial port failed"); exit(1); } serial->setParams(9600, Serial::PARITY_NONE, 8, 1, Serial::FLOW_NONE); serial->write("Hello, serial\n", 14); } ~MyClass(void) { serial->close(); delete serial; } private: Serial *serial; void onCharactersReceived(char *buf, int count) { cout << "Read " << count << " characters from serial port: " << buf << endl; } }; int main(int argc, char **argv) { CppApplication app; MyClass my_class; app.exec(); }
Definition at line 129 of file AsyncSerial.h.
enum Async::Serial::Flow |
A type that defines the possible choices for flow control.
FLOW_NONE | No flow control in use. |
FLOW_HW | Use hardware flow control. |
FLOW_XONOFF | Use software (XON/XOFF) flow control. |
Definition at line 145 of file AsyncSerial.h.
enum Async::Serial::Pin |
A type that defines the read/write pins in the serial port.
Definition at line 155 of file AsyncSerial.h.
Async::Serial::Serial | ( | const std::string & | serial_port | ) | [explicit] |
Constuctor.
serial_port | The device name of the serial port to use |
Async::Serial::~Serial | ( | void | ) |
Destructor.
bool Async::Serial::close | ( | void | ) |
Close a previously opened serial port.
bool Async::Serial::getPin | ( | Pin | pin, | |
bool & | is_set | |||
) |
Get the state of one of the input pins in the serial port.
pin | The pin to get the state of. See Serial::Pin. | |
is_set | The result will be returned in this variable. |
bool Async::Serial::open | ( | void | ) |
Open the serial port.
bool Async::Serial::setCanonical | ( | bool | canonical | ) |
Set or clear canonical mode.
This function may be called both before or after the port has been opened and the setting is remembered after a close.
Setup the serial port communications parameters.
speed | The serial speed to use | |
parity | The parity to use (see Serial::Parity) | |
bits | The number of bits in each serial word | |
stop_bits | The number of stop bits to use | |
flow | The type of flow control to use (see Serial::Flow) |
bool Async::Serial::setPin | ( | Pin | pin, | |
bool | set | |||
) |
Set the state of one of the output pins in the serial port.
pin | The pin to set. See Serial::Pin. | |
set | If true the pin is set, if false the pin is cleared |
bool Async::Serial::stopInput | ( | bool | stop | ) |
Stop/start input of data.
stop | Stop input if true or start input if false |
int Async::Serial::write | ( | const char * | buf, | |
size_t | count | |||
) | [inline] |
Write data to the serial port.
buf | A buffer containing the data to write | |
count | The number of bytes to write |
Definition at line 243 of file AsyncSerial.h.
SigC::Signal2<void, char*, int> Async::Serial::charactersReceived |
A signal that is emitted when there is data to read.
buf | A buffer containing the data that has been read | |
count | The number of bytes that was read |
Definition at line 314 of file AsyncSerial.h.
const int Async::Serial::READ_BUFSIZE = 1024 [static] |
The maximum number of characters that can be read at once.
Definition at line 169 of file AsyncSerial.h.