This function will retrieve a service from the device.
To list all the known services, keep calling this function with incrementing index until it returns -4 (_BT_ERR_NOT_FOUND).
Note that some services that are used internally, such as Generic Access( UUID 00001800-0000-1000-8000-00805f9b34fb ) are not included.
Input:
dev : STRING
The address of the device to get the data from.
idx : INT
The index of the service to read.
Output:
service : INT
The ID to the service.
primary : BOOL
TRUE if this is a primary service.
UUID : STRING
The UUID of this service.
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).
|
-4
|
-
|
_BT_ERR_NOT_FOUND
|
|
The device or service could not be found.
|
-8
|
-
|
_BT_ERR_INVAL
|
|
This device does not have any services.
|
Declaration:
FUNCTION btleServiceGet : INT;
VAR_INPUT
dev : STRING;
idx : INT;
service : ACCESS INT;
primary : ACCESS BOOL;
UUID : ACCESS STRING;
END_VAR;
Example:
...
FUNCTION getServices
VAR_INPUT
dev : STRING;
END_VAR;
VAR
rc : INT;
rc2 : INT;
service : INT;
ch : INT;
primary : BOOL;
UUID : STRING;
i : INT;
c : INT;
flags : DINT;
END_VAR;
DebugMsg(message:="Get services for "+dev);
i := 1;
REPEAT
rc := btleServiceGet(dev:=dev, idx:=i, service:=service, primary:=primary, UUID:=UUID);
DebugFmt(message:=" btleServiceGet "+dev+": \1", v1:=rc);
IF rc = _BT_OK THEN
DebugFmt(message:=" Service: \1, primary: \2, UUID: "+UUID, v1:=service, v2:=INT(primary));
c := 1;
REPEAT
rc2 := btleCharGet(dev:=dev, idx:=c, service:=service, char:=ch, UUID:=UUID, flags := flags);
DebugFmt(message:=" btleCharGet "+dev+": \1", v1:=rc2);
IF rc2 = _BT_OK THEN
DebugFmt(message:=" Service: \1, Char: \2, flags: \4, UUID: "+UUID, v1:=service, v2:=ch, v4:=flags);
END_IF;
c := c + 1;
UNTIL rc2 <> _BT_OK END_REPEAT;
END_IF;
i := i + 1;
UNTIL rc <> _BT_OK END_REPEAT;
END_FUNCTION;
...
|