SDK Home Glossary Index Left Right Up

Comm Class


Section contents


Overview

Defined in

ccomms.oxh

Description

Comm represents 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.


Construction / destruction


NewComm - Constructor

Usage

this& = NewComm&:

Description

Creates a comm object and returns a handle which allows the object to be manipulated.

Return Value
this& An value which represents the created comm object
Error Handling

If the object could not be created then an error is generated which should be trapped by an ONERR handler.

Example
  LOCAL this&

  this& = NewComm&:
  DeleteComm:(this&) 

DeleteComm - Destructor

Usage

DeleteComm:(BYREF this&)

Description

Destroys the comm object.

Arguments
BYREF this& A handle to a comm object
Example
  LOCAL this&

  this& = NewComm&:()
  DeleteComm:(this&) 

Methods provided


CommBreakA - set a break condition at a serial port

Usage

CommBreakA:(this&,time&,BYREF status&)

Description

 

Arguments
this& A handle to a comm object
time& A timed break period in microseconds
BYREF status&  
See Also

CommBreakCancel


CommBreakCancel - cancel a break condition at a serial port

Usage

CommBreakCancel:(this&)

Description

 

Arguments
this& A handle to a comm object
See Also

CommBreakA


CommCancel - cancel any pending reads and writes

Usage

CommCancel:(this&)

Description

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 CommCancel before closing a port as this is done automatically

Arguments
this& A handle to a comm object
See Also

CommReadA, CommWriteA, CommWriteCancel


CommCaps - read serial port capabilities

Usage

CommCaps:(this&,caps&)

Description

Use this function to retrieve the capabilities of the serial port.

Arguments
this& A handle to a comm object
caps& A handle to a Serial Capabilities object

CommClose - close a serial port

Usage

CommClose:(this&)

Description

Use this function to close a serial port.

Arguments
this& A handle to a comm object
See Also

CommOpen


CommConfig - read serial port configuration

Usage

CommConfig:(this&,config&)

Description

Use this function to read the current configuration of the serial port..

Arguments
this& A handle to a comm object
config& A handle to a Comm Configuration object
See Also

CommSetConfig


CommMode - retrieve server buffering mode

Usage

CommMode:(this&,config&)

Description

This function enables the comms server buffering mode to be retrieved. If partial buffering is being used, then iBufSize will hold the size of the buffer used by the server.

Arguments
this& A handle to a comm object
config& A handle to a CommServerConfig object
See Also

CommSetMode


CommOpen - open a serial port

Usage

result% = CommOpen%:(this&,server&,name$,mode%)

Description

Use this function to open a serial port, either for exclusive use of this Comm or giving permission for the port to be shared by other Comms. 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 exclusive mode.

Arguments
this& A handle to a comm object
server& The comms server session
name$ The name of the port
mode% The mode in which the port is opened. There is no default.
Return value
result% An error code
See Also

CommClose, SerialInfoName


CommQueryReceiveBuffer - number of bytes waiting in receive buffer

Usage

count& = CommQueryReceiveBuffer&:(this&)

Description

Use this function to find out how many bytes are currently waiting in the driver’s input buffer. A return value of zero means the buffer is empty.

Arguments
this& A handle to a comm object
Return value
count& The number of bytes currently waiting to be read from the receive buffer.
Notes

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. If KConfigWriteBufferedComplete& 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.

See Also

CommReceiveBufferLength


CommReadA - read data from a serial port

Usage

CommReadA:(this&,des&,length&,timeout&,BYREF status&)

Description

Use this function to request data from a serial port. All reads from the serial device use 8-bit descriptors as data buffers, even on a Unicode system.

Arguments
this& A handle to a comm object
des& A descriptor to store the incoming data. The length of the descriptor is the default for the number of bytes to be read.
length& If not -1 an optional explicit length of data to be read. If present, this overrides the length of the descriptor default
timeout& If not 0, the read will terminate after timeout& microseconds if the data requested has not arrived
BYREF status& The request status used to contain completion information for the function.
Notes
  1. The length of the descriptor is set to zero on entry, which means that buffers can be reused without having to be zeroed first.
  2. The amount of data to be read from the serial driver depends upon which overload of Read() is used. Normally the length used is the maximum length of the descriptor. In the version which takes an explicit length this value is used in preference to the descriptor’s maximum length.
  3. If a read is issued with a data length of zero (either explicitly or implicit in the descriptor) the Read() will complete immediately with the side effect that the serial hardware will have been powered up.
  4. If a read terminates with K32ErrTimedOut& and the descriptor is not empty, it will contain valid data. Its length should therefore be tested.
See Also

CommCancel, CommReadCancel, CommReadOneOrMoreA


CommReadCancel - cancel pending read

Usage

CommReadCancel:(this&)

Description

Causes any pending CommReadA or CommReadOneOrMoreA operation to complete immediately.

Arguments
this& A handle to a comm object
Note

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

See Also

CommCancel, CommReadA, CommReadOneOrMoreA


CommReadOneOrMoreA - read data from a serial port

Usage

CommReadOneOrMoreA:(this&,des&,BYREF status&)

Description

Use this function to request data from a serial port. All reads from the serial device use 8-bit descriptors as data buffers, even on a Unicode system.

If there is data in the serial driver’s buffer when CommReadOneOrMoreA 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.

