This class can manage a serial port. The class allows basic operations (opening the connection, reading, writing data and closing the connection). More...
#include <serialib.h>
Public Member Functions | |
serialib () | |
Constructor of the class serialib. | |
~serialib () | |
Destructor of the class serialib. It close the connection. | |
char | Open (const char *Device, const unsigned int Bauds) |
Open the serial port. | |
void | Close () |
Close the connection with the current device. | |
char | WriteChar (char) |
Write a char on the current serial port. | |
char | ReadChar (char *pByte, const unsigned int TimeOut_ms=NULL) |
Wait for a byte from the serial device and return the data read. | |
char | WriteString (const char *String) |
Write a string on the current serial port. | |
int | ReadString (char *String, char FinalChar, unsigned int MaxNbBytes, const unsigned int TimeOut_ms=NULL) |
Read a string from the serial device (with timeout) | |
char | Write (const void *Buffer, const unsigned int NbBytes) |
Write an array of data on the current serial port. | |
int | Read (void *Buffer, unsigned int MaxNbBytes, const unsigned int TimeOut_ms=NULL) |
Read an array of bytes from the serial device (with timeout) | |
void | FlushReceiver () |
Empty receiver buffer (UNIX only) | |
int | Peek () |
Return the number of bytes in the received buffer (UNIX only) |
This class can manage a serial port. The class allows basic operations (opening the connection, reading, writing data and closing the connection).
Definition at line 53 of file serialib.h.
char serialib::Open | ( | const char * | Device, |
const unsigned int | Bauds | ||
) |
Open the serial port.
Device | : Port name (COM1, COM2, ... for Windows ) or (/dev/ttyS0, /dev/ttyACM0, /dev/ttyUSB0 ... for linux) |
Bauds | : Baud rate of the serial port. |
Supported baud rate for Windows :
Supported baud rate for Linux :
Definition at line 90 of file serialib.cpp.
int serialib::Peek | ( | ) |
Return the number of bytes in the received buffer (UNIX only)
Definition at line 468 of file serialib.cpp.
int serialib::Read | ( | void * | Buffer, |
unsigned int | MaxNbBytes, | ||
const unsigned int | TimeOut_ms = NULL |
||
) |
Read an array of bytes from the serial device (with timeout)
Buffer | : array of bytes read from the serial device |
MaxNbBytes | : maximum allowed number of bytes read |
TimeOut_ms | : delay of timeout before giving up the reading |
Definition at line 412 of file serialib.cpp.
char serialib::ReadChar | ( | char * | pByte, |
const unsigned int | TimeOut_ms = NULL |
||
) |
Wait for a byte from the serial device and return the data read.
pByte | : data read on the serial device |
TimeOut_ms | : delay of timeout before giving up the reading If set to zero, timeout is disable (Optional) |
Definition at line 292 of file serialib.cpp.
int serialib::ReadString | ( | char * | String, |
char | FinalChar, | ||
unsigned int | MaxNbBytes, | ||
const unsigned int | TimeOut_ms = NULL |
||
) |
Read a string from the serial device (with timeout)
String | : string read on the serial device |
FinalChar | : final char of the string |
MaxNbBytes | : maximum allowed number of bytes read |
TimeOut_ms | : delay of timeout before giving up the reading (optional) |
Definition at line 364 of file serialib.cpp.
char serialib::Write | ( | const void * | Buffer, |
const unsigned int | NbBytes | ||
) |
Write an array of data on the current serial port.
Buffer | : array of bytes to send on the port |
NbBytes | : number of byte to send |
Definition at line 265 of file serialib.cpp.
char serialib::WriteChar | ( | char | Byte | ) |
Write a char on the current serial port.
Byte | : char to send on the port (must be terminated by '\0') |
Definition at line 210 of file serialib.cpp.
char serialib::WriteString | ( | const char * | String | ) |
Write a string on the current serial port.
String | : string to send on the port (must be terminated by '\0') |
Definition at line 237 of file serialib.cpp.