This function will read data from a characteristic on a device.
Input:
dev: SYSHANDLE
Handle to the device.
char : UINT
The ID of the characteristic to read from.
size : INT
The size of the buffer to read the data into.
data : PTR
A pointer to a buffer to store the data in.
Output:
size : INT
The size of the read data.
Returns: INT
1
|
-
|
_BLE_OK
|
|
Success
|
0
|
-
|
_BLE_ERR_NOT_SUPPORTED
|
|
The API is not supported.
|
-1
|
-
|
_BLE_ERR_NOT_OPEN
|
|
The interface is not powered(see blePower).
|
-4
|
-
|
_BLE_ERR_NOT_FOUND
|
|
Failed to find device.
|
-7
|
-
|
_BLE_ERR_NO_RES
|
|
Data length is not supported by device.
|
-8
|
-
|
_BLE_ERR_INVAL
|
|
Read is not supported.
|
-9
|
-
|
_BLE_ERR_NODATA
|
|
Characteristic not found
|
-13
|
|
_BLE_ERR_STATE
|
|
Not allowed to read at this time.
|
-19
|
-
|
_BLE_ERR_NOT_CONNECTED
|
|
Device is not connected.
|
-20
|
-
|
_BLE_ERR_INVAL_HANDLE
|
|
Invalid handle.
|
-21
|
-
|
_BLE_ERR_NO_CACHE
|
|
No cache found, use bleServiceCacheUpdate to update the cache.
|
-99
|
-
|
_BLE_ERR_GENERIC
|
|
Failed to read
|
Declaration:
FUNCTION bleReadVal : INT;
VAR_INPUT
dev : SYSHANDLE;
char : UINT;
size : ACCESS INT;
data : PTR;
END_VAR;
Example:
...
size:=1;
rc := bleReadVal(dev:=dev, char:=bat_level_id, size := size, data := ADDR(bat_level));
DebugFmt(message:="bleReadVal(\2): \1", v1:=rc, v2:=bat_level_id);
...
|