How to Set when Write Calls Return: Tutorial

This tutorial follows on from the tutorial on How to transfer data.

Context

This tutorial follows on from the How to Transfer Data Tutorial. The RComm::Write() function can return when the data has been queued in the device driver buffer, or when the data has been sent by the device driver.

The RComm::Write() API can return in one of two ways:

  1. As soon as the data has been queued with the device driver.

    This allows the application to run while the data is sent so that the application can create the next block of data to send.

  2. After the device driver has sent the data.

    This is used when the application must wait for a response from the remote device after the data is sent.

The default value is dependent on the Serial Device Driver.

Steps

  1. Create an object of type TCommConfig.
  2. Call RComm::Config() with the aConfig parameter set to the TCommConfig object.

    The TCommConfig object now contains the port settings.
  3. To set the RComm::Write() API to return early, set the KConfigWriteBufferedComplete flag in the iHandshake field in the TCommconfig object. To set the RComm::Write() API to return after the data is sent, clear the KConfigWriteBufferedComplete flag in the iHandshake field in the TCommconfig object.
  4. Call RComm::SetConfig() with the aConfig parameter set to the TCommConfig object.

Example

TCommConfig portSettings;
commPort.Config(portSettings);
portSettings().iHandshake |= KConfigWriteBufferedComplete;     // set early complete
User::LeaveIfError (commPort.SetConfig(portSettings));