BlackLib::BlackUART Class Reference

Interacts with end user, to use UART. More...

#include <BlackUART.h>

Inheritance diagram for BlackLib::BlackUART:

Public Types

enum  flags {
  dtErr = 1,
  openErr = 2,
  closeErr = 3,
  directionErr = 4,
  flushErr = 5,
  readErr = 6,
  writeErr = 7,
  baudRateErr = 8,
  parityErr = 9,
  stopBitsErr = 10,
  charSizeErr = 11
}
 

Public Member Functions

 BlackUART (uartName uart, baudRate uartBaud, parity uartParity, stopBits uartStopBits, characterSize uartCharSize)
 Constructor of BlackUART class. More...
 
 BlackUART (uartName uart, BlackUartProperties uartProperties)
 Constructor of BlackUART class. More...
 
 BlackUART (uartName uart)
 Constructor of BlackUART class. More...
 
virtual ~BlackUART ()
 Destructor of BlackUART class. More...
 
bool open (uint openMode)
 Opens TTY file of uart. More...
 
bool close ()
 Closes TTY file of uart. More...
 
bool flush (direction whichDirection)
 Flushes uart line. More...
 
std::string read ()
 Reads values from uart line. More...
 
bool read (char *readBuffer, size_t size)
 Reads values from uart line. More...
 
bool write (std::string writeBuffer)
 Writes values to uart line. More...
 
bool write (char *writeBuffer, size_t size)
 Writes values to uart line. More...
 
bool transfer (char *writeBuffer, char *readBuffer, size_t size, uint32_t wait_us)
 Writes and reads values sequentially to/from uart line. More...
 
std::string transfer (std::string writeBuffer, uint32_t wait_us)
 Writes and reads values sequentially to/from uart line. More...
 
void setReadBufferSize (uint32_t newBufferSize)
 Changes internal temporary buffers' sizes. More...
 
bool setBaudRate (baudRate newBaud, direction whichDirection, uartApplyMode applyMode=ApplyNow)
 Changes baud rate of uart. More...
 
bool setParity (parity newParity, uartApplyMode applyMode=ApplyNow)
 Changes parity of uart. More...
 
bool setStopBits (stopBits newStopBits, uartApplyMode applyMode=ApplyNow)
 Changes stop bits size of uart. More...
 
bool setCharacterSize (characterSize newCharacterSize, uartApplyMode applyMode=ApplyNow)
 Changes character size of uart. More...
 
bool setProperties (BlackUartProperties &props, uartApplyMode applyMode=ApplyNow)
 Changes properties of uart. More...
 
BlackUartProperties getProperties ()
 Exports properties of uart. More...
 
std::string getPortName ()
 Exports uart's port path. More...
 
uint32_t getReadBufferSize ()
 Exports internal temporary buffers' size. More...
 
baudRate getBaudRate (direction whichDirection)
 Exports baud rate value of uart. More...
 
parity getParity ()
 Exports parity value of uart. More...
 
stopBits getStopBits ()
 Exports stop bits size value of uart. More...
 
characterSize getCharacterSize ()
 Exports character size value of uart. More...
 
bool isOpen ()
 Checks uart's tty file's open state. More...
 
bool isClose ()
 Checks uart's tty file's close state. More...
 
bool fail ()
 Is used for general debugging. More...
 
bool fail (BlackUART::flags f)
 Is used for specific debugging. More...
 
BlackUARToperator<< (std::string &writeFromThis)
 Writes values to uart line with "<<" operator. More...
 
BlackUARToperator>> (std::string &readToThis)
 Reads values from uart line with ">>" operator. More...
 

Private Member Functions

bool loadDeviceTree ()
 Loads UART overlay to device tree. More...
 
- Private Member Functions inherited from BlackLib::BlackCore
 BlackCore ()
 Constructor of BlackCore class. More...
 
virtual ~BlackCore ()
 Destructor of BlackCore class. More...
 
std::string searchDirectoryOcp (BlackCore::ocpSearch searchThis)
 Searches ocp directory to find specified file/directory. More...
 
errorCoregetErrorsFromCore ()
 Exports errorCore struct to derived class. More...
 
std::string getCapeMgrName ()
 Exports capemgr name to derived class. More...
 
std::string getOcpName ()
 Exports ocp name to derived class. More...
 
