Faulhaber Serial Com Test  Version 1
A Qt interface to test Faulhaber MCBL 3006 motion controller
Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
FaulhaberSerial Class Reference

Class for communicating with Faulhaber MCBL 3006 through serial COM ports. More...

#include "FaulhaberSerial.h"

Public Member Functions

 FaulhaberSerial ()
 Constructor. More...
 
 ~FaulhaberSerial ()
 
void initialize (const QString pCOMPortName)
 Initialize the COM port member variables. More...
 
void attachErrorHandler (QSharedPointer< ErrorHandler > pDIOCard)
 
bool open (QString pBaudRate="19200", QString pParity="n", QString pByteSize="8", QString pStopBit="1")
 Open communication with the COM port. More...
 
bool close ()
 Close communication with the COM port. More...
 
bool receivePacket (int &pData)
 Read a full packet of data from the COM port. More...
 
bool send (int pUnit, QString pCommand, int pData, bool pUseData)
 Send a packet to the COM port. More...
 

Protected Attributes

QSerialPort * mSerialPort
 In Qt5, QSerialPort handles the COM port. More...
 
QSharedPointer< ErrorHandlermErrorHandler
 Error handler. More...
 
bool mIsPortInitialized
 Flag that defines if port has been initialized or not. More...
 
bool mIsOpen
 Flag that defines if port has been opened or not. More...
 

Static Protected Attributes

static const unsigned char CR = '\r'
 Carriage return character used as special end character when communicating with Faulhaber motors. More...
 
static const int RXTIMEOUT = 500
 Communication timeout limit in milliseconds. More...
 

Detailed Description


This class handles serial port communication with Faulhaber MCBL 3006 Motion Controller. It is based on QSerialPort provided in Qt5. It provides simpler methods for reading and writing to serial COM ports. It is designed for the commands required to control robots embding Faulhaber motors. It allows to control a set of n motors through a unique serial COM port. To begin communication with a port, you must first initialize it, then open it. The Faulhaber motors can have variable packet sizes and therefore use a special character (a carriage return ASCII character) to distinguish the end of the packet.

Constructor & Destructor Documentation

FaulhaberSerial::FaulhaberSerial ( )

Initializes all flags to False.

FaulhaberSerial::~FaulhaberSerial ( )

Member Function Documentation

void FaulhaberSerial::attachErrorHandler ( QSharedPointer< ErrorHandler pDIOCard)
void FaulhaberSerial::close ( )

This calls the QSerialPort::close() function.

See also
QSerialPort::close
void FaulhaberSerial::initialize ( const QString  pCOMPortName)

Initializes the COM port.

Parameters
[in]pPortNameName of the COM port used.
See also
QSerialPort::setPortName
bool FaulhaberSerial::open ( QString  pBaudRate = "19200",
QString  pParity = "n",
QString  pByteSize = "8",
QString  pStopBit = "1" 
)

This method first checks if the port isn't already open (using a QSerialPortInfo structure). It sets the baud rate, the number of data bits, the parity, the nomber of stop bits and the flow control. Finally, it opens the port for read and write.

Parameters
[in]pBaudRateBaud rate used for the communication.
[in]pParityParity used for the communication.
[in]pByteSizeNumber of data bits used for the communication.
[in]pStopBitNumber of stop bits used for the communication.
Returns
True if the port has been suffessfully opened and configured, false if an error occured.
See also
QSerialPortInfo::isBusy, QSerialPort::setBaudRate, QSerialPort::setDataBits, QSerialPort::setParity, QSerialPort::setStopBits, QSerialPort::setFlowControl(QSerialPort::NoFlowControl), QSerialPort::open(QIODevice::ReadWrite)
bool FaulhaberSerial::receivePacket ( int &  pData)

This method reads the COM port while new data is available. It keeps reading until either no new data is available or the RXTIMEOUT time limit is reached.

Parameters
[out]pDataThe data is converted from char* to int using atoi().
See also
QSerialPort::readAll, QSerialPort::waitForReadyRead, RXTIMEOUT
bool FaulhaberSerial::send ( int  pUnit,
QString  pCommand,
int  pData,
bool  pUseData 
)

This method sends a packet of bytes as a char* to the COM port as specified for the Faulhaber motors. The packet is constructed for the Faulhaber motors: it is sent as an array of ASCII characters with a CR character at the end, as explained in section 4 (page 50) of the Faulhaber 3006S Motion Controller Instruction Manual. For all commands, the QSerialPort::waitForBytesWritten() command is called with the RXTIMEOUT time limit, in order to ensure the full delivery of the packet.

Parameters
[in]pUnitUnit number of the motor to which the command should be sent.
[in]pCommandA string that defines the command to be sent.
[in]pDataThe optional integer data to be sent with the command (such as position, distance, speed, etc). If no data is necessary, then use 0.
[in]pUseDataA flag defining whether the pData parameter should be used or not when sending the command.
See also
QSerialPort::write, QSerialPort::waitForBytesWritten, CR, RXTIMEOUT

Member Data Documentation

const unsigned char FaulhaberSerial::CR = '\r'
staticprotected
QSharedPointer<ErrorHandler> FaulhaberSerial::mErrorHandler
protected
bool FaulhaberSerial::mIsOpen
protected
bool FaulhaberSerial::mIsPortInitialized
protected
QSerialPort* FaulhaberSerial::mSerialPort
protected
const int FaulhaberSerial::RXTIMEOUT = 500
staticprotected

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