×
Namespaces

Variants
Actions
Revision as of 05:05, 20 July 2012 by hamishwillee (Talk | contribs)

BTCOMM serial communication.

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: judith14 (27 Jul 2007)
Last edited: hamishwillee (20 Jul 2012)

Bluetooth CSY is provided primarily to support serial communication (RS232) over Bluetooth. BTComm is itself provided by a serial communications module in the form of a CSY file.

BTComm provides the framework to produce an RS232 emulation plug-in communicating over a Bluetooth RFComm connection.

The following Serial Communication C32 classes are used in making an RS232 BTComm connection:

  • RCommServ - A session on the Serial Comms server.
  • RComm - A subsession on the Serial Comms server.
  • RCommServ::Connect() - Creates a session on the comms server.
  • RCommServ::LoadCommModule() - The desired serial communication protocol Module(CSY Module) is loaded using this function.
  • RComm::Open() - Open a port on the serial server.
  • RComm::Close() - Closes the port.
  • RComm::Read(), RComm::ReadOneOrMore() - Reading data over the port.
  • RComm::Write() - Writing data over the port.

How to use the above APIs for BTCOMM

First you need to create some objects.

// Opening a simple BTCOMM connection.
// Create an RCommServ object.
RCommServ server;
// Create an RComm object.
RComm commport;
// Required LITs
_LIT(KTxtBTCOMM,"BTCOMM");
_LIT(KTxtBTCommName,"BTCOMM::");

Connect to the serial comms server:

server.Connect();

Load the Bluetooth BTComm CSY module using RCommServ::LoadCommModule().

server.LoadCommModule(KTxtBTCOMM);

Prepare the port name for the connection.

TBuf8<15> commname(KTxtBTCommName); commname.AppendNum(0); The TDes8::AppendNum() function above appends the decimal character '0', representing the port for this example, onto the end of the 'commname' descriptor. The RCommServ::GetPortInfo() function is used to discover the port number if it is not known.

Open and configure the BTComm serial port.

User::LeaveIfError(commport.Open(server,commname,ECommExclusive));
 
 
//Configuring Port is done by using the code
 
TCommConfig cBuf;
TCommConfigV01 &c=cBuf();
 
// Get the current configuration
commPort.Config(cBuf);
 
// Set new settings
c.iFifo = EFifoEnable;
c.iRate = EBps19200;
c.iHandshake = KConfigObeyCTS;
c.iTerminatorCount = 0;
c.iDataBits = EData8;
c.iParity = EParityNone;
c.iStopBits = EStop1;
 
// Write the settings out
commPort.SetConfig(cBuf);

After Succesfull opening of a port can allow to do data transfer. RComm allows you to read and write data over the port. There are several kinds of read and write methods available.

Reading

RComm::Read() reads data from the serial port.

Writing RComm::Write() writes data to the serial port.

iComm.Read(iStatus, iBuffer);
//iComm is the instance of RComm opened earlier.
iComm.Write(iStatus,iBuffer);

Cancelling

You can cancel a pending Read() or Write() using ReadCancel() or WriteCancel().

iComm.ReadCancel(); The TRequestStatus of the pending Read(), or Write() will be set to KErrCancel.

Close the serial port is done using RComm::Close():

iComm.Close();
 
//Closes the serial port.
35 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.

×