PropellerSession Class Reference

The PropellerSession class provides a persistent interface to Propeller hardware via PropellerManager. More...

#include <PropellerSession>

Inherits QObject.

Signals

void bytesWritten (qint64 bytes)
 
void readyRead ()
 
void baudRateChanged (qint32 baudRate)
 
void sendError (const QString &message)
 
void deviceFree ()
 
void deviceBusy ()
 

Public Member Functions

 PropellerSession (PropellerManager *manager, const QString &portname=QString(), QObject *parent=0)
 
 ~PropellerSession ()
 
const QString & portName ()
 
void setPortName (const QString &name)
 
bool isOpen ()
 
Access Control
bool reserve ()
 
bool isReserved ()
 
void release ()
 
void pause ()
 
bool isPaused ()
 
void unpause ()
 
Device I/O
bool clear ()
 
bool setBaudRate (quint32 baudRate)
 
qint64 bytesToWrite ()
 
qint64 bytesAvailable ()
 
QByteArray read (qint64 maxSize)
 
QByteArray readAll ()
 
bool putChar (char c)
 
qint64 write (const QByteArray &byteArray)
 
int error ()
 
QString errorString ()
 
Download-Related
void useReset (const QString &name, int pin)
 
void useDefaultReset ()
 
bool reset ()
 
quint32 resetPeriod ()
 
quint32 minimumTimeout ()
 
void setMinimumTimeout (quint32 milliseconds)
 
quint32 calculateTimeout (quint32 bytes)
 

Detailed Description

The PropellerSession class provides a persistent interface to Propeller hardware via PropellerManager.

Sessions can communicate with any available device without needing to manually open and close ports. Many sessions can be connected to a single device at a time. However, sessions may also request exclusive access to a device to complete a long-running operation.

Usage

Using PropellerSession is easy because it handles all of the device setup transparently. In just a few lines of code, you'll be able to develop Propeller-based applications.

Here is a random function that writes some data to the device.

void writeToDevice()
{
PropellerSession session(&manager);
session.setPortName("ttyUSB0");
session.write(QByteArray("some data!"))
}

PropellerSession automatically disconnects from PropellerManager when destroyed, so manual cleanup isn't needed, and it's easy to make sure your connected devices don't end up in an invalid state.

See also
PropellerManager

Constructor & Destructor Documentation

PropellerSession::PropellerSession ( PropellerManager manager,
const QString &  portname = QString(),
QObject *  parent = 0 
)
PropellerSession::~PropellerSession ( )

Member Function Documentation

void PropellerSession::baudRateChanged ( qint32  baudRate)
signal

This signal is emitted after the baud rate has been changed. The new baud rate is passed as baudRate.

qint64 PropellerSession::bytesAvailable ( )

Returns the number of bytes waiting to be read from the device.

This function returns 0 if the device is busy.

qint64 PropellerSession::bytesToWrite ( )

Returns the number of bytes waiting to be written to the device.

This function returns 0 if the device is busy.

void PropellerSession::bytesWritten ( qint64  bytes)
signal

This signal is emitted once every time data has been written to the device. The bytes argument is the number of bytes that were written.

quint32 PropellerSession::calculateTimeout ( quint32  bytes)

Calculates a reasonable timeout value for writing the given number of bytes to the device.

Returns
the timeout value in milliseconds.
bool PropellerSession::clear ( )

Clear send and receive buffers for this session.

void PropellerSession::deviceBusy ( )
signal

This signal is emitted when the device has been reserved by another session.

void PropellerSession::deviceFree ( )
signal

This signal is emitted when the device becomes free for use again.

int PropellerSession::error ( )

Returns the error of the device.

Deprecated:
Errors are currently handled by PropellerDevice so this function is unlikely to return anything useful.
QString PropellerSession::errorString ( )

Returns the error string of the device.

Deprecated:
Errors are currently handled by PropellerDevice so this function is unlikely to return anything useful.
bool PropellerSession::isOpen ( )

Returns true if device is open, or false if not available or busy.

bool PropellerSession::isPaused ( )

Returns true if session is paused, otherwise returns false.

bool PropellerSession::isReserved ( )

Returns true if this session has reserved the device, otherwise false.

quint32 PropellerSession::minimumTimeout ( )

Returns the minimum timeout for this device.

void PropellerSession::pause ( )

Prevent session from sending or receiving data temporarily.

const QString & PropellerSession::portName ( )

Returns the name of the current device.

bool PropellerSession::putChar ( char  c)

Writes a single byte of data to the device.

Returns
True if the command was successful, otherwise returns false.
QByteArray PropellerSession::read ( qint64  maxSize)

Reads the number of byte specified by maxSize from the device.

Returns
A QByteArray containing the data, or an empty one if no data was available or the device was not available.
QByteArray PropellerSession::readAll ( )

Reads all of the available data from the device.

Returns
A QByteArray containing the data, or an empty one if there was no data or the device was not available.
void PropellerSession::readyRead ( )
signal

This signal is emitted every time new data is available for reading from the device.

void PropellerSession::release ( )

Releases the device so that other sessions can use it.

bool PropellerSession::reserve ( )

Reserve the device for exclusive access.

Returns
true if successfully reserved, otherwise false.
bool PropellerSession::reset ( )

Reset the connected device.

Returns
true if successful, false if not found or busy.
quint32 PropellerSession::resetPeriod ( )
void PropellerSession::sendError ( const QString &  message)
signal
bool PropellerSession::setBaudRate ( quint32  baudRate)

Set the baud rate of the device.

Note
This command can be used at any time, unlike some serial terminal implementations.
void PropellerSession::setMinimumTimeout ( quint32  milliseconds)

Sets the minimum timeout for this device.

void PropellerSession::setPortName ( const QString &  name)

Sets the name of the current device.

void PropellerSession::unpause ( )

Resuming sending and receiving data.

void PropellerSession::useDefaultReset ( )

Use the default reset strategy for this platform.

This command is not needed unless you have previously used useReset.

void PropellerSession::useReset ( const QString &  name,
int  pin 
)

Force the use of a specific reset strategy on this platform.

This function is usually not needed, but might be necessary if building PropellerManager for a platform that is not current supported.

qint64 PropellerSession::write ( const QByteArray &  byteArray)

Writes a QByteArray of data to the device.

Returns
The number of bytes written if successful, otherwise returns 0.