Serial communication using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Keywords: RCommServ, RComm,
Created: vasant21 (25 Apr 2007)
Last edited: hamishwillee (24 Jan 2012)

Serial communication is a low-level, point-to-point technology used to transfer data between two devices, typically at close range — S60 supports serial communication over infrared and Bluetooth. Central to the S60 implementation is the Serial Communications Server (also referred to as the Comms Server or C32). This uses the familiar Symbian OS Client/Server framework to provide access to serial hardware, and it is generic (in other words, the same API is used for both infrared and Bluetooth serial communication — note that other hardware can be supported by the addition of plug-ins) and shared (in other words, several client threads can safely use the same serial port concurrently).


All serial communication on Symbian is implemented using the following basic steps

  • Load the serial device drivers.
  • Start the Comms Server.
  • Connect to the Comms Server.
  • Load a comms module (otherwise known as a CSY) — this is the Comms Server plug-in that determines which type of serial port you wish to use (for example, infrared or Bluetooth).
  • Open a serial port.
  • Configure the serial port.
  • Write data to (and/or read data from) the port.
  • Finally, close the port.

An Example IR Serial Communication

Important Classes involved:

  • RCommServ // serial comms
  • RComm // comm port
  • TBuf8<64> Data // data to transmit

Part 1

  • Load the physical and logical device drivers.
  • Connect to the Serial comms server.
  • Load the CSY module.
 err = User::LoadPhysicalDevice(KPddName);
if (err&nbsp;!= KErrNone && err != KErrAlreadyExists)
// Load the logical device driver.
err = User::LoadLogicalDevice(KLddName);
if (err != KErrNone && err != KErrAlreadyExists)
// Start the comms server process
err = StartC32();
if (err != KErrNone && err != KErrAlreadyExists)
// Connect to the Serial comms server.
// Load the CSY module.

Part 2

  • Open the serial port
  • Check port capabilities
  • Configure port
  • Set buffer size
//Open the serial port
User::LeaveIfError(iCommPort.Open(iCommServer, KPortName, ECommShared));
// Check port capabilities
TCommCaps portCapabilities;
if (((portCapabilities().iRate & KCapsBps19200) == 0) ||
((portCapabilities().iDataBits& KCapsData8) == 0) ||
((portCapabilities().iStopBits & KCapsStop1) == 0) ||
((portCapabilities().iParity& KCapsParityNone) == 0))
User::Leave (KErrNotSupported);
// Configure port
TCommConfig portSettings;
iCommPort.Config(portSettings); // Get current configuration
// Set port characteristics
portSettings().iRate = EBps19200;
portSettings().iParity = EParityNone;
portSettings().iDataBits = EData8;
portSettings().iStopBits = EStop1;
portSettings().iFifo = EFifoEnable;
portSettings().iHandshake = KConfigObeyXoff|KConfigSendXoff;
portSettings().iTerminator[0] = 10; // line feed character
portSettings().iTerminatorCount = 1;
// Turn on DTR and RTS
iCommPort.SetSignals(KSignalDTR, 0);
iCommPort.SetSignals(KSignalRTS, 0);
// Set buffer size
const TInt KBufferLength = 4096;

Part 3

  • write to the serial port.
 const TTimeIntervalMicroSeconds32 KTimeOut(4000000);
iCommPort.Write(iStatus, KTimeOut, Data);
This page was last modified on 24 January 2012, at 06:25.
77 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.