Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: c32comm.h
Link against: c32.lib

Class RComm

RComm

Support

Supported from 5.0

Description

A serial port. It provides all the necessary functions for communicating via a port, including functions for opening, closing, reading, writing, together with port configuration and capability checking.

Derivation

RCommA serial port
RSubSessionBaseClient-side handle to a sub-session

Defined in RComm:
OpenWhenAvailableCancel(), Break(), BreakCancel(), Cancel(), Caps(), Close(), Config(), GetFlowControlStatus(), GetRole(), Mode(), NotifyBreak(), NotifyBreakCancel(), NotifyConfigChange(), NotifyConfigChangeCancel(), NotifyDataAvailable(), NotifyDataAvailableCancel(), NotifyFlowControlChange(), NotifyFlowControlChangeCancel(), NotifyOutputEmpty(), NotifyOutputEmptyCancel(), NotifySignalChange(), NotifySignalChangeCancel(), Open(), OpenWhenAvailable(), QueryReceiveBuffer(), Read(), ReadCancel(), ReadOneOrMore(), ReceiveBufferLength(), ResetBuffers(), SetAccessMode(), SetConfig(), SetMode(), SetReceiveBufferLength(), SetSignals(), SetSignalsToMark(), SetSignalsToSpace(), Signals(), Write(), WriteCancel()

Inherited from RSubSessionBase:
CloseSubSession(), CreateSubSession(), Send(), SendReceive(), SubSessionHandle(), operator=()


Opening ports


Open()

TInt Open(RCommServ &aServer, const TDesC &aName,TCommAccess aMode);

Description

Opens a serial port, for one of the three modes indicated by the TCommAccess argument. This may dictate exclusive use of the RComm, shared use (giving permission for the port to be shared by other RComms) or pre-emptable use (allowing another client to pre-empt this session with an open request in one of the other two modes). The request will fail if the port does not exist, or if it has been opened in exclusive mode elsewhere. If the port has been opened in shared mode elsewhere, the request will fail if a subsequent attempt is made to open it in exclusive mode.

Parameters

RCommServ &aServer

The comms server session

const TDesC &aName

The name of the port

TCommAccess aMode

The mode in which the port is opened. There is no default.

Return value

TInt

System-wide error code. KErrLocked if the port has already been opened in the opposite role elsewhere.


Open()

TInt Open(RCommServ &aServer, const TDesC &aName,TCommAccess aMode,TCommRole aRole);

Support

Supported from 6.0

Description

Opens a serial port, as described for the previous function. It allows the port to be opened in either DTE role or DCE role. This latter role means that the lines are configured as for a port of a modem. DTR and RTS are inputs while the other signals are outputs.

Parameters

RCommServ &aServer

The comms server session

const TDesC &aName

The name of the port

TCommAccess aMode

The mode in which the port is opened. There is no default.

TCommRole aRole

DTE/DCE role

Return value

TInt

System-wide error code. KErrLocked if the port has already been opened in the opposite role elsewhere.


OpenWhenAvailable()

void OpenWhenAvailable(TRequestStatus& aStatus, RCommServ &aServer, const TDesC &aName);

Support

Supported from 6.0

Description

Opens a serial port when it is freed by another client. When a client has a port open in either exclusive or shared mode, another client may use this function to gain access to the port when the owning client closes its handle. Upon closure, the asynchronous OpenWhenAvailable() function will complete. The port role, DTE or DCE, is not be changed by this request and so the role will be inherited from the previous session. The port is automatically opened in pre-emptive mode. This can be subsequently upgraded to shared or exclusive mode using the SetAccessMode() function.

Notes:

If client submits an OpenWhenAvailable() request and then attempts to execute an action, for example a read or write request, before the OpenWhenAvailable() has completed, the action will fail with the KErrNotReady error code.

The server can only support one OpenWhenAvailable() request per port. For example, if client A has a port open in exclusive mode and client B has an OpenWhenAvailable() request pending, then client C’s OpenWhenAvailable() request will fail with the KErrAccessDenied error code.

The server is designed to support the OpenWhenAvailable() request dispatched from a different RCommServ session than the one actively using the port. This is not viewed as a major disadvantage since, in practice, the two clients will normally be running in different threads, and quite probably different processes.

Parameters

RCommServ &aServer

The comms server session

const TDesC &aName

The name of the port

Return value

TInt

System-wide error code.


OpenWhenAvailableCancel()

void OpenWhenAvailableCancel();

Support

Supported from 6.0

Description

Cancels an OpenWhenAvailable() request.

[Top]


Closing ports


Close()

void Close();

Description

Closes a serial port.

[Top]


Configuring Ports


Cancel()

void Cancel();

Description

Cancels any pending reads and writes.

