This function will read the value that belongs to a notification and is used to handle event 16 (_BT_EVENT_NOTIFY) from btWaitEvent.
Input:
size : INT
The size of the buffer.
data : PTR
The buffer to read the data into.
Output:
service : INT
The service of the notification.
char : INT
The characteristic of the notification.
size : INT
The number of bytes read. If the buffer is too small, this will contain the needed size.
Returns: INT
1
|
-
|
_BT_OK
|
|
Success.
|
0
|
-
|
_BT_ERR_NOT_SUPPORTED
|
|
The API is not supported.
|
-1
|
-
|
_BT_ERR_NOT_OPEN
|
|
The adapter is not powered(see btPower).
|
-7
|
-
|
_BT_ERR_NO_RES
|
|
The buffer is too small for the data. The size parameter contains the needed size.
|
-8
|
-
|
_BT_ERR_INVAL
|
|
Invalid size provided.
|
-9
|
-
|
_BT_ERR_NODATA
|
|
No valid event found.
|
Declaration:
FUNCTION btleHandleNotification : INT;
VAR_INPUT
service : ACCESS INT;
char : ACCESS INT;
size : ACCESS INT;
data : PTR;
END_VAR;
Example:
...
THREAD_BLOCK btThread
VAR
rc : INT;
address : STRING;
ch : SINT;
pass : DINT;
service : INT;
chara : INT;
size : INT;
data : ARRAY [1..10] OF SINT;
END_VAR;
WHILE TRUE DO
rc := btWaitEvent(timeout:=10000, dev := address);
IF rc <> _BT_ERR_TIMEOUT THEN
DebugFmt(message:="event \1: "+address, v1:=rc);
CASE rc OF
_BT_EVENT_INCOMING:
rc := btHandleSerialPortIncomingConnection(ch := ch, port := port);
DebugFmt(message:="btHandleSerialPortIncomingConnection(\2) : \1, \3", v1:=rc, v2:=ch, v3:=port);
_BT_EVENT_DEV_FOUND:
DebugFmt(message:="Found "+address);
_BT_EVENT_DEV_LOST:
DebugFmt(message:="Lost "+address);
_BT_EVENT_PAIR_REQ:
DebugFmt(message:="Requested confirm for "+address);
rc := btHandlePairRequest(passkey:=pass);
DebugFmt(message:="Pass: \4, \1", v1:=rc, v4:=pass);
rc := guiShowMessage(message:="Is the pairing code "+dintToStr(v:=pass)+" correct?", type := 2, timeout := 20);
DebugFmt(message:="guiShowMessage: \1", v1:=rc);
rc := btSendPairResponse(accept:=(rc = 3));
DebugFmt(message:="btSendPairResponse: \1", v1:=rc);
_BT_EVENT_NOTIFY:
size := SIZEOF(data);
rc := btleHandleNotification(service := service, char := chara, size := size, data:=ADDR(data));
DebugFmt(message:="btleHandleNotification: \1, s\2,\3, sz: \4", v1:=rc, v2:=service, v3:=chara, v4:=size);
ELSE
DebugFmt(message:="unknown event: \1", v1:=rc);
END_CASE;
btEventDone();
END_IF;
END_WHILE;
END_THREAD_BLOCK;
...
|