Class for communicating with Faulhaber MCBL 3006 through serial COM ports.
More...
#include "FaulhaberSerial.h"
|
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...
|
|
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.
FaulhaberSerial::FaulhaberSerial |
( |
| ) |
|
Initializes all flags to False.
FaulhaberSerial::~FaulhaberSerial |
( |
| ) |
|
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] | pPortName | Name 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] | pBaudRate | Baud rate used for the communication. |
[in] | pParity | Parity used for the communication. |
[in] | pByteSize | Number of data bits used for the communication. |
[in] | pStopBit | Number 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] | pData | The 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] | pUnit | Unit number of the motor to which the command should be sent. |
[in] | pCommand | A string that defines the command to be sent. |
[in] | pData | The optional integer data to be sent with the command (such as position, distance, speed, etc). If no data is necessary, then use 0. |
[in] | pUseData | A flag defining whether the pData parameter should be used or not when sending the command. |
- See also
- QSerialPort::write, QSerialPort::waitForBytesWritten, CR, RXTIMEOUT
const unsigned char FaulhaberSerial::CR = '\r' |
|
staticprotected |
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: