McuSerial Class Reference

MCU serial communication handler. More...

List of all members.

Public Types

enum  Status { unknown, error, cmd_ok, ans_ok }

Signals

void status (bool bOpen, McuSerial::Status eStatus)

Public Member Functions

bool open (const QString &qsPort)
void close ()
bool send (IMcuCmd *pCmd)
bool recv (IMcuAns *pAns, int nTimeout=200)
void flush ()

Static Public Member Functions

static void msleep (int nMsecs)

Static Private Member Functions

static QString hex (const QByteArray &aData)

Private Attributes

QextSerialPort * m_pSerPort
bool m_bOpen
Status m_eStatus
QString m_qsLastCmd


Detailed Description

MCU serial communication handler.

This class encapsulates the serial port that is used to talk to the MCU.

It provides methods for passing commands described by IMcuCmd derived classes to the MCU and filling in the received answers.


Member Function Documentation

bool McuSerial::send ( IMcuCmd pCmd  ) 

Send command pCmd over serial line to MCU

Typically send() is followed by an immediate recv(). Except a few special cases, a flush() should be issued before send().

Note:
: Care must be taken with conversions from/to QChar and QString:
  • Strings that are sent/received from the MCU must be converted with toLatin1()/fromLatin1()
  • Strings that come from source code must be converted with the editor's encoding, here fromUtf8()
  • Strings that are output to the debugging console must be converted with LQS() (i.e. toLocal8Bit())
See also:
recv(), flush()

bool McuSerial::recv ( IMcuAns pAns,
int  nTimeout = 200 
)

Recieve answer pAns from MCU serial line

Typically recv() is called immediately after send().

Since the communication with QExtSerialPort seems to be very fragile when attempting to read more answer characters than available, an iterative approach is chosen:

Note:
: Care must be taken with conversions from/to QChar and QString:
  • Strings that are sent/received from the MCU must be converted with toLatin1()/fromLatin1()
  • Strings that come from source code must be converted with the editor's encoding, here fromUtf8()
  • Strings that are output to the debugging console must be converted with LQS() (i.e. toLocal8Bit())
See also:
send()

void McuSerial::flush (  ) 

Flush serial receive queue.

For most commands, it is recommended to flush the receive queue befor sending a new command, to avoid stale answer bytes spoiling the real answer to this command.

There are exceptions where flushing is not wanted, i.e. while receiving a PEC table, where commands for reading each PEC value are issued and then all answers are read (for performance improvement).

See also:
send(), recv()

void McuSerial::msleep ( int  nMsecs  )  [static]

Sleep nMsecs milliseconds

Note:
: Use with care: will stall the GUI while sleeping when called from GUI thread

QString McuSerial::hex ( const QByteArray &  aData  )  [static, private]

Return binary data oData as hexdump and string of characters, with non-printable characters replaced by "."


The documentation for this class was generated from the following files:
Generated on Sun Jun 3 16:45:47 2007 for Aspect by  doxygen 1.5.1