All data written to and read from the serial device is 8-bit even on a Unicode system. We therefore pass the RComm::Read()
function a reference to a TDes8
into which any received data is written, and we pass RComm::Write()
function a reference to a TDesC8
containing the data we want to transmit. Since both of these data transfer functions are asynchronous, they must therefore
be passed a reference to a TRequestStatus
.
Since data transfers are implemented using a client-server architecture, multiple read and write requests cannot be outstanding simultaneously.
Read requests will normally complete when the maximum length of the supplied buffer has been filled with data, while writes
normally complete when the last character in the supplied buffer has been written to the serial hardware. ReadCancel()
and WriteCancel()
are provided to enable an application to terminate any pending data transfer requests as needed (in response to a user request,
for example).
A port can be configured to automatically terminate data transfer requests early when various error conditions apply. Both
Read()
and Write()
are available in versions which allow you to specify an optional time-out in microseconds, which permit them to terminate
with a KErrTimedOut
status if the timer expires before normal completion.
As well as the standard Read()
function, RComm
provides an extra ReadOneOrMore()
function. This completes by reading any data which is in the input buffer (up to the length of the supplied descriptor) or,
if no data is present in the input buffer, as soon as the first character arrives at the serial port. This function enables
the input buffer to be emptied quickly without knowing how much data it contains. However, it is not available in any overloaded
versions, and consequently does not take an optional timeout.
The QueryReceiveBuffer()
function, which returns the number of characters in the input buffer, can be used to avoid making blocking calls to ReadOneOrMore()
when there is no data to be read.