arduino-emulator
|
This class is used for communication over a serial device. More...
#include <serialib.h>
Public Member Functions | |
serialib () | |
Constructor of the class serialib. | |
~serialib () | |
Destructor of the class serialib. It close the connection. | |
int | available () |
Return the number of bytes in the received buffer (UNIX only) More... | |
bool | clearDTR () |
Clear the bit DTR (pin 4) DTR stands for Data Terminal Ready. More... | |
bool | clearRTS () |
Clear the bit RTS (pin 7) RTS stands for Data Terminal Ready. More... | |
void | closeDevice () |
Close the connection with the current device. | |
bool | DTR (bool status) |
Set or unset the bit DTR (pin 4) DTR stands for Data Terminal Ready Convenience method :This method calls setDTR and clearDTR. More... | |
char | flushReceiver () |
Empty receiver buffer. More... | |
bool | isCTS () |
Get the CTS's status (pin 8) CTS stands for Clear To Send. More... | |
bool | isDCD () |
Get the DCD's status (pin 1) CDC stands for Data Carrier Detect. More... | |
bool | isDSR () |
Get the DSR's status (pin 6) DSR stands for Data Set Ready. More... | |
bool | isDTR () |
Get the DTR's status (pin 4) DTR stands for Data Terminal Ready May behave abnormally on Windows. More... | |
bool | isRI () |
Get the RING's status (pin 9) Ring Indicator. More... | |
bool | isRTS () |
Get the RTS's status (pin 7) RTS stands for Request To Send May behave abnormally on Windows. More... | |
char | openDevice (const char *Device, const unsigned int Bauds) |
Open the serial port. More... | |
int | readBytes (void *buffer, unsigned int maxNbBytes, const unsigned int timeOut_ms=0, unsigned int sleepDuration_us=100) |
Read an array of bytes from the serial device (with timeout) More... | |
char | readChar (char *pByte, const unsigned int timeOut_ms=0) |
Wait for a byte from the serial device and return the data read. More... | |
int | readString (char *receivedString, char finalChar, unsigned int maxNbBytes, const unsigned int timeOut_ms=0) |
Read a string from the serial device (with timeout) More... | |
bool | RTS (bool status) |
Set or unset the bit RTS (pin 7) RTS stands for Data Termina Ready Convenience method :This method calls setDTR and clearDTR. More... | |
bool | setDTR () |
Set the bit DTR (pin 4) DTR stands for Data Terminal Ready. More... | |
bool | setRTS () |
Set the bit RTS (pin 7) RTS stands for Data Terminal Ready. More... | |
char | writeBytes (const void *Buffer, const unsigned int NbBytes) |
Write an array of data on the current serial port. More... | |
char | writeChar (char) |
Write a char on the current serial port. More... | |
char | writeString (const char *String) |
Write a string on the current serial port. More... | |
This class is used for communication over a serial device.
int serialib::available | ( | void | ) |
Return the number of bytes in the received buffer (UNIX only)
bool serialib::clearDTR | ( | ) |
Clear the bit DTR (pin 4) DTR stands for Data Terminal Ready.
bool serialib::clearRTS | ( | ) |
Clear the bit RTS (pin 7) RTS stands for Data Terminal Ready.
bool serialib::DTR | ( | bool | status | ) |
Set or unset the bit DTR (pin 4) DTR stands for Data Terminal Ready Convenience method :This method calls setDTR and clearDTR.
status | = true set DTR status = false unset DTR |
char serialib::flushReceiver | ( | ) |
Empty receiver buffer.
bool serialib::isCTS | ( | ) |
Get the CTS's status (pin 8) CTS stands for Clear To Send.
bool serialib::isDCD | ( | ) |
Get the DCD's status (pin 1) CDC stands for Data Carrier Detect.
bool serialib::isDSR | ( | ) |
Get the DSR's status (pin 6) DSR stands for Data Set Ready.
bool serialib::isDTR | ( | ) |
Get the DTR's status (pin 4) DTR stands for Data Terminal Ready May behave abnormally on Windows.
bool serialib::isRI | ( | ) |
Get the RING's status (pin 9) Ring Indicator.
bool serialib::isRTS | ( | ) |
Get the RTS's status (pin 7) RTS stands for Request To Send May behave abnormally on Windows.
char serialib::openDevice | ( | 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 :
|
int serialib::readBytes | ( | void * | buffer, |
unsigned int | maxNbBytes, | ||
const unsigned int | timeOut_ms = 0 , |
||
unsigned int | sleepDuration_us = 100 |
||
) |
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 |
sleepDuration_us | : delay of CPU relaxing in microseconds (Linux only) In the reading loop, a sleep can be performed after each reading This allows CPU to perform other tasks |
char serialib::readChar | ( | char * | pByte, |
const unsigned int | timeOut_ms = 0 |
||
) |
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) |
int serialib::readString | ( | char * | receivedString, |
char | finalChar, | ||
unsigned int | maxNbBytes, | ||
const unsigned int | timeOut_ms = 0 |
||
) |
Read a string from the serial device (with timeout)
receivedString | : 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) |
bool serialib::RTS | ( | bool | status | ) |
Set or unset the bit RTS (pin 7) RTS stands for Data Termina Ready Convenience method :This method calls setDTR and clearDTR.
status | = true set DTR status = false unset DTR |
bool serialib::setDTR | ( | ) |
Set the bit DTR (pin 4) DTR stands for Data Terminal Ready.
bool serialib::setRTS | ( | ) |
Set the bit RTS (pin 7) RTS stands for Data Terminal Ready.
char serialib::writeBytes | ( | 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 |
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') |
char serialib::writeString | ( | const char * | receivedString | ) |
Write a string on the current serial port.
receivedString | : string to send on the port (must be terminated by '\0') |