std::string getSlotsFilePath ()
 Exports slots file path to derived class. More...
 

Private Attributes

BlackUartProperties defaultUartProperties
 is used to hold the default properties of uart More...
 
BlackUartProperties currentUartProperties
 is used to hold the current properties of uart More...
 
BlackUartProperties constructorProperties
 is used to hold the user specified properties of uart More...
 
errorUARTuartErrors
 is used to hold the errors of BlackUART class More...
 
std::string dtUartFilename
 is used to hold the uart's device tree overlay name More...
 
std::string uartPortPath
 is used to hold the uart's tty port path More...
 
uint32_t readBufferSize
 is used to hold the size of temporary buffer More...
 
int uartFD
 is used to hold the uart's tty file's file descriptor More...
 
bool isOpenFlag
 is used to hold the uart's tty file's state More...
 
bool isCurrentEqDefault
 is used to hold the properties of uart is equal to default properties More...
 

Additional Inherited Members

- Private Types inherited from BlackLib::BlackCore
enum  ocpSearch {
  ADC_helper = 0,
  PWM_P8_13 = 1,
  PWM_P8_19 = 2,
  PWM_P9_14 = 3,
  PWM_P9_16 = 4,
  PWM_P9_21 = 5,
  PWM_P9_22 = 6,
  PWM_P9_42 = 7,
  SPI0 = 8,
  SPI1 = 9
}
 

Detailed Description

Interacts with end user, to use UART.

This class is end node to use uart. End users interact with uart from this class. It includes public functions to set and get properties of uart's and to read, write and transfer datas.

Example
EXAMPLE PROJECT FILE TREE:

   myUartProject
   |-> src
       |-> BlackLib
           |-> BlackDirectory
               |-> BlackDirectory.cpp
               |-> BlackDirectory.h
           |-> BlackThread
               |-> BlackThread.cpp
               |-> BlackThread.h
           |-> BlackMutex
               |-> BlackMutex.cpp
               |-> BlackMutex.h
           |-> BlackTime
               |-> BlackTime.cpp
               |-> BlackTime.h
           |-> BlackADC
               |-> BlackADC.cpp
               |-> BlackADC.h
           |-> BlackGPIO
               |-> BlackGPIO.cpp
               |-> BlackGPIO.h
           |-> BlackI2C
               |-> BlackI2C.cpp
               |-> BlackI2C.h
           |-> BlackPWM
               |-> BlackPWM.cpp
               |-> BlackPWM.h
           |-> BlackSPI
               |-> BlackSPI.cpp
               |-> BlackSPI.h
           |-> BlackUART
               |-> BlackUART.cpp
               |-> BlackUART.h
           |-> BlackCore.cpp
           |-> BlackCore.h
           |-> BlackDef.h
           |-> BlackErr.h
           |-> BlackLib.h
       |-> myUartProject.cpp


If BlackLib source files are located in your project like above example project file tree, you have to include BlackUART.h or another source files with adding this line to your project file (myUartProject.cpp at the example):
#include "BlackLib/BlackUART/BlackUART.h"


If BlackLib source files are located at same level with your project file (myUartProject.cpp at the example), you have to include BlackUART.h or another source files with adding this line to your project file:

// Filename: myUartProject.cpp
// Author: Yiğit Yüce - ygtyce@gmail.com
#include <iostream>
#include "BlackLib/BlackUART/BlackUART.h"
int main()
{
std::string testMessage = "This is uart test message.";
std::cout << myUart.transfer(testMessage, 40000);
return 0;
}


You can use "using namespace BlackLib" also. You can get rid of writing "BlackLib::", with using this method.
// Filename: myUartProject.cpp
// Author: Yiğit Yüce - ygtyce@gmail.com
#include <iostream>
#include "BlackLib/BlackUART/BlackUART.h"
using namespace BlackLib;
int main()
{
BlackUART myUart(UART1,
Char8 );
myUart.open( ReadWrite | NonBlock);
std::string testMessage = "This is uart test message.";
std::cout << myUart.transfer(testMessage, 40000);
return 0;
}

Member Enumeration Documentation

This enum is used to define UART debugging flags.

Enumerator
dtErr 

enumeration for errorUART::dtError status

openErr 

enumeration for errorUART::openError status

closeErr 

enumeration for errorUART::closeError status

directionErr 

enumeration for errorUART::directionError status

