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:
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.
No related wiki articles found