BPS C++ API  2.24.4
BpsAsyncIO Class Reference

BPS asynchronous IO communications class, based on QIODevice. More...

#include <bpsasyncio.h>

+ Inheritance diagram for BpsAsyncIO:

Public Types

enum  BitRate {
  B110 , B300 , B600 , B1200 , B2400 , B4800 , B9600 , B19200 , B38400 , B57600 ,
  B115200
}
 Bits per second. More...
 
enum  DataBits { D5 , D6 , D7 , D8 }
 Number of data bits per word. More...
 
enum  FlowControl { NoFlowControl , Hard , Soft , HardAndSoft }
 Flow control. More...
 
enum  Parity { NoParity , Odd , Even , Mark , Space }
 Parity settings. More...
 
enum  StopBits { S1 , S1_5 , S2 }
 Number of stop bits per word. More...
 
- Public Types inherited from QIODevice
enum  OpenModeFlag
 

Signals

void error (const QString &aError)
 Signal emitted whenever an error is registered. More...
 

Public Member Functions

BitRate bitRate () const
 
 BpsAsyncIO (QObject *aParent=nullptr)
 
DataBits dataBits () const
 
QString error () const
 The last error message saved. More...
 
FlowControl flowControl () const
 
Parity parity () const
 
QString portName () const
 
void setBitRate (BitRate aBitRate)
 Set the bit rate. More...
 
void setDataBits (DataBits aDataBits)
 Set the number of data bits per word. More...
 
void setFlowControl (FlowControl aFlowControl)
 Set the flow control mode to use. More...
 
void setParity (Parity aParity)
 Set the parity to use. More...
 
void setPortName (const QString &aPortName)
 Set the port name. More...
 
void setStopBits (StopBits aStopBits)
 Set the number of stop bits to use. More...
 
void setup (const QMap< QString, QString > &aConfig)
 Initialize by values given in the config map. More...
 
void setWriteTimeout (quint32 aMillisecs)
 Set the write timeout in milliseconds. More...
 
StopBits stopBits () const
 
void unsetError ()
 Clears the error message returned by error().
 
quint32 writeTimeout () const
 
- Public Member Functions inherited from QIODevice
void aboutToClose ()
 
virtual bool atEnd () const const
 
virtual qint64 bytesAvailable () const const
 
virtual qint64 bytesToWrite () const const
 
void bytesWritten (qint64 bytes)
 
virtual bool canReadLine () const const
 
void channelBytesWritten (int channel, qint64 bytes)
 
void channelReadyRead (int channel)
 
virtual void close ()
 
void commitTransaction ()
 
int currentReadChannel () const const
 
int currentWriteChannel () const const
 
QString errorString () const const
 
bool getChar (char *c)
 
bool isOpen () const const
 
bool isReadable () const const
 
virtual bool isSequential () const const
 
bool isTextModeEnabled () const const
 
bool isTransactionStarted () const const
 
bool isWritable () const const
 
virtual bool open (QIODevice::OpenMode mode)
 
QIODevice::OpenMode openMode () const const
 
qint64 peek (char *data, qint64 maxSize)
 
QByteArray peek (qint64 maxSize)
 
virtual qint64 pos () const const
 
bool putChar (char c)
 
 QIODevice (QObject *parent)
 
qint64 read (char *data, qint64 maxSize)
 
QByteArray read (qint64 maxSize)
 
QByteArray readAll ()
 
int readChannelCount () const const
 
void readChannelFinished ()
 
qint64 readLine (char *data, qint64 maxSize)
 
QByteArray readLine (qint64 maxSize)
 
void readyRead ()
 
virtual bool reset ()
 
void rollbackTransaction ()
 
virtual bool seek (qint64 pos)
 
void setCurrentReadChannel (int channel)
 
void setCurrentWriteChannel (int channel)
 
void setTextModeEnabled (bool enabled)
 
virtual qint64 size () const const
 
qint64 skip (qint64 maxSize)
 
void startTransaction ()
 
void ungetChar (char c)
 
virtual bool waitForBytesWritten (int msecs)
 
virtual bool waitForReadyRead (int msecs)
 
qint64 write (const char *data)
 
qint64 write (const char *data, qint64 maxSize)
 
qint64 write (const QByteArray &byteArray)
 
int writeChannelCount () const const
 
- Public Member Functions inherited from QObject
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
 QObject (QObject *parent)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QStringList portNames ()
 Get a list of all asynchronous IO devices available on the current computer. More...
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Public Attributes inherited from QIODevice
 Append
 
 ExistingOnly
 
 NewOnly
 
 NotOpen
 
typedef OpenMode
 
 ReadOnly
 
 ReadWrite
 
 Text
 
 Truncate
 
 Unbuffered
 
 WriteOnly
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QIODevice
virtual qint64 readData (char *data, qint64 maxSize)=0
 
virtual qint64 readLineData (char *data, qint64 maxSize)
 
void setErrorString (const QString &str)
 
void setOpenMode (QIODevice::OpenMode openMode)
 
virtual qint64 writeData (const char *data, qint64 maxSize)=0
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

BPS asynchronous IO communications class, based on QIODevice.

Asynchronous devices are often called COM device on windows, or tty character devices on unix stemmed operating systems. Background operations are implemented with QTimer, so the signal readReady will only be auto fired when the opening thread has an event queue.

Member Enumeration Documentation

◆ BitRate

Bits per second.

Enumerator
B110 

110 bits/sec.

B300 

300 bits/sec.