flushErr 

enumeration for errorUART::flushError status

readErr 

enumeration for errorUART::readError status

writeErr 

enumeration for errorUART::writeError status

baudRateErr 

enumeration for errorUART::baudRateError status

parityErr 

enumeration for errorUART::parityError status

stopBitsErr 

enumeration for errorUART::stopBitsError status

charSizeErr 

enumeration for errorUART::charSizeError status

Constructor & Destructor Documentation

BlackLib::BlackUART::BlackUART ( uartName  uart,
baudRate  uartBaud,
parity  uartParity,
stopBits  uartStopBits,
characterSize  uartCharSize 
)

Constructor of BlackUART class.

This function initializes errorUART struct, sets value of constructorProperties struct and local variables. Then calls device tree loading function.

Parameters
[in]uartname of uart (enum),(UARTx)
[in]uartBaudbaud rate of uart (enum)
[in]uartParityparity of uart (enum)
[in]uartStopBitsstop bits of uart (enum)
[in]uartCharSizecharacter size of uart (enum)
Example
See also
loadDeviceTree()
uartName
baudRate
parity
stopBits
characterSize
BlackLib::BlackUART::BlackUART ( uartName  uart,
BlackUartProperties  uartProperties 
)

Constructor of BlackUART class.

This function initializes errorUART struct, sets value of constructorProperties struct and local variables. Then calls device tree loading function.

Parameters
[in]uartname of uart (enum),(UARTx)
[in]uartPropertiesimport properties from outside
Example
See also
loadDeviceTree()
uartName
BlackUartProperties
BlackLib::BlackUART::BlackUART ( uartName  uart)

Constructor of BlackUART class.

This function initializes errorUART struct, sets local variables. Then calls device tree loading function. Objects which are initialized from BlackUART class with this constructor, uses default uart properties.

Parameters
[in]uartname of uart (enum),(UARTx)
Example
See also
loadDeviceTree()
uartName
BlackLib::BlackUART::~BlackUART ( )
virtual

Destructor of BlackUART class.

This function closes TTY file and deletes errorUART struct pointer.

Member Function Documentation

bool BlackLib::BlackUART::close ( )

Closes TTY file of uart.

This function closes uart's TTY file and changes BlackUART::isOpenFlag's value.

Returns
True if tty file closing successful, else false.
Example
See also
BlackUART::isOpenFlag
bool BlackLib::BlackUART::fail ( )

Is used for general debugging.

Returns
True if any error occured, else false.
Example
myUart.open( BlackLib::ReadWrite );
if( myUart.fail() )
{
std::cout << "ERROR OCCURED" << std::endl;
}
else
{
std::cout << "EVERYTHING IS OK" << std::endl;
}
// Possible Output:
// EVERYTHING IS OK
See also
errorUART
bool BlackLib::BlackUART::fail ( BlackUART::flags  f)

Is used for specific debugging.

You can use this function, after call BlackUART member functions in your code. The input parameter is used for finding out status of selected error.

Parameters
[in]fspecific error type (enum)
Returns
Value of selected error.
Example
if( myUart.fail(BlackLib::BlackUART::dtErr) )
{
std::cout << "BlackUART INITIALIZATION FAILED" << std::endl;
}
else
{
std::cout << "BlackUART INITIALIZATION IS OK" << std::endl;
}
if( myUart.fail(BlackLib::BlackUART::openErr) )
{
std::cout << "OPENNING ERROR OCCURED" << std::endl;
}
else
{
std::cout << "OPENNING IS OK" << std::endl;
}
myUart.flush( BlackLib::bothDirection );
{
std::cout << "FLUSHING ERROR OCCURED" << std::endl;
}
else
{
std::cout << "FLUSHING IS OK" << std::endl;
}
std::string writeThis = "Loopback test message.";
std::string readThis = myUart.transfer( writeThis, 40000 );
{
std::cout << "TRANSFER ERROR OCCURED" << std::endl;
}
else
{
std::cout << "TRANSFER IS OK" << std::endl;
}
// Possible Output:
// BlackUART INITIALIZATION IS OK
// OPENNING IS OK
// FLUSHING IS OK
// TRANSFER IS OK
See also
errorUART
bool BlackLib::BlackUART::flush ( direction  whichDirection)

Flushes uart line.

This function flushes uart line at specified direction.

