This function will write data to a characteristic on a device.
Input:
dev: SYSHANDLE
Handle to the device.
char : UINT
The ID of the characteristic to write to.
mode : INT (default 0)
The kind of write to perform.
0
|
-
|
Auto
|
|
Use write with response if supported, otherwise try write with no response.
|
1
|
-
|
No response
|
|
Use write with no response.
|
2
|
-
|
Response
|
|
Use write with response.
|
size : INT
The size of the data to write.
data : PTR
A pointer to the data to write.
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
|
|
Selected mode not supported. If mode is 0, the characteristic does not support writing.
|
-9
|
-
|
_BLE_ERR_NODATA
|
|
Characteristic not found
|
-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 write
|
Declaration:
FUNCTION bleWriteVal : INT;
VAR_INPUT
dev : SYSHANDLE;
char : UINT;
mode : INT;
size : INT;
data : PTR;
END_VAR;
Example:
...
rc := bleWriteVal(dev:=dev, char:=led_color_id, size := 4, data := ADDR(colors));
DebugFmt(message:="bleWriteVal(): \1: ", v1:=rc);
...
|