Pairing of two sets of the terminals is carried
out as server and client, respectively,
It
can make data communication by the Bluetooth(SPP) connection.
As apply, other than terminal, it can use for
machines control etc.
To use this function, Bluetooth function is
necessary to terminal.
Connection data.
Profile RFCOMM
SPP UUID = "00001101-0000-1000-8000-00805F9B34FB"
NAME = "bt_spp_andbas"
The flow of Bluetooth communications program.
Turn on both Bluetooth
switches. (BT_ENABLE)
Client-side acquires
the device by server-side for mating.(BT_DEVICE)
Server-side is in accept state.(BT_OPEN)
Client-side sends a connection signal to the
server-side, (BT_OPEN)
server-side receives
it, and socket is secured, and file is opened.
Data is exchanged.(BT_OUTPUT,BT_INPUT$)
By combined use of interruption command,
(BLUETOOTH,ON-BLUETOOTH)
there is the method
to receive the data only at the time of the data reception.
The minimum composition of
Bluetooth communication program.
Server-side: This is executed first, and make
'accept' state.
10
bt_open "accept"
20 bt_output "From
server"
30 a$=bt_input$(30):print a$
Client-side: since device
name comes out in dialog detection, select by tap.
The 'connect' signal is immediately send after
tapping.
10
bt_device
20 bt_open "connect"
30 bt_output "From client"
40 a$=bt_input$(30):print a$
When sending the 'connect'
signal, it is necessary that
the
server-side become in the 'accept' state first and wait.
-Caution: When different
Bluetooth application is used just before,
and When it was the application that it has not been release the socket at app
end,
it may not be able to connect. In this
case, please reset once.
BT_STATE$ |
[Features]
The state of Bluetooth is acquired and returned.
[Format] BT_STATE$([n])
[Explanation]
n=0 To return state of
Bluetooth.
Return value.
(String)
0 It is a model
without a Bluetooth function.
1 Bluetooth is OFF state.
2
Bluetooth is ON state.
3 The
state where the connection device is discovered.
4 Bluetooth is pairing connection,
and the state file is open.
n=1 To
return 'UUID of SPP'.
n=2 To
return Device name of other side(server). (cann't acquire client-side,return
null)
n=3 To return Mac Address
of other side(server). (cann't acquire client-side,return null)
[e.g.]
bt_open
if val(bt_state$(0))<4 then print"not
connect":end
BT_ENABLE |
[Features]
To switch ON/OFF of the Bluetooth function.
[Format] BT_ENABLE ON|OFF
[Explanation]
ON Bluetooth is turned ON.
OFF Bluetooth is turned OFF. Bluetooth
file is closed, and interrupt becomes 'off'.
[e.g.]
bt_enable on
BT_SIGNAL |
[Features]
To send a signal to have discovered device itself.
[Format] BT_SIGNAL [seconds]
[Explanation]
At the time of terminals connected for the
first time,
The signal is sent at the
other-side for being recognized
this
device name and Mac-Address.
This
operation is necessary only once at the first.
When the other-side choose 'Search
signal devices.' in 'BT_DEVICE',
this one send 'BT_SIGNAL' so as to overlap, the other-side can catch it.
After being recognized once,
since it comes to be displayed from the
beginning into the list of 'BT_DEVICE',
after that the execution of 'BT_SIGNAL' is not necessary.
(Please don't write 'BT_SIGNAL' in part
to be executed repeatedly in the program)
This signal can send in the same way from 'BT_Signal' of Menu.
(It is the easy way to send this from
Menu at the time of 'Search signal devices.')
It can specify the number of [seconds] to
send signal.(default is 15 seconds)
A
confirmation dialog will appear.
This
command progresses to the next command immediately after dialog closed.
(Usually, it becomes a flow of
'accept')
[e.g.]
bt_signal 20
BT_DEVICE |
[Features]
It discover and select devices to connect.
[Format]
BT_DEVICE ["DeviceName"]
[Explanation]
First, it is displayed 'to have connected devices name and MACAddress' in
a dialog.
If "DeviceName" is
specified and it exists in the list,
Device is selected automatically, and will proceed to the next.
Furthermore, when
user would like to detect the device
which has sent the discovery signal(the case of this app:BT_SIGNAL),
select 'Search signal devices.' at
the top.
The detection for about 12
seconds will start,
discovered
devices will be added to the list.
Although whichever may be executed first as
for (Server-BT_SIGNAL) and
(Client-'Search...'),
it is necessary
to overlap during this period.
When Bluetooth is OFF state, 'bluetooth on'
is executed automatically.
This
command doesn't progress to the next command until selection is performed.
When connection isn't completed and when
cancel is pushed,
acquisition
of device cannot be performed, but doesn't result in an error.
Immediately after, it can check by
'BT_STATE$()' to be acquired or not.
[e.g.]
bt_device
bt_device "android01"
BT_OPEN |
[Features]
[Format]
BT_OPEN ["function"][,seconds]
[Explanation]
To open Bluetooth file as server or client.
This is done in both device.
The [seconds] of reception can be
specified. (default 15)
["function"]: "accept" is opened as a
Server.
To wait for 'connect' signal
from the client side(accept-state),
and secure socket, and the file is opened.
["function"]: "connect" is opened as a
Client.
The 'connect' signal is sent
to the device acquired by 'BT_DEVICE',
and secure socket, and the file is opened.
For send 'connect' signal,
it is necessary that the other
device is in 'accept' state previously.
If ["function"] is omitted,
if the device is acquired by
'BT_DEVICE' in advance,
it will
be distinguished as "connect", otherwise "accept".
After BASIC starting, and there is connection
once, and
by execution of the same
settings repeatedly,
(Between the
same terminals, and when specification of server and client is the same)
In this case, and
Case "accept":
Selection dialog will appear.
[Last device.] It is in connection
with the same socket.
[Accepting
new.] To start the accepting newly.
(It is here also when server and client are exchanged)
Case "connect":
When having chosen the same device by
'BT_DEVICE'
-It is in connection with
the same socket.
If you want to send
'connect' signal newly,
execute
next command once,
bt_enable
off : bt_enable on (cleared)
and newly execution: BT_DEVICE -> BT_OPEN "connect"
(Usually, it is repeatedly
connectable
by
Server:"accept"->[Last device.] and Client:'BT_DEVICE'->select same
device)
When
Bluetooth is OFF state, 'bluetooth on' is executed automatically.
This command doesn't progress to the
next command
until 'open' work
finished or [seconds] time finished.
Even if the 'open' is not successful, it doesn't result in an error.
Immediately after, it can check by
'BT_STATE$()' to be file 'open' or not.
[e.g.]
Server-side
10 bt_enable on
20 bt_open "accept"
Client-side
10 bt_enable on
20 bt_device
30 bt_open "connect"
BT_INPUT$ |
[Features]
[Format]
BT_INPUT$ [second]
[Explanation]
To receive data(string) from
socket of Bluetooth.
It can specify
the number of seconds waiting for input. (default 5)
It doesn't progress to the next command
until 'input' finished or [seconds]
time finished.
When it finished
specified [seconds] without any input,
in this case, null string is returned.
When there are send data from the
other
and getting data by
'BT_INPUT$' is not made immediately,
it is stored in the stack, and when 'BT_INPUT$' is executed,
it is got as a series of string
together.
[e.g.]
a$=bt_input$(20)
print a$
BT_OUTPUT |
[Features]
To output data(string) from socket of Bluetooth.
[Format] BT_OUTPUT StringData
[Explanation]
Data input/output commands can be used in
both Server-side and Client-side.
[e.g.]
bt_output "data01"
BLUETOOTH |
[Features]
To switch on/off of interruption of Bluetooth.
[Format] BLUETOOTH ON|OFF
[Explanation]
When Bluetooth data reception happen,
go to interrupt processing routine
specified line
by 'ON BLUETOOTH
LineNumber',
and return to the
original line by 'return' command.
This command must have opened Bluetooth file first, and
the jump point must have specified by
'ON BLUETOOTH' command.
Because
'Input wait' always work at 'ON state',
should be 'OFF' at the program end.
cf: ON-BLUETOOTH (Interruption)
[e.g.]
10
bt_open "server"
20 on bluetooth gosub
100
30 bluetooth on
40 pause 1:goto 40
100 print bt_input$();:return
SAMPLE [ Bluetooth chat ]
Start by typing 1 and 2 in each
devices.
100
bt_enable on
110 input "1:Server
2:Client";sc
120 if sc<>1 then
bt_device
130 if sc=1 then bt_open"accept"
else bt_open"connect"
140 on stop gosub
230:stop on
150 on bluetooth gosub 220
160 bluetooth on
170 while -1
180 a$=inkey$:pause 1
190 if a$<>"" then print a$;:s$=s$+a$
200 if a$=chr$(13) then bt_output s$:s$=""
210 wend
220 c$=bt_input$():print c$;:return
230
bluetooth off:stop off:end
Explanation.
100 Turn on the bluetooth.
120 Executed Client->'bt_device'
130 Open for server or client.
140 ,230 End processing
150 ,160,220 Data reception, Interrupt
processing.
170 -210 Loop processing.
200 When enter, data output by
'bt_output'