B600 

600 bits/sec.

B1200 

1200 bits/sec.

B2400 

2400 bits/sec.

B4800 

4800 bits/sec.

B9600 

9600 bits/sec.

B19200 

19200 bits/sec.

B38400 

38400 bits/sec.

B57600 

57600 bits/sec.

B115200 

115200 bits/sec.

◆ DataBits

Number of data bits per word.

Enumerator
D5 

5 bits per word.

D6 

6 bits per word.

D7 

7 bits per word.

D8 

8 nits per word.

◆ FlowControl

Flow control.

Enumerator
NoFlowControl 

No flow control at all. DTR and RTS always on.

Hard 

Hardware flow control by DTR and RTS.

Soft 

Software flow control by XON/XOFF. DTR and RTS always on.

HardAndSoft 

Hardware flow control plus software flow control.

◆ Parity

Parity settings.

Enumerator
NoParity 

No parity at all.

Odd 

Odd parity.

Even 

Even parity.

Mark 

Always mark.

Space 

Always space.

◆ StopBits

Number of stop bits per word.

Enumerator
S1 

One stop bit per word.

S1_5 

One and a half stop bits per word.

S2 

Two stop bits per word.

Constructor & Destructor Documentation

◆ BpsAsyncIO()

BpsAsyncIO::BpsAsyncIO ( QObject aParent = nullptr)
Parameters
aParentPointer to an optional parent object.

Member Function Documentation

◆ bitRate()

BitRate BpsAsyncIO::bitRate ( ) const
Returns
The port name.

◆ dataBits()

DataBits BpsAsyncIO::dataBits ( ) const
Returns
The number of data bits per word.

◆ error() [1/2]

QString BpsAsyncIO::error ( ) const

The last error message saved.

For example, if open() returns false, or a read/write operation returns -1, this function can be called to get the according message.

Returns
The latest error message.

◆ error [2/2]

void BpsAsyncIO::error ( const QString aError)
signal

Signal emitted whenever an error is registered.

Parameters
aErrorThe error message generated.

◆ flowControl()

FlowControl BpsAsyncIO::flowControl ( ) const
Returns
The flow control.

◆ parity()

Parity BpsAsyncIO::parity ( ) const
Returns
The parity setting.

◆ portName()

QString BpsAsyncIO::portName ( ) const
Returns
The current port name.

◆ portNames()

static QStringList BpsAsyncIO::portNames ( )
static

Get a list of all asynchronous IO devices available on the current computer.

Returns
List of all COM/tty device names found.
Exceptions
BpsExceptionThrown on errors.

◆ setBitRate()

void BpsAsyncIO::setBitRate ( BitRate  aBitRate)

Set the bit rate.

The initial default value is B115200. Setting the bit rate must be done before opening the device.

Parameters
aBitRateThe bit rate to set.

◆ setDataBits()

void BpsAsyncIO::setDataBits ( DataBits  aDataBits)

Set the number of data bits per word.

The initial default value is D8. Setting the data bits must be done before opening the device.

Parameters
aDataBitsThe number of data bits per word.

◆ setFlowControl()

void BpsAsyncIO::setFlowControl ( FlowControl  aFlowControl)

Set the flow control mode to use.

Parameters
aFlowControlThe flow control mode. The initial default value is NoFlowControl. Setting the flow control must be done before opening the device.

◆ setParity()

void BpsAsyncIO::setParity ( Parity  aParity)

Set the parity to use.

The initial default value is NoParity. Setting the parity must be done before opening the device.

Parameters
aParityThe new parity to set.

◆ setPortName()

void BpsAsyncIO::setPortName ( const QString aPortName)

Set the port name.

On windows this is something like COM1, COM2 etc. On other systems it might be something like /dev/tty01. Setting the port name must be done before opening the device.

Parameters
aPortNameThe port name to use.

◆ setStopBits()

void BpsAsyncIO::setStopBits ( StopBits  aStopBits)

Set the number of stop bits to use.

The initial default value is S1. Setting the stop bits must be done before opening the device.

Parameters
aStopBitsThe number of stop bits.

◆ setup()

void BpsAsyncIO::setup ( const QMap< QString, QString > &  aConfig)

Initialize by values given in the config map.

Keys of the map are searched case insensitive.

KeyValue
PortThe serial port name, for example COM1 on windows, or /dev/tty01 on unixoid operating systems like OSX or Linux.
BitrateLine speed in bits/sec, one of 110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600 or 115200 (default).
DatabitsNumber of data bits in a word: 5, 6, 7 or 8 (default).
ParityOne of none (default), odd, even, mark or space.
StopbitsNumber of stop bits, either 1 (default), 1.5 or 2.
Flowcontrolnone: No flow control (default).
hard: Hardware flow control by CTS/RTS.
soft: Software flow control by XON/XOFF.
both: Both, hardware as well as software flow control.
Parameters
aConfigThe map of configuration values.

◆ setWriteTimeout()

void BpsAsyncIO::setWriteTimeout ( quint32  aMillisecs)

Set the write timeout in milliseconds.

A value of 0 disables write timeout and waits forever.

Parameters
aMillisecsThe flow control mode. The initial default value is 0. Setting the write timeout must be done before opening the device.

◆ stopBits()

StopBits BpsAsyncIO::stopBits ( ) const
Returns
The number of stop bits per word.

◆ writeTimeout()

quint32 BpsAsyncIO::writeTimeout ( ) const
Returns
Write timeout in milliseconds.

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