Parameters
[in]whichDirectionflushing direction
Returns
True if flushing successful, else false.
Example
See also
direction
baudRate BlackLib::BlackUART::getBaudRate ( direction  whichDirection)

Exports baud rate value of uart.

This function Exports baud rate value of uart at specified direction.

Parameters
[in]whichDirectiondirection
Returns
baud rate value of uart.
Example
Example usage is shown in BlackUART::setBaudRate() function's example.
See also
baudRate
direction
characterSize BlackLib::BlackUART::getCharacterSize ( )

Exports character size value of uart.

Returns
character size value of uart.
Example
Example usage is shown in BlackUART::setCharacterSize() function's example.
See also
characterSize
parity BlackLib::BlackUART::getParity ( )

Exports parity value of uart.

Returns
parity value of uart.
Example
Example usage is shown in BlackUART::setParity() function's example.
See also
parity
std::string BlackLib::BlackUART::getPortName ( )

Exports uart's port path.

Returns
uart's port path as string.
Example
// Possible Output:
// Port path: /dev/ttyO1
See also
uartPortPath
BlackUartProperties BlackLib::BlackUART::getProperties ( )

Exports properties of uart.

This function gets properties of uart. These properties are composed of baud rate, parity, stop bits size and character size.

Returns
BlackUART::currentUartProperties struct with updated values.
Example
Example usage is shown in BlackUART::setProperties() function's example.
See also
BlackUartProperties
uint32_t BlackLib::BlackUART::getReadBufferSize ( )

Exports internal temporary buffers' size.

Returns
size of internal temporary buffers.
Example
Example usage is shown in BlackUART::setReadBufferSize() function's example.
See also
readBufferSize
stopBits BlackLib::BlackUART::getStopBits ( )

Exports stop bits size value of uart.

Returns
stop bits size value of uart.
Example
Example usage is shown in BlackUART::setStopBits() function's example.
See also
stopBits
bool BlackLib::BlackUART::isClose ( )

Checks uart's tty file's close state.

Returns
true if tty file is close, else false.
Example
std::cout << "Is close?: " << std::boolalpha << myUart.isClose() << std::endl;
std::cout << "Is close?: " << std::boolalpha << myUart.isClose();
// Possible Output:
// Is close?: true
// Is close?: false
See also
BlackUART::isOpenFlag
bool BlackLib::BlackUART::isOpen ( )

Checks uart's tty file's open state.

Returns
true if tty file is open, else false.
Example
std::cout << "Is open?: " << std::boolalpha << myUart.isOpen() << std::endl;
std::cout << "Is open?: " << std::boolalpha << myUart.isOpen();
// Possible Output:
// Is open?: false
// Is open?: true
See also
BlackUART::isOpenFlag
bool BlackLib::BlackUART::loadDeviceTree ( )
privatevirtual

Loads UART overlay to device tree.

This function loads BlackUART::dtUartFilename named overlay to device tree. This file name changes with uartName constructor parameter. This overlay performs pinmuxing and generates device driver.

Returns
True if successful, else false.

Implements BlackLib::BlackCore.

bool BlackLib::BlackUART::open ( uint  openMode)

Opens TTY file of uart.

This function opens uart's TTY file with selected open mode, gets default properties of UART and saves this properties to BlackUART::defaultUartProperties struct. Then sets properties which are specified at class initialization stage. Users can send "or"ed BlackLib::openMode enums as parameter to this function.

Warning
After initialization of BlackUART class, this function must call. Otherwise users could not use any of data sending or receiving functions.
Parameters
[in]openModefile opening mode
Returns
True if tty file opening successful, else false.
Example
See also
openMode
BlackUART & BlackLib::BlackUART::operator<< ( std::string &  writeFromThis)

Writes values to uart line with "<<" operator.

This function writes values to uart line. Values sent to this function as string type.

Parameters
[in]&writeFromThisto uart
Example
myUart.flush( BlackLib::bothDirection );
std::string writeToUart = "this is test.\n";
myUart << writeToUart;
sleep(1);
std::string readFromUart;
myUart >> readFromUart;
std::cout << "Test output on loopback: " << readFromUart;
// Possible Output:
// Test output on loopback: this is test.
BlackUART & BlackLib::BlackUART::operator>> ( std::string &  readToThis)

Reads values from uart line with ">>" operator.

