UniPRT SDK v2.0.0.0
 
Loading...
Searching...
No Matches
BleComm Class Reference

A communication class for handling Bluetooth Low Energy (BLE) connections. More...

#include <BleComm.h>

Inheritance diagram for BleComm:
AComm <IComm>

Instance Methods

(NSArray< NSString * > *) - availableDevices
 Retrieves a list of available BLE devices.
 
(void) - open:
 Connects to the specified BLE device by name.
 
(bool) - isConnected
 Checks if the BLE connection is currently active.
 
(void) - close
 Disconnects the current BLE connection.
 
(void) - write:
 Writes data to the connected BLE device.
 
(NSData *) - read
 Reads the data received from the BLE device.
 
(void) - waitForDataWithTimeout:
 Waits for data from the BLE device within a timeout period.
 
(NSData *) - writeAndWaitForResponse:responseStartTimeOut:responseEndTimeOut:completionToken:
 Sends data to the BLE device and waits for a response.
 
(NSData *) - writeAndWaitForResponseJson:responseStartTimeOut:responseEndTimeOut:completionToken:
 Sends JSON data to the BLE device and waits for a response.
 
- Instance Methods inherited from AComm
(void) - open
 Opens the communication interface.
 
(void) - readToBinaryWriter:
 Reads data into a binary writer (output stream).
 
(void) - writeFromBinaryReader:
 Writes data from a binary reader (input stream) to the communication interface.
 
(void) - writeAndWaitForResponseToBinaryWriter:fromBinaryReader:responseStartTimeout:responseEndTimeout:completionToken:
 Writes data to the communication interface and waits for a response, using binary streams.
 

Properties

CBCentralManager * centralManager
 
NSMutableArray< NSString * > * discoveredDevices
 
NSMutableArray< CBPeripheral * > * foundPeripherals
 
CBPeripheral * connectedPeripheral
 
NSMutableArray< CBCharacteristic * > * writeCharacteristics
 
NSMutableArray< CBCharacteristic * > * readCharacteristics
 
NSMutableData * receivedData
 
void(^ _Nullable )(void)
 Callback triggered after all required BLE characteristics are discovered and ready to use. Set this before calling open: to know when it's safe to proceed with data operations.
 
- Properties inherited from AComm
int maxPacketSize
 The maximum packet size for communication.
 
NSString * descriptor
 The descriptor for the communication interface.
 
int bytesAvailable
 The number of bytes available to read.
 
BOOL isConnected
 A flag indicating whether the connection is established.
 
- Properties inherited from <IComm>
NSString * descriptor
 The descriptor for the communication interface.
 
int bytesAvailable
 The number of bytes available to read.
 

Detailed Description

A communication class for handling Bluetooth Low Energy (BLE) connections.

This class extends AComm and implements the CBCentralManagerDelegate and CBPeripheralDelegate protocols. It provides methods to discover, connect, send, and receive data from BLE peripherals.

Method Documentation

◆ availableDevices

- (NSArray< NSString * > *) availableDevices

Retrieves a list of available BLE devices.

Returns
An array of NSString objects representing device names.

◆ close

- (void) close

Disconnects the current BLE connection.

Reimplemented from AComm.

◆ isConnected

- (bool) isConnected

Checks if the BLE connection is currently active.

Returns
true if connected, false otherwise.

Reimplemented from <IComm>.

◆ open:

- (void) open: (NSString *) deviceName

Connects to the specified BLE device by name.

Parameters
deviceNameThe name of the device to connect to.

◆ read

- (NSData *) read

Reads the data received from the BLE device.

Returns
An NSData object containing the received data.

Reimplemented from AComm.

◆ waitForDataWithTimeout:

- (void) waitForDataWithTimeout: (NSTimeInterval) msTimeOut

Waits for data from the BLE device within a timeout period.

Parameters
msTimeOutThe maximum time to wait in milliseconds.

Reimplemented from AComm.

◆ write:

- (void) write: (NSData *) text

Writes data to the connected BLE device.

Parameters
textThe data to be written.

Reimplemented from AComm.

◆ writeAndWaitForResponse:responseStartTimeOut:responseEndTimeOut:completionToken:

- (NSData *) writeAndWaitForResponse: (NSData *) text
responseStartTimeOut: (NSTimeInterval) responseStartTimeOut
responseEndTimeOut: (NSTimeInterval) responseEndTimeOut
completionToken: (NSString *) completionToken 

Sends data to the BLE device and waits for a response.

Parameters
textThe data to send.
responseStartTimeOutThe maximum time to wait for the response to start.
responseEndTimeOutThe maximum time to wait for the response to finish.
completionTokenA string token indicating response completion.
Returns
An NSData object containing the response.

Reimplemented from AComm.

◆ writeAndWaitForResponseJson:responseStartTimeOut:responseEndTimeOut:completionToken:

- (NSData *) writeAndWaitForResponseJson: (NSData *) text
responseStartTimeOut: (NSTimeInterval) responseStartTimeOut
responseEndTimeOut: (NSTimeInterval) responseEndTimeOut
completionToken: (NSString *) completionToken 

Sends JSON data to the BLE device and waits for a response.

Parameters
textThe JSON data to send.
responseStartTimeOutThe maximum time to wait for the response to start.
responseEndTimeOutThe maximum time to wait for the response to finish.
completionTokenA string token indicating response completion.
Returns
An NSData object containing the response.

Property Documentation

◆ _Nullable

- (void(^ _Nullable) (void))
readwritenonatomiccopy

Callback triggered after all required BLE characteristics are discovered and ready to use. Set this before calling open: to know when it's safe to proceed with data operations.

◆ centralManager

- (CBCentralManager*) centralManager
readwritenonatomicstrong

Central manager for BLE operations.

◆ connectedPeripheral

- (CBPeripheral*) connectedPeripheral
readwritenonatomicstrong

Currently connected peripheral.

◆ discoveredDevices

- (NSMutableArray<NSString *>*) discoveredDevices
readwritenonatomicstrong

List of discovered device names.

◆ foundPeripherals

- (NSMutableArray<CBPeripheral *>*) foundPeripherals
readwritenonatomicstrong

List of found peripherals.

◆ readCharacteristics

- (NSMutableArray<CBCharacteristic *>*) readCharacteristics
readwritenonatomicstrong

BLE characteristics available for reading.

◆ receivedData

- (NSMutableData*) receivedData
readwritenonatomicstrong

Accumulated received data from the BLE device.

◆ writeCharacteristics

- (NSMutableArray<CBCharacteristic *>*) writeCharacteristics
readwritenonatomicstrong

BLE characteristics available for writing.


The documentation for this class was generated from the following file: