!! This program demonstrates using Bluetooth as both an application that listens for a connection or makes a connection to a listener. Before running this program use the Android "Settings" application to enable Bluetooth and to pair with the device(s) that you will talk to. This program will send and receive data bytes to and from a connected device. You can use this program to (among many other things) set up a chat between two Android devices. Note: The UUID used by default is the standard serial port UUID. This can be changed. Read the manual. !! ! Begin by opening Bluetooth ! If Bluetooth is not enabled ! the program will stop here. BT.OPEN ! When BT is opened, the program ! will start listening for another ! device to connect. At this time ! the user can continue to wait ! for a connection are can attempt ! to connect to another device ! that is waiting for a connection ! Ask user what to do ARRAY.LOAD type$[], "Connect to listener", "Continue to listen for connection", "Quit" msg$ = "Select operation mode" new_connection: SELECT type, type$[], msg$ ! If the user pressed the back ! key or selected quit then quit ! otherwise try to connect to ! a listener IF (type = 0) | (type =3) PRINT "!!!" BT.CLOSE END ELSEIF type = 1 BT.CONNECT ENDIF ! Read status until ! a connection is made DO BT.STATUS s IF s = 1 PRINT "Listening ELSEIF s =2 PRINT "Connecting" ELSEIF s = 3 PRINT "Connected" ENDIF PAUSE 1000 UNTIL s =3 ! When a connection is made ! get the name of the connected ! device BT.DEVICE.NAME device$ cls ! Задержка fk$ = "3" ! Пауза fm$ = "3" ! Горизонтальных шагов fe$ = "4" ! Вертикальных шагов fn$ = "1" ! Горизонтальный угол ff$ = "20" ! Вертикальный угол fg$ = "30" a$ = "X = 0" b$ = "Y = 90" ARRAY.LOAD menus$[], "Задержка =", "Пауза ="~ "Горизонтальный угол =", "Вертикальный угол ="~ "Шагов по горизонтали =", "Шагов по вертикали =", "Лево", "Право"~ "Верх", "Низ", "Затвор", "Панорама" ARRAY.LOAD months$[], menus$[1] + fk$, menus$[2] + fm$ ~ menus$[3] + ff$, menus$[4] + fg$, menus$[5] + fe$, menus$[6] + fn$ ~ menus$[7], menus$[8], menus$[9], menus$[10], menus$[11]~ menus$[12], a$ + " : " + b$ ! Set the Popup Message msg$ ="Меню" Menu: ! Read status to insure ! that we remain connected. ! If disconnected, program ! reverts to listen mode. ! In that case, ask user ! what to do. BT.STATUS s IF s<> 3 PRINT "Connection lost" GOTO new_connection ENDIF ! Shows the list and waits for the user ! to make the selection. SELECT month, months$[], msg$ ! if the selection was zero, the user hit the ! BACK key IF month = 1 input menus$[1], fk$ months$[1] = menus$[1] + fk$ goto Menu ELSEIF month = 2 input menus$[2], fm$ months$[2] = menus$[2] + fm$ goto Menu ELSEIF month = 3 input menus$[3], ff$ months$[3] = menus$[3] + ff$ goto Menu ELSEIF month = 4 input menus$[4], fg$ months$[4] = menus$[4] + fg$ goto Menu ELSEIF month = 5 input menus$[5], fe$ months$[5] = menus$[5] + fe$ goto Menu ELSEIF month = 6 input menus$[6], fn$ months$[6] = menus$[6] + fn$ goto Menu ELSEIF month = 7 BT.WRITE chr$(27)+"r"+ff$+Chr$(19) sss$ = "@" DO BT.READ.READY rr IF rr BT.READ.BYTES msgs$ j = LEN(msgs$) FOR i=1 TO j ms$ = MID$(msgs$,i,1) IF ASCII(ms$) > 19 m$ = m$ + ms$ ELSEIF ASCII(ms$) = 19 IF flaga = 1 a$ = "X = " + m$ ELSEIF flagb = 1 b$ = "Y = " + m$ ENDIF IF m$ = "A" flaga = 1 ELSEIF m$ = "B" flagb = 1 ELSE flaga = 0 flagb = 0 sss$ ="x" months$[13] = a$ + " : " + b$ ENDIF m$ = "" ENDIF NEXT ENDIF UNTIL sss$ <> "@" goto Menu ELSEIF month = 8 BT.WRITE chr$(27)+"q"+ff$+Chr$(19) sss$ = "@" DO BT.READ.READY rr IF rr BT.READ.BYTES msgs$ j = LEN(msgs$) FOR i=1 TO j ms$ = MID$(msgs$,i,1) IF ASCII(ms$) > 19 m$ = m$ + ms$ ELSEIF ASCII(ms$) = 19 IF flaga = 1 a$ = "X = " + m$ ELSEIF flagb = 1 b$ = "Y = " + m$ ENDIF IF m$ = "A" flaga = 1 ELSEIF m$ = "B" flagb = 1 ELSE flaga = 0 flagb = 0 sss$ ="x" months$[13] = a$ + " : " + b$ ENDIF m$ = "" ENDIF NEXT ENDIF UNTIL sss$ <> "@" goto Menu ELSEIF month = 9 BT.WRITE chr$(27)+"s"+fg$+Chr$(19) sss$ = "@" DO BT.READ.READY rr IF rr BT.READ.BYTES msgs$ j = LEN(msgs$) FOR i=1 TO j ms$ = MID$(msgs$,i,1) IF ASCII(ms$) > 19 m$ = m$ + ms$ ELSEIF ASCII(ms$) = 19 IF flaga = 1 a$ = "X = " + m$ ELSEIF flagb = 1 b$ = "Y = " + m$ ENDIF IF m$ = "A" flaga = 1 ELSEIF m$ = "B" flagb = 1 ELSE flaga = 0 flagb = 0 sss$ ="x" months$[13] = a$ + " : " + b$ ENDIF m$ = "" ENDIF NEXT ENDIF UNTIL sss$ <> "@" goto Menu ELSEIF month = 10 BT.WRITE chr$(27)+"p"+fg$+Chr$(19) sss$ = "@" DO BT.READ.READY rr IF rr BT.READ.BYTES msgs$ j = LEN(msgs$) FOR i=1 TO j ms$ = MID$(msgs$,i,1) IF ASCII(ms$) > 19 m$ = m$ + ms$ ELSEIF ASCII(ms$) = 19 IF flaga = 1 a$ = "X = " + m$ ELSEIF flagb = 1 b$ = "Y = " + m$ ENDIF IF m$ = "A" flaga = 1 ELSEIF m$ = "B" flagb = 1 ELSE flaga = 0 flagb = 0 sss$ ="x" months$[13] = a$ + " : " + b$ ENDIF m$ = "" ENDIF NEXT ENDIF UNTIL sss$ <> "@" goto Menu ELSEIF month = 11 BT.WRITE chr$(27)+"k"+fk$+Chr$(19) BT.WRITE chr$(27)+"o"+fm$+Chr$(19) goto Menu ELSEIF month = 12 BT.WRITE chr$(27)+"k"+fk$+Chr$(19) BT.WRITE chr$(27)+"e"+fe$+Chr$(19) BT.WRITE chr$(27)+"n"+fn$+Chr$(19) BT.WRITE chr$(27)+"f"+ff$+Chr$(19) BT.WRITE chr$(27)+"g"+fg$+Chr$(19) BT.WRITE chr$(27)+"m"+fm$+Chr$(19) sss$ = "@" Kb.toggle DO BT.READ.READY rr IF rr !Pause 500 BT.READ.BYTES msgs$ j = LEN(msgs$) FOR i=1 TO j ms$ = MID$(msgs$,i,1) IF ASCII(ms$) > 19 m$ = m$ + ms$ ELSEIF ASCII(ms$) = 19 IF flaga = 1 a$ = "X = " + m$ ELSEIF flagb = 1 b$ = "Y = " + m$ ENDIF IF m$ = "A" flaga = 1 ELSEIF m$ = "B" flagb = 1 ELSE flaga = 0 flagb = 0 cls PRINT a$ + " : " + b$ months$[13] = a$ + " : " + b$ ENDIF m$ = "" ENDIF NEXT !PRINT device$;": ";msgs$ ENDIF Inkey$ sss$ UNTIL sss$ <> "@" Kb.hide goto Menu ELSEIF month = 13 goto Menu ELSE PRINT "Выход"; ENDIF BT.CLOSE BT.OPEN GOTO new_connection !OnMenuKey: !sss$ = "x" !print "xxx" !MenuKey.Resume