Skip to content

Modules.BLE.L2CAPChannel

L2Cap allow us to open a side channel, with it we can directly read and write without any framing limitation, packet size limitations. It’s a direct way to talk between our devices and accessories.

L2Cap Channel on the lowest level is the stream of data between two devices. It’s actually the protocol that has been used underneath for all types of communication between two devices. So L2Cap has been used from the first day of Bluetooth communications. but now with the L2CAP class, we use is directly talk over these channels.

Extends: Titanium.Proxy · Since: 1.1.0, 1.0.0, 1.0.0 · Platforms: android, iphone, ipad

Properties #

peer#

Type: Modules.BLE.Peer

The peer connected to the channel

psm#

Type: Number

The PSM of the channel.

Methods #

close #

closes the l2cap channel

Returns: void

getReadBufferSize #

Get the size of the read buffer in bytes.

Returns: Number — Size of the read buffer in bytes.

setReadBufferSize #

Sets the size of the read buffer in bytes.

You can set the read buffer size at any time, but it will only take effect during the next read.
By default, the buffer size is 1024 bytes.

Parameters:
NameTypeSummaryOptional
sizeNumberThe desired size of the read buffer in bytes.No

write #

write data to channel

Parameters:
NameTypeSummaryOptional
dataTitanium.BufferTitanium.Buffer object to write data on channelNo

Returns: void

Events #

onDataReceived #

Fired whenever new data recived on channel.

Event Properties:
NameTypeSummary
dataTitanium.BufferTitanium.Buffer object which represent the read data

onStreamEndEncountered #

Fired whenever the end of the stream has been reached.

onStreamError #

Fired whenever there is some error in reading or writing.

Event Properties:
NameTypeSummary
errorCodeStringThe error code
errorDomainStringThe error domain
errorDescriptionStringThe error description

Titanium SDK Documentation