Connect Method

Connect to a BLE GATT server based on its identifier.

Syntax

ANSI (Cross Platform)
int Connect(const char* lpszServerId);

Unicode (Windows)
INT Connect(LPCWSTR lpszServerId);
#define MID_BLECLIENT_CONNECT 3

IPWORKSBLE_EXTERNAL int IPWORKSBLE_CALL IPWorksBLE_BLEClient_Do(void *lpObj, int methid, int cparam, void *param[], int cbparam[], int64 *lpllVal);

Remarks

This method will attempt to connect to the BLE GATT server represented by the platform-specific identifier supplied in the ServerId parameter. The Connected event will be fired when the connection attempt finishes, and will contain additional information if the attempt failed.

If the class is connected to a server already when Connect is called, and the given ServerId is different than the currently connected server's ServerId, it will attempt to gracefully disconnect prior to initiating a new connection.

Calling Connect does nothing if ServerId is empty or matches the currently connected server's ServerId.

If Connect is called while the class is Scanning, the class will stop scanning prior to attempting to initiate a connection.

Note that there are a variety of reasons that a connection to a server may fail, not the least of which includes the server device being out of range of the client device. For the best results, it is recommended that you scan for devices before attempting a connection. Also note that the device identifier is a platform-specific value which is not guaranteed to be the same at any given point in time for any specific server device.

Connecting and Disconnecting

// Connect to our TI SensorTag device.
bleclient1.Connect("546C0E795800");
// Use BLEClient...
// Disconnect from the device.
bleclient1.Disconnect();

Error Handling (C++)

This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks BLE 2020 C++ Edition - Version 20.0 [Build 8158]