This function reads values from uart line with ">>" operator. It creates temporary read buffer with specified size and reads values to this buffer. Then resize buffer to read value size. BlackUART::readBufferSize variable is used to specify temporary buffer size.

Parameters
[in]&readToThisfrom uart. If reading fails, this functions sets BlackLib::UART_READ_FAILED string to this variable.
Example
myUart.flush( BlackLib::bothDirection );
std::string writeToUart = "this is test.\n";
myUart << writeToUart;
sleep(1);
std::string readFromUart;
myUart >> readFromUart;
std::cout << "Test output on loopback: " << readFromUart;
// Possible Output:
// Test output on loopback: this is test.
std::string BlackLib::BlackUART::read ( )

Reads values from uart line.

This function reads values from uart line and returns read value as string. It creates temporary read buffer with specified size and reads values to this buffer. Then resize buffer to read value size. BlackUART::readBufferSize variable is used to specify temporary buffer size.

Returns
read value if reading successful, else returns BlackLib::UART_READ_FAILED string.
Example
myUart.flush( BlackLib::bothDirection );
std::string writeToUart = "this is test.\n";
myUart.write(writeToUart);
sleep(1);
std::string readFromUart = myUart.read();
std::cout << "Test output on loopback: " << readFromUart;
// Possible Output:
// Test output on loopback: this is test.
See also
BlackUART::readBufferSize
bool BlackLib::BlackUART::read ( char *  readBuffer,
size_t  size 
)

Reads values from uart line.

This function reads values from uart line and saves read value to readBuffer pointer. It creates temporary read buffer with specified size and reads values to this buffer. Then copies buffer to readBuffer pointer.

Parameters
[out]readBufferbuffer pointer
[in]sizebuffer size
Returns
true if reading successful, else false.
Example
myUart.flush( BlackLib::bothDirection );
std::string writeToUart = "this is test.\n";
myUart.write(writeToUart);
sleep(1);
char readBuffer[14];
myUart.read(readBuffer, sizeof(readBuffer));
std::cout << "Test output on loopback: " << readBuffer;
// Possible Output:
// Test output on loopback: this is test.
bool BlackLib::BlackUART::setBaudRate ( baudRate  newBaud,
direction  whichDirection,
uartApplyMode  applyMode = ApplyNow 
)

Changes baud rate of uart.

This function changes baud rate of uart at specified direction. Also users can select apply condition like ApplyNow, ApplyDrain, ApplyFlush.

Parameters
[in]newBaudnew baud rate value
[in]whichDirectiondirection
[in]applyModenew value's apply condition
Returns
true if changing operation is successful, else false.
Warning
Before use this function, users must be called open function. If uart is not open, this function returns false and sets errorUART::baudRateError and errorUART::openError flags.
Example
// 13 means Baud9600. See the BlackLib::baudRate enums.
std::cout << "Current baud rate: " << myUart.getBaudRate(BlackLib::output) << std::endl;
// 14 means Baud19200. See the BlackLib::baudRate enums.
std::cout << "Current baud rate: " << myUart.getBaudRate(BlackLib::output);
// Possible Output:
// Current baud rate: 13
// Current baud rate: 14
See also
baudRate
direction
uartApplyMode
bool BlackLib::BlackUART::setCharacterSize ( characterSize  newCharacterSize,
uartApplyMode  applyMode = ApplyNow 
)

Changes character size of uart.

This function changes character size of uart. Also users can select apply condition like ApplyNow, ApplyDrain, ApplyFlush.

Parameters
[in]newCharacterSizenew character size value
[in]applyModenew value's apply condition
Returns
true if changing operation is successful, else false.
Warning
Before use this function, users must be called open function. If uart is not open, this function returns false and sets errorUART::charSizeError and errorUART::openError flags.
Example
// 8 means Char8. See the BlackLib::characterSize enums.
std::cout << "Current character size: " << myUart.getCharacterSize() << std::endl;
myUart.setCharacterSize(BlackLib::Char7, BlackLib::ApplyNow);
// 7 means Char7. See the BlackLib::characterSize enums.
std::cout << "Current character size: " << myUart.getCharacterSize();
// Possible Output:
// Current character size: 8
// Current character size: 7
See also
characterSize
uartApplyMode
bool BlackLib::BlackUART::setParity ( parity  newParity,
uartApplyMode  applyMode = ApplyNow 
)

