BGXDevice

The BGXDevice class is used to represent the BGX device. More...

Classes

protocol <BGXSerialDelegate>
BGXSerialDelegate protocol. More...
protocol <BGXDeviceDelegate>
BGXDeviceDelegate protocol is used to be notified of state changes and device-level events. More...
class BGXDevice

Typedefs

typedef void(^ busmode_write_completion_handler_t ) ( BGXDevice *, NSError *err)

Enumerations

enum DeviceState : NSUInteger {
Interrogating , Disconnected , Connecting , Connected ,
Disconnecting
}
DeviceState values. More...
enum BusMode {
UNKNOWN_MODE , STREAM_MODE , LOCAL_COMMAND_MODE , REMOTE_COMMAND_MODE ,
UNSUPPORTED_MODE
}
Values of the bus mode. More...

Detailed Description

The BGXDevice class is used to represent the BGX device.

It contains a group of properties as well as methods used to perform appropriate actions on a BGXDevice .

Supports two delegates, deviceDelegate and serialDelegate, as well as KVO.


Class Documentation

BGXSerialDelegate-p

protocol BGXSerialDelegate-p

BGXSerialDelegate protocol.

The BGXSerialDelegate is used to perform serial read/write operations with the BGX.

Instance Methods

(void) - busModeChanged:forDevice:
Detect bus mode changes. More...
(void) - dataRead:forDevice:
Delegate method is called when data is received. More...
(void) - dataWrittenForDevice:
Delegate method used to advise that the data has been written. More...

Method Documentation

busModeChanged:forDevice:()

- (void) busModeChanged: ( BusMode ) newBusMode
forDevice: ( BGXDevice *) device
required

Detect bus mode changes.

Delegate method called when the bus mode changes or is read. If you call the BGXpressManager method -(BOOL)readBusMode, this delegate will be called with the bus mode that was read whether or not it was different than the previous bus mode.

Parameters
newBusMode the new bus mode for the connection

dataRead:forDevice:()

- (void) dataRead: (NSData *) newData
forDevice: ( BGXDevice *) device
required

Delegate method is called when data is received.

Parameters
newData updated values

dataWrittenForDevice:()

- (void) dataWrittenForDevice: ( BGXDevice *) device
required

Delegate method used to advise that the data has been written.

BGXDeviceDelegate-p

protocol BGXDeviceDelegate-p

BGXDeviceDelegate protocol is used to be notified of state changes and device-level events.

Instance Methods

(void) - connectionTimeoutForDevice:
The device was connecting but the connection operation failed to finish within the timeout period. More...
(void) - stateChangedForDevice:
The value of the deviceState variable changed. More...
(void) - rssiChangedForDevice:
The RSSI value changed for the device. More...

Method Documentation

connectionTimeoutForDevice:()

- (void) connectionTimeoutForDevice: ( BGXDevice *) device
optional

The device was connecting but the connection operation failed to finish within the timeout period.

The device is probably disconnected as a result.

Parameters
device The device whose connection timed out.

stateChangedForDevice:()

- (void) stateChangedForDevice: ( BGXDevice *) device
optional

The value of the deviceState variable changed.

This could mean that the device connected, disconnected, and so on. The typical flow is: Connect operation: Disconnected -> Connecting -> Interrogating -> Connected.

Disconnect operation: Connected -> Disconnecting -> Disconnected

Parameters
device The device whose state changed.

rssiChangedForDevice:()

- (void) rssiChangedForDevice: ( BGXDevice *) device
optional

The RSSI value changed for the device.

Parameters
device The device for which the RSSI changed.

BGXDevice

class BGXDevice

Inherits NSObject, and <CBPeripheralDelegate>.

Instance Methods

(BOOL) - connect
Method to connect to the device. More...
(BOOL) - disconnect
Method to disconnect to the device. More...
(BOOL) - readBusMode
Method used to read the BusMode for a device e.g., Stream, Local or Remote commands. More...
(BOOL) - writeBusMode:
Deprecated Use writeBusMode: password: completionHandler: instead. More...
(BOOL) - writeBusMode:password:completionHandler:
Method used to write new bus mode for device. More...
(BOOL) - canWrite
Method to see if you can write to the device. More...
(BOOL) - writeData:
Method used to write data to a device. More...
(BOOL) - writeString:
Method used to write a string to device. More...
(BOOL) - sendCommand:args:
Method used to send commands to the device. More...
(nullable NSString *) - device_unique_id
Returns the device unique id. More...
(CBPeripheral *) - peripheral
Access to the CBPeripheral. More...

Class Methods

(NSString *) + nameForDeviceState:
Printable name for a device state value. More...

Protected Attributes

DeviceState _deviceState
BusMode _busMode
BOOL _writeWithResponse

Properties

NSObject< BGXDeviceDelegate > * deviceDelegate
NSObject< BGXSerialDelegate > * serialDelegate
NSString * name
NSNumber * rssi
NSUUID * identifier
DeviceState deviceState
BusMode busMode
NSString * modelNumber
NSString * firmwareRevision
NSString * bootloaderVersion
BOOL fastAck
YES = The device supports fastAck and will operate in fastAck mode. More...
BOOL writeWithResponse
YES = Writes occur using CBCharacteristicWriteWithResponse NO = Writes occur using CBCharacteristicWriteWithoutResponse = YES. More...

Method Documentation

connect()

