hBasic Manual Bluetooth
command changes
|
||||||||||||||||||||
Return Codes
An optional return code variable {rc_nvar} can be
inserted for the following commands;
BT.OPEN { rc_nvar, } {secure_lexp} BT.CONNECT { rc_nvar, } {secure_lexp} BT.CONNECT.TO { rc_nvar, } {secure_lexp, } mac$_sexp BT.DEVICE.NAME { rc_nvar, } name$_svar BT.DEVICE.ADDR { rc_nvar, } mac$_svar BT.READ.BYTES { rc_nvar, } buffer$_svar BT.RECONNECT { rc_nvar } In the case of { rc_nvar, } {secure_lexp} if only one expression is given, without a preceding comma, it will be taken as {secure_lexp}. If the return code rc_nvar is unused (omitted), you will get Run-Time-Error upon an error. If the return code rc_nvar is used (not omitted), then certain Run-Time-Errors will be suppressed and the program will continue. These errors include;
Bluetooth is not available These errors can be read with the system function
getError$().Bluetooth Not Enabled Bluetooth not connected Could not get remote device Connect error: .. Error> selecting device Not previously connected
You will
still get Run-Time-Errors for
Syntax-Errors Bluetooth not opened No Bluetooth permsissions granted The code value returned depends on the command but in general the return codes are as follows;
Note that a positive return code (OK) does not
neccessarily mean that an operation was successful, but does mean that the command launched without errors. You should also use BT.STATUS to check the current status.
Examples
s=1 BT.CONNECT rc,s % get result, set secure BT.CONNECT rc, % get result, default secure BT.CONNECT s % no result, set secure BT.CONNECT % no result, default secure BT.CONNECT.TO m$ % default result, default secure BT.CONNECT.TO rc,,m$ % get result, default secure BT.CONNECT.TO s,m$ % no result, set secure |
||||||||||||||||||||
BT.CONNECT BT.CONNECT { rc_nvar, } {secure_lexp} Connect to a bluetooth device by selecting one from a dialog. This is now a modal dialog (blocking). Your program will not continue until the dialog closes secure
This optional parameter dictates whether the
connection should be secure or not.
rc
An optional return code.
If the rc varaible is used, the command will suppress some run-time-errors during connection. rc returns; 1 = OK 0 = Error (a description may be found with getError$() ) -1 = Cancelled dialog (user touched outside or hit BackKey) |
||||||||||||||||||||
BT.CONNECT.TO
BT.CONNECT.TO
{ rc_nvar,
} {secure_lexp,
} mac$_sexp
Connects directly to a device given the MAC address
mac$.
Leading commas are optional if only mac$ is used. If only one numeric expression is given, it is taken as secure_lexp. mac$
A MAC address is 6 hex bytes separated with
colons
e.g 11:22:33:DD:EE:FF It is exactly 17 characters long. The MAC address is not optional. If you don't already have a MAC address, you can get one from BT.GET.PAIRED.
secure
This optional parameter dictates wether the
connection should be secure or not. rc
An optional return code.
If the rc variable is used, the command will suppress some run-time-errors during connection. rc returns; 1 = OK 0 = Error (a description may be found with getError$() )
Example
BT.CONNECT.TO
m$
% default
result, default secure
|
||||||||||||||||||||
BT.DEVICE.ADDR
BT.DEVICE.ADDR
{ rc_nvar,
} mac$_svar
Get the MAC address of the currently connected (other)
device.
The connection state must be connected (3) or there will be an error. Some run-rime-errors can be suppressed with rc_nvar. mac$
The variable to get the device MAC address.
e.g 11:22:33:DD:EE:FF It is exactly 17 characters long. The MAC address is not optional.
rc
An optional return code.
If the rc variable is used, the command will suppress some run-time-errors. rc returns; 1 = OK 0 = Error (a description may be found with getError$() ) |
||||||||||||||||||||
BT.GET.PAIRED
BT.GET.PAIRED
macList_nexp { , nameList_nexp, }
Get list/s of paired devices.
Gets the paired MAC addresses into a list given by
macList_nexp. Optionally get the corresponding Names into the list nameList_nexp. If the given list/s already exist, it is overwriiten. If the given list/s does not exist, and is a numeric variable (nvar), a new list is created and the index is put in the variable. If the given list/s does not exist, and is not a numeric variable, there will be an error. If there are no paired devices. The list/s will be empty.
Example
BT.OPEN BT.GET.PAIRED macList, nameList list.size macList,z .cs "TextSize 16" ? int$(z);" paired devices" for i=1 to z list.get maclist,i,mac$ list.get nameList,i,name$ ? int$(i);" ";mac$;"-";name$ next END |
||||||||||||||||||||