Changes parity of uart.

This function changes parity of uart. Also users can select apply condition like ApplyNow, ApplyDrain, ApplyFlush.

Parameters
[in]newParitynew parity value
[in]applyModenew value's apply condition
Returns
true if changing operation is successful, else false.
Warning
Before use this function, users must be called open function. If uart is not open, this function returns false and sets errorUART::parityError and errorUART::openError flags.
Example
// 2 means ParityEven. See the BlackLib::parity enums.
std::cout << "Current parity: " << myUart.getParity() << std::endl;
// 1 means ParityOdd. See the BlackLib::parity enums.
std::cout << "Current parity: " << myUart.getParity();
// Possible Output:
// Current parity: 2
// Current parity: 1
See also
parity
uartApplyMode
bool BlackLib::BlackUART::setProperties ( BlackUartProperties props,
uartApplyMode  applyMode = ApplyNow 
)

Changes properties of uart.

This function changes properties of uart. Also users can select apply condition like ApplyNow, ApplyDrain, ApplyFlush. These properties are composed of baud rate, parity, stop bits size and character size.

Parameters
[in]&propsnew properties
[in]applyModenew properties' apply condition
Returns
true if changing operation is successful, else false.
Warning
Before use this function, users must be called open function. If uart is not open, this function returns false and sets errorUART::baudRateError, errorUART::charSizeError, errorUART::parityError, errorUART::stopBitsError and errorUART::openError flags.
Example
BlackLib::BlackUartProperties currentProps = myUart.getProperties();
std::cout << "First bauds(in/out) : " << currentProps.uartBaudIn << "/" << currentProps.uartBaudIn << std::endl
<< "First parity : " << currentProps.uartParity << std::endl
<< "First stop bits size: " << currentProps.uartStopBits << std::endl
<< "First character size: " << currentProps.uartCharSize << std::endl;
myUart.setProperties(currentProps, BlackLib::ApplyNow);
std::cout << "Second bauds(in/out) : " << currentProps.uartBaudIn << "/" << currentProps.uartBaudIn << std::endl
<< "Second parity : " << currentProps.uartParity << std::endl
<< "Second stop bits size: " << currentProps.uartStopBits << std::endl
<< "Second character size: " << currentProps.uartCharSize << std::endl;
// Possible Output:
// First bauds(in/out) : 13/13
// First parity : 2
// First stop bits size: 1
// First character size: 8
// Second bauds(in/out) : 14/14
// Second parity : 1
// Second stop bits size: 2
// Second character size: 7
See also
BlackUartProperties
uartApplyMode
void BlackLib::BlackUART::setReadBufferSize ( uint32_t  newBufferSize)

Changes internal temporary buffers' sizes.

This function changes internal buffers' sizes which are used at read and transfer operations. This buffer size must be maximum possible read value size. Otherwise read value will truncate.

Parameters
[in]newBufferSizenew size of the temporary internal buffer
Example
std::cout << "Current temporary buffer size: " << myUart.getReadBufferSize() << std::endl;
myUart.setReadBufferSize(2048);
std::cout << "Current temporary buffer size: " << myUart.getReadBufferSize();
// Possible Output:
// Current temporary buffer size: 1024
// Current temporary buffer size: 2048
See also
BlackUART::readBufferSize
bool BlackLib::BlackUART::setStopBits ( stopBits  newStopBits,
uartApplyMode  applyMode = ApplyNow 
)

Changes stop bits size of uart.

This function changes stop bits size of uart. Also users can select apply condition like ApplyNow, ApplyDrain, ApplyFlush.

Parameters
[in]newStopBitsnew stop bits size value
[in]applyModenew value's apply condition
Returns
true if changing operation is successful, else false.
Warning
Before use this function, users must be called open function. If uart is not open, this function returns false and sets errorUART::stopBitsError and errorUART::openError flags.
Example
// 1 means StopOne. See the BlackLib::stopBits enums.
std::cout << "Current stop bits size: " << myUart.getStopBits() << std::endl;
// 2 means StopTwo. See the BlackLib::stopBits enums.
std::cout << "Current stop bits size: " << myUart.getStopBits();
// Possible Output:
// Current stop bits size: 1
// Current stop bits size: 2
See also
stopBits
uartApplyMode
bool BlackLib::BlackUART::transfer ( char *  writeBuffer,
char *  readBuffer,
size_t  size,
uint32_t  wait_us 
)