- (BOOL) connect

Method to connect to the device.

Operation happens asynchronously. Observe the deviceState property to determine the outcome of the operation.

Returns
BOOL value to indicate if the connection operation started successfully.

disconnect()

- (BOOL) disconnect

Method to disconnect to the device.

Operation happens asynchronously. Observe the deviceState property to determine the outcome of the operation.

Returns
BOOL value to indicate if the disconnection operation started successfully.

readBusMode()

- (BOOL) readBusMode

Method used to read the BusMode for a device e.g., Stream, Local or Remote commands.

This operation occurs asynchronously. Observe the changes to the busMode property.

Returns
BOOL value, YES to indicate that the read operation could be initiated. NO if the read operation could not be started.

writeBusMode:()

- (BOOL) writeBusMode: ( BusMode ) newBusMode

Deprecated Use writeBusMode: password: completionHandler: instead.

Method used to write new bus mode for device. Operation occurs asynchronously.

Parameters
newBusMode The new BusMode for the device
Returns
BOOL value, YES if BusMode write operation could be started.

writeBusMode:password:completionHandler:()

- (BOOL) writeBusMode: ( BusMode ) newBusMode
password: (NSString *_Nullable) password
completionHandler: ( busmode_write_completion_handler_t ) completionHandler

Method used to write new bus mode for device.

Operation occurs asynchronously. You may get an error if the password you pass is wrong.

Parameters
newBusMode The new BusMode for the device
password The password for the bus mode characteristic. Pass nil for no password.
completionHandler This will be called when the operation completes. You will get an error as a parameter to the completionHandler if the password is wrong or if you pass nil when a password is required.

canWrite()

- (BOOL) canWrite

Method to see if you can write to the device.

Returns
BOOL value, YES if device is connected and no data waiting to be written to the device, else NO.

writeData:()

- (BOOL) writeData: (NSData *) data

Method used to write data to a device.

Parameters
data Data to be written to device.
Returns
BOOL value advising if the data has been written to the device or not.

writeString:()

- (BOOL) writeString: (NSString *) string

Method used to write a string to device.

Parameters
string String value to be written to device.
Returns
BOOL value advising if the string has been written to the device or not.

sendCommand:args:()

- (BOOL) sendCommand: (NSString *) command
args: (NSString *) args

Method used to send commands to the device.

Parameters
command Command
args Arguments
Returns
BOOL value advising if the command has been written to the device or not.

device_unique_id()

- (nullable NSString *) device_unique_id

Returns the device unique id.

Returns
NSString with the unique id of the device. Nil on error.

nameForDeviceState:()

+ (NSString *) nameForDeviceState: ( DeviceState ) ds

Printable name for a device state value.

peripheral()

- (CBPeripheral *) peripheral

Access to the CBPeripheral.

Member Data Documentation

_deviceState

- ( DeviceState ) _deviceState
protected

_busMode

- ( BusMode ) _busMode
protected

_writeWithResponse

- (BOOL) _writeWithResponse
protected

Property Documentation

deviceDelegate

- (NSObject< BGXDeviceDelegate >*) deviceDelegate
read write nonatomic weak

serialDelegate

- (NSObject< BGXSerialDelegate >*) serialDelegate
read write nonatomic weak

name

- (NSString*) name
read nonatomic assign

rssi

- (NSNumber*) rssi
read nonatomic assign

identifier

- (NSUUID*) identifier
read nonatomic assign

deviceState

- ( DeviceState ) deviceState
read nonatomic assign

busMode

- ( BusMode ) busMode
read nonatomic assign

modelNumber

- (NSString*) modelNumber
read write nonatomic strong

firmwareRevision

- (NSString*) firmwareRevision
read write nonatomic strong

bootloaderVersion

- (NSString*) bootloaderVersion
read write nonatomic strong

fastAck

- (BOOL) fastAck
read nonatomic assign

YES = The device supports fastAck and will operate in fastAck mode.

NO = The device does not support fastAck and will operate in legacy mode.

writeWithResponse

- (BOOL) writeWithResponse
read write nonatomic assign

YES = Writes occur using CBCharacteristicWriteWithResponse NO = Writes occur using CBCharacteristicWriteWithoutResponse = YES.

Note: If the device supports fastAck, writeWithoutResponse will always be used.

Typedef Documentation

busmode_write_completion_handler_t

typedef void(^ busmode_write_completion_handler_t) ( BGXDevice *, NSError *err)

Enumeration Type Documentation

DeviceState

enum DeviceState : NSUInteger

DeviceState values.

Enumerator
Interrogating

The BGXDevice has connected and Bluetooth services and characteristics are being discovered.

Disconnected

The BGXDevice is not connected (to this iOS device).

Connecting

The BGXDevice is in the process of connecting.

Connected

The BGXDevice is connected.

Disconnecting

The BGXDevice is in the process of disconnecting.

BusMode

Values of the bus mode.

Enumerator
UNKNOWN_MODE

an invalid mode used to indicate that the

mode has not been determined

STREAM_MODE

send and receive serial data to the device to

which the BGX is connected

LOCAL_COMMAND_MODE

data received over the serial lines is

processed as a command by the BGX and results returned over the serial lines

REMOTE_COMMAND_MODE

data received over Bluetooth is processed as

a command by the BGX and results returned over Bluetooth

UNSUPPORTED_MODE

an invalid mode state