Arguments
this& A handle to a comm object
des& A descriptor to store the incoming data. The length of the descriptor is the default for the number of bytes to be read.
BYREF status& The request status used to contain completion information for the function.
See Also

CommCancel, CommReadA, CommReadCancel


CommReceiveBufferLength - get size of serial port buffers

Usage

length& = CommReceiveBufferLength&:(this&)

Description

Use this function to find out 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.

Arguments
this& A handle to a comm object
Return value
length& The current size of both the receive and transmit buffers in bytes
See Also

CommQueryReceiveBuffer, CommSetReceiveBufferLength


CommResetBuffers - reset serial port buffers

Usage

CommResetBuffers:(this&,flags&)

Description

Either buffer can be reset independently and all data in the them is lost. This function should not be called when there are pending reads or writes.

Arguments
this& A handle to a comm object
flags& KCommResetRx& to reset the receive buffer

KCommResetTx& to reset the transmit buffer

See Also

CommMode, CommQueryReceiveBuffer, CommReceiveBufferLength, CommSetMode


CommSetConfig - set serial port configuration

Usage

result% = CommSetConfig%:(this&,config&)

Description

Use this function to open a serial port, either for exclusive use of this Comm or giving permission for the port to be shared by other Comms. 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 exclusive mode.

Arguments
this& A handle to a comm object
config& A handle to a CommConfig object
Return value
result% An error code
Notes

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.

See Also

CommConfig


CommSetMode - set server buffering mode

Usage

result% = CommSetMode%:(this&,config&)

Description

The comms server copies data, between the descriptors provided by the client and the buffers used by the serial port drivers, for each read and write request. There are two methods by which this can be accomplished. Full buffering means that the comms server will always attempt to allocate enough memory to satisfy any reads or writes in a single copy, while partial buffering means that the comms server will allocate a static buffer and use partial copies to transfer data to the serial driver.

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 CommServerConfigV01 descriptor.

When a port is opened, the default is full buffering

Arguments
this& A handle to a comm object
config& A handle to a CommServerConfig object
Return value
result% An error code
Notes

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.

See Also

CommMode, CommQueryReceiveBuffer, CommReceiveBufferLength, CommResetBuffers


CommSetReceiveBufferLength - set size of serial port buffers

Usage

CommSetReceiveBufferLength:(this&,length&)

Description

Use this function to change the size of the serial port receive and transmit buffers.

Arguments
this& A handle to a comm object
length& The required size of the receive and transmit buffers in bytes.
Notes
  1. There is no error code returned by this function. If the buffer is set to too large a figure, the request is simply ignored. If you are in any doubt about the success of a CommSetReceiveBufferLength request, you should examine the returned value from CommReceiveBufferLength.
  2. It isn’t always essential to set a buffer size as there is a generous default of 1024.
  3. Changing the size of the receive buffer is the only way to tailor the operation of flow control in EPOC32 as the exact position of the high water mark is not configurable.
See Also

CommReceiveBufferLength


CommSetSignals - set serial port control line

Usage

CommSetSignals:(this&,setmask&,clearmask&)

Description

Using this inline function, either of the RS232 output lines (DTR and RTS) can be set or cleared manually as needed.

Arguments
this& A handle to a comm object
setmask& Set the handshaking lines in the mask as specified in Signal line constants
clearmask& Set the handshaking lines in the mask as specified in Signal line constants
Notes

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

See Also

CommSignals


CommSignals - read serial port control lines

Usage

signals& = CommSignals&:(this&,mask&)

Description

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

Arguments
this& A handle to a comm object
mask& This defaults to 0x3f as only the top six bits of this integer are valid.
Return value
signals& An integer with the bits set to reflect the status of the handshaking lines according to the values defined in Signal line constants
Notes
  1. Not all of the input lines are guaranteed to be available on all serial devices. In particular, the integral UART built in the ARM does not support the Ring Indicate (RI) input line.
  2. A different value to 0x3f can be specified as aSignalMask if specific information is required - for instance, CommSignals(KSignalDSR&) could be used to find out if a modem were connected to the serial port.
See Also

CommSetSignals


CommWriteA - write data to a serial port

Usage

CommWriteA:(this&,des&,length&,timeout&,BYREF status&)

Description

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

Arguments
this& A handle to a comm object
des& A descriptor to a buffer containing the data to be written to the serial port
length& An optional explicit length of data to be written. If not -1, this overrides the length of the descriptor default
timeout& If not 0, the read will terminate after timeout& microseconds if the data requested has not been sent.
BYREF status& The request status used to contain completion information for the function.
Notes
  1. If a write is issued with a data length of zero (either explicitly or implicit in the descriptor) the CommWrite will complete when the current handshaking configuration and the state of input control lines would allow any data to be immediately written to the serial line. This functionality is useful to determine when serial devices come on line, and to check that the output buffer is empty if KConfigWriteBufferedComplete& is set.
See Also

CommCancel, CommWriteCancel


CommWriteCancel - cancel a pending write

Usage

CommWriteCancel:(this&)

Description

Causes any pending CommWrite operation to complete immediately.

Arguments
this& A handle to a comm object
Note

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

See Also

CommCancel, CommWriteA


  SDK Home Glossary Index Left Right Up