A panic will result if an attempt is made to reconfigure a port if there are any pending reads or writes. Use this function before configuring a port if there is any doubt as to whether it is safe to do so. It isn’t necessary to call Cancel() before closing a port as this is done automatically.


Caps()

void Caps(TDes8& aCaps);

Description

Reads the capabilities of the serial port.

As the serial driver can control a range of different physical devices with differing capabilities, it could be considered important from the point of view of the operating system to be able to read these capabilities before attempting to configure the port. In practice however, program development is likely to be targeted at a specific hardware configuration, and interrogation of a device to ascertain its capabilities isn’t normally necessary.

Parameters

const TDesC8& aCaps

On return this descriptor will contain either a packagedTCommCapsV01 structure or a packagedTCommCapsV02structure corresponding to the capabilities of the serial device and of the CSY module, depending on the size of the descriptor passed in to the function.


Config()

void Config(TDes8 &aConfig) const;

Description

Reads the current configuration of the serial port.

It isn’t essential to read an existing configuration in order to set a new one. However, calling this function is a useful way of initializing aTCommConfig structure and thus avoiding the overhead of having to explicitly set every member. If a port were being shared between difference processes, it would also be good manners to save an existing configuration before using the port in order than it might be restored when you have finished with it.

Parameters

TDes8 &aConfig

On return, a TCommConfig package buffer holding the configuration settings


SetAccessMode()

TInt SetAccessMode(TCommAccess aNewMode);

Support

Supported from 6.0

Description

Upgrades the mode of a port handle from pre-emptive mode to shared or exclusive mode.

Notes:

If a client attempts to change the mode of a port that is already in either shared or exclusive modes, the request will fail with theKErrNotSupported error code.

Clients should not attempt to change the access mode to pre-emptive, the behaviour in this case is unpredictable.

Parameters

TCommAccess aNewMode

The value of the new port mode, eitherECommSharedorECommExclusive


SetConfig()

TInt SetConfig(const TDesC8 &aConfig);

Description

Sets the configuration of the serial port.

It is not possible to reconfigure the capabilities of ports while they are being used. In particular, the comms server will panic any client that attempts to reconfigure a port when there are pending reads or writes.

Parameters

const TDesC8 &aConfig

New configuration settings packaged in a TCommConfig

Return value

TInt

System-wide error code


SetSignals()

void SetSignals(TUint aSetMask,TUint aClearMask);

Description

Sets or clears RS232 output lines (DTR and RTS).

For many applications, these lines will be read and set under driver control as determined by the handshaking options selected.

Parameters

TUint aSetMask

Set the handshaking lines in the mask.

TUint aClearMask

Clear the handshaking lines in the mask.

See also:


SetSignalsToMark()

void SetSignalsToMark(TUint aSignalMask);

Description

Sets the specified RS232 output lines.

Parameters

TUint aSignalMask

Bitmask of handshaking lines

See also:


SetSignalsToSpace()

void SetSignalsToSpace(TUint aSignalMask);

Description

Clears RS232 output lines.

Parameters

TUint aSignalMask

Bitmask of handshaking lines

See also:


Signals()

TUint Signals(TUint aSignalMask=0x3F) const;

Description

Reads the status of the RS232 input and output lines (RTS, CTS, DSR, DCD, DTR). They are bit-masked into a single integer and one or all of them can be read at any time.

Not all of the input lines are guaranteed to be available on all serial devices.

Parameters

TUint aSignalMask

Bitmask of lines to read. It defaults to all lines (0x3f as only the top six bits of this integer are valid). A different value can be specified as aSignalMask if specific information is required: for instance, Signals(KSignalDSR) could be used to find out if a modem were connected to the serial port.

Return value

TInt

An integer with the bits set to reflect the status of the handshaking lines

See also:

[Top]


Reading from ports


Read()

void Read(TRequestStatus &aStatus, TDes8 &aDes);
void Read(TRequestStatus &aStatus, TDes8 &aDes, TInt aLength);
void Read(TRequestStatus &aStatus, TTimeIntervalMicroSeconds32 aTimeOut,TDes8 &aDes);
void Read(TRequestStatus &aStatus, TTimeIntervalMicroSeconds32 aTimeOut,TDes8 &aDes, TInt aLength);

Description

Reads data from a serial port. All reads from the serial device use 8-bit descriptors as data buffers, even on a Unicode system.

Note:

Parameters

TRequestStatus &aStatus

The request status used to contain completion information for the function. On completion, contains System-wide error code

TTimeIntervalMicroSeconds32 aTimeOut

If present, the read will terminate afteraTimeoutmicroseconds if the data requested has not arrived. AKErrTimedOutstatus is returned.

TDes8 &aDes

A buffer to store the incoming data. The length of the descriptor is the default for the number of bytes to be read.

TInt aLength

An optional explicit length of data to be read. If present, this overrides the length of the TDes8 default


ReadCancel()

void ReadCancel();

Description

Cancels any pendingRead()orReadOneOrMore()operations.

The cancelled request will still terminate with its TRequestStatus set to any value other than KErrPending. While this is most likely to be KErrCancel, it is nevertheless possible for the cancellation to have been issued after the asynchronous request had already terminated for some other reason.


ReadOneOrMore()

void ReadOneOrMore(TRequestStatus &aStatus,TDes8 &aDes);

Description

Reads data from a serial port, but with slightly different behaviour toRead(). If there is data in the serial driver’s buffer whenReadOneOrMore() is called, it will read as much data as possible (up to the maximum length of the supplied buffer) and return immediately. If there is no data in the buffer, the request will complete as soon as the first character arrives at the serial hardware.

Parameters

TRequestStatus &aStatus

The request status used to contain completion information for the function. On completion, contains System-wide error code

TDes8 &aDes

A descriptor to a buffer. When the request completes this will hold data read from the input buffer.

[Top]


Writing to ports


Write()

void Write(TRequestStatus &aStatus,const TDesC8 &aDes);
void Write(TRequestStatus &aStatus,const TDesC8 &aDes, TInt aLength);
void Write(TRequestStatus &aStatus, TTimeIntervalMicroSeconds32 aTimeOut,const TDesC8 &aDes);
void Write(TRequestStatus &aStatus, TTimeIntervalMicroSeconds32 aTimeOut,const TDesC8 &aDes, TInt aLength);

Description

Writes data to a serial port. All writes to the serial device use 8-bit descriptors as data buffers, even on a Unicode system.

Note:

Parameters

TrequestStatus &aStatus

The request status used to contain completion information for the function. On completion, contains System-wide error code

TtimeIntervalMicroSeconds32 aTimeOut

If present, the read will terminate afteraTimeoutmicroseconds if the data requested has not been sent. AKErrTimedOut status is returned.

Const TDesC8 &aDes

A descriptor to a buffer containing the data to be written to the serial port

TInt aLength

An optional explicit length of data to be written. This can be used to override the length implicit in the buffer’s descriptor.


WriteCancel()

void WriteCancel();

Description

Cancels any pending Write() operations.

The cancelled request will still terminate with its TRequestStatus set, to any value other than KErrPending. While this is most likely to be KErrCancel, it is nevertheless possible for the cancellation to have been issued after the asynchronous request had already terminated for some other reason.

[Top]


Buffer management


Mode()

void Mode(TCommServerConfig &aConfig)const;

Description

Gets server buffering mode.

Parameters

TCommServerConfig &aConfig

A packaged TCommServerConfigV01 structure which will hold the required information on return.


QueryReceiveBuffer()

TInt QueryReceiveBuffer() const;

Description

Gets the number of bytes currently waiting in the driver’s input buffer. A return value of zero means the buffer is empty.

It is not possible to find out exactly how many bytes are currently in the driver’s output buffer waiting to be transmitted. However, this is not an issue since it is easy to ensure that the output buffer is empty. IfKConfigWriteBufferedComplete is clear then all write requests will delay completion until the data has completely cleared the driver’s output buffer. If KConfigWriteBufferedComplete is set, a write of zero bytes to a port which has data in the output buffer is guaranteed to delay completion until the buffer has been fully drained.

Return value

Tint

The number of bytes currently waiting to be read from the receive buffer.


ReceiveBufferLength()

TInt ReceiveBufferLength() const;

Description

Gets the size of the serial port buffers. Despite its name, this function returns the size of both the receive and transmit buffers, which are (obviously) always the same size.

Return value

TInt

The current size of both the receive and transmit buffers in bytes..


ResetBuffers()

void ResetBuffers();
void ResetBuffers(TUint aFlags);

Description

Resets the serial port buffers. By default, if no argument is passed, both the receive and transmit buffers are reset to zero length, and all data in the them is lost. Alternatively, either buffer can be reset independently.

Note:

Parameters

TUint aFlags

KCommResetRx to reset the receive bufferKCommResetTx to reset the transmit buffer


SetMode()

TInt SetMode(const TCommServerConfig &aConfig);

Description

Sets the server buffering mode. This function can be used to set either buffering mode, and if partial buffering is being used, it can also set the size of the buffer that the server will use. These items are packaged up into the TCommServerConfig descriptor.

The default of full buffering is nearly always going to be the quicker option, as only a single client-server data transfer is ever needed. The mode should not be changed by an application without a very good reason (such as memory constraints) otherwise performance is liable to suffer.

Parameters

const TCommServerConfig &aConfig

A packaged TCommServerConfigV01 structure to be set

Return value

TInt

System-wide error code


SetReceiveBufferLength()

void SetReceiveBufferLength(TInt aLength);

Description

Sets the size of the serial port receive and transmit buffers.

Note:

Parameters

TInt aLength

The required size of the receive and transmit buffers in bytes.

[Top]


Setting a break condition

Description

Note:

A break condition on a line is when a data line is held permanently high for an indeterminate period which must be greater than the time normally taken to transmit two characters. It is sometimes used as an error signal between computers and other devices attached to them over RS232 lines.


Break()

void Break(TRequestStatus &aStatus, TTimeIntervalMicroSeconds32 aTime);

Description

Sets a break condition for a specified time.

Parameters

TRequestStatus &aStatus

The request status used to contain completion information for the function. On completion, contains a System-wide error code.

TTimeIntervalMicroSeconds32 aTime

A timed break period in microseconds


BreakCancel()

void BreakCancel();

Description

Cancels any pending Break() operations.

[Top]


Notifications


NotifySignalChange()

void NotifySignalChange(TRequestStatus& aStatus, TUint& aSignals, TUint aSignalMask=0x3F);

Support

Supported from 6.0

Description

Notifies the client when one of the signals change.

Parameters

TRequestStatus& aStatus

Asynchronous completion status

TUint& aSignals

On return, the new set of signals. The bottom five bits contain a mask of the signals that are set (using the Signal line constants). The top four bits store which signal has changed (using the Signal line changed constants).

TUint aSignalMask=0x3F

Bitmaks of the signals to monitor. The default is all signals. See alsoKSignalDTEOutputs and KSignalDTEInputs.

See also:


NotifySignalChangeCancel()

void NotifySignalChangeCancel() const;

Support

Supported from 6.0

Description

Cancels a NotifySignalChange() request.


NotifyConfigChange()

void NotifyConfigChange(TRequestStatus& aStatus, TDes8& aNewConfig) const;

Support

Supported from 6.0

Description

Notifies the client when the port configuration (data rate, character width, stop bits, handshaking, or parity) of the remote end changes.

Parameters

TRequestStatus& aStatus

Asynchronous completion status

TDes8& aNewConfig

On completion, a packaged TCommNotificationV01


NotifyConfigChangeCancel()

void NotifyConfigChangeCancel() const;

Support

Supported from 6.0

Description

Cancels a NotifyConfigChangeCancel() request.


NotifyFlowControlChange()

void NotifyFlowControlChange(TRequestStatus& aStatus, TFlowControl& aFlowControl);

Support

Supported from 6.0

Description

Notifies the client when the flow control between the CSY and the external device changes.

Parameters

TRequestStatus& aStatus

Asynchronous completion status

TFlowControl& aFlowControl

On completion, new flow control status


NotifyFlowControlChangeCancel()

void NotifyFlowControlChangeCancel() const;

Support

Supported from 6.0

Description

Cancels a NotifyFlowControlChangeCancel() request.


NotifyBreak()

void NotifyBreak(TRequestStatus& aStatus) const;

Support

Supported from 6.0

Description

Notifies the client when a break occurs: the remote end has held the communication line high for a certain number of bits to indicate a break condition

Parameters

TRequestStatus& aStatus

Asynchronous completion status


NotifyBreakCancel()

void NotifyBreakCancel() const;

Support

Supported from 6.0

Description

Cancels a NotifyBreakCancel() request.


NotifyDataAvailable()

void NotifyDataAvailable(TRequestStatus& aStatus) const;

Support

Supported from 6.0

Description

Notifies the client when data is available to be read from the input buffer.

Parameters

TRequestStatus& aStatus

Asynchronous completion status


NotifyDataAvailableCancel()

void NotifyDataAvailableCancel() const;

Support

Supported from 6.0

Description

Cancels a NotifyDataAvailableCancel() request.


NotifyOutputEmpty()

void NotifyOutputEmpty(TRequestStatus& aStatus) const;

Support

Supported from 6.0

Description

Notifies the client when the transmit buffer is emptied.

Parameters

TRequestStatus& aStatus

Asynchronous completion status


NotifyOutputEmptyCancel()

void NotifyOutputEmptyCancel() const;

Support

Supported from 6.0

Description

Cancels a NotifyOutputEmptyCancel() request.

[Top]


Information


GetFlowControlStatus()

TInt GetFlowControlStatus(TFlowControl& aFlowControl) const;

Support

Supported from 6.0

Description

Gets the current status of flow control between the port and the third party (external PC or internal signalling stack).

Parameters

TFlowControl& aFlowControl

On return, flow control status

Return value

TInt

System-wide error code


GetRole()

TInt GetRole(TCommRole& aRole) const;

Support

Supported from 6.0

Description

Gets current DCE/DTE role.

Parameters

TCommRole& aRole

On return, current DCE/DTE role

Return value

TInt

System-wide error code