Writes and reads values sequentially to/from uart line.

This function writes values to uart line firstly and then reads values from uart line and saves read value to readBuffer pointer. It creates temporary read buffer with specified size and reads values to this buffer. Then it copies buffer to readBuffer pointer. This function waits between writing and reading operations.

Parameters
[in]writeBuffervalues buffer
[out]readBufferread buffer pointer
[in]sizebuffer size
[in]wait_ussleep time between writing and reading
Returns
true if transfering successful, else false.
Example
myUart.flush( BlackLib::bothDirection );
char writeBuffer[] = "this is test.\n";
char readBuffer[ myUart.getReadBufferSize() ];
myUart.transfer(writeBuffer, readBuffer, sizeof(writeBuffer), 40000);
std::cout << "Test output on loopback: " << readBuffer;
// Possible Output:
// Test output on loopback: this is test.
See also
BlackUART::readBufferSize
std::string BlackLib::BlackUART::transfer ( std::string  writeBuffer,
uint32_t  wait_us 
)

Writes and reads values sequentially to/from uart line.

This function writes values to uart line firstly and then reads values from uart line and returns read value as string. It creates temporary read buffer with specified size and reads values to this buffer. Then resize buffer to read value size. BlackUART::readBufferSize variable is used to specify temporary buffer size.

Parameters
[in]writeBufferwrite buffer
[in]wait_ussleep time between writing and reading
Returns
read value if reading successful, else returns BlackLib::UART_READ_FAILED or BlackLib::UART_WRITE_FAILED string.
Example
myUart.flush( BlackLib::bothDirection );
std::string writeToUart = "this is test.\n";
std::string readFromUart;
readFromUart = myUart.transfer(writeToUart, 40000);
std::cout << "Test output on loopback: " << readFromUart;
// Possible Output:
// Test output on loopback: this is test.
See also
BlackUART::readBufferSize
bool BlackLib::BlackUART::write ( std::string  writeBuffer)

Writes values to uart line.

This function writes values to uart line. Values sent to this function as string type.

Parameters
[in]writeBuffervalues buffer
Returns
true if writing successful, else false.
Example
myUart.flush( BlackLib::bothDirection );
std::string writeToUart = "this is test.\n";
myUart.write(writeToUart);
sleep(1);
std::string readFromUart = myUart.read();
std::cout << "Test output on loopback: " << readFromUart;
// Possible Output:
// Test output on loopback: this is test.
bool BlackLib::BlackUART::write ( char *  writeBuffer,
size_t  size 
)

Writes values to uart line.

This function writes values to uart line. Values sent to this function as c-style string(char array).

Parameters
[in]writeBuffervalues buffer
[in]sizebuffer size
Returns
true if writing successful, else false.
Example
myUart.flush( BlackLib::bothDirection );
char writeBuffer[] = "this is test.\n";
myUart.write(writeBuffer, sizeof(writeBuffer));
sleep(1);
std::string readFromUart = myUart.read();
std::cout << "Test output on loopback: " << readFromUart;
// Possible Output:
// Test output on loopback: this is test.

Member Data Documentation

BlackUartProperties BlackLib::BlackUART::constructorProperties
private

is used to hold the user specified properties of uart

BlackUartProperties BlackLib::BlackUART::currentUartProperties
private

is used to hold the current properties of uart

BlackUartProperties BlackLib::BlackUART::defaultUartProperties
private

is used to hold the default properties of uart

std::string BlackLib::BlackUART::dtUartFilename
private

is used to hold the uart's device tree overlay name

bool BlackLib::BlackUART::isCurrentEqDefault
private

is used to hold the properties of uart is equal to default properties

bool BlackLib::BlackUART::isOpenFlag
private

is used to hold the uart's tty file's state

uint32_t BlackLib::BlackUART::readBufferSize
private

is used to hold the size of temporary buffer

errorUART* BlackLib::BlackUART::uartErrors
private

is used to hold the errors of BlackUART class

int BlackLib::BlackUART::uartFD
private

is used to hold the uart's tty file's file descriptor

std::string BlackLib::BlackUART::uartPortPath
private

is used to hold the uart's tty port path


The documentation for this class was generated from the following files: