! rev PF 09/04/2012 ! version RFO basic 01.50 ! test avec archos ! Liaison BlueTooth-click avec Archos ! BT envoi un indice toutes les 2 secondes et 3 mesures Analog ! archos affiche la reception et renvoi un N° de message recu !--------------------- ! Lancer terminal VBRAY ! test prealable en mode Commande doivent etre OK ! voir Bluetooth_click.log ! Selectionner COM2 115200,N,8,1 !connect !Hardware: !Module Bluetooth_Click Mikronicka relie a COM2 via interface RS232 DS275 !Alim 3,3V pour le module !seuls TX et RX sont connecte !Archos 43 it !Association avec Bluetooth_Click code =1234 ! debug.on Prog$="_Bluetooth_Click_120407" print "Version basic : "; Version$() Device DV$ print "Device Info : "; DV$ pause 3000 type=0 ! 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$[], "Connection avec Bluetooh-click","Continue to listen for connection","Quitter" msg$ = "Selection du mode" debug.print 10 bt.open 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 debug.print 15 !debug.echo.on if (type = 0) | (type =3) print "Thanks for playing" bt.close !debug.print 16 goto fini elseif type = 1 bt.connect Debug.print 17 endif Debug.print 20 !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 Debug.print "s=";s Debug.print 30 print "." ! When a connection is made get the name of the connected device bt.device.name device$ print "connection to ";device$ goto NoInit ! envoi les reponses à l'init BT pas=0; gosub ReadBT if (Is_in("$$$$",MsgR$,1) MsgE$="CMD"+chr$(13) bt.write msgE$ end if print "Pas=1" gosub ReadBT if (Is_in("("SN,MyBT-DB49",MsgR$,1) MsgE$="AOK"+chr$(13) bt.write msgE$ end if print "Pas=2" gosub ReadBT if (Is_in("("SU,38.4",MsgR$,1) MsgE$="AOK"+chr$(13) bt.write msgE$ end if print "Pas=3" gosub ReadBT if (Is_in("("SO,CONN",MsgR$,1) MsgE$="AOK"+chr$(13) bt.write msgE$ end if print "Pas=4" gosub ReadBT if (Is_in("("SM,0",MsgR$,1) MsgE$="AOK"+chr$(13) bt.write msgE$ end if print "Pas=5" gosub ReadBT if (Is_in("("SA,1",MsgR$,1) MsgE$="AOK"+chr$(13) bt.write msgE$ end if print "Pas=6" gosub ReadBT if (Is_in("("SP,1234",MsgR$,1) MsgE$="AOK"+chr$(13) bt.write msgE$ end if print "Pas=7" gosub ReadBT msgE$="END"+chr$(13) if (Is_in("("---",MsgR$,1) MsgE$="AOK"+chr$(13) bt.write msgE$ end if print "Pas=7 END of Init" !------------------------------- NoInit: ! *** Read/Write Loop **** RW_Loop: Debug.print 40 Debug.print "debut RW_loop" Do ! 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 perdue" goto new_connection endif gosub ReadBT ! Read messages until the message queue is empty ! boucle pour ne pas fractionner le message if dr=1 print left$(device$,9);" : " ;msgR$;chr$(13) k1=k1+1 Tone 800,1000 endif do gosub ReadBT until (Is_in('$',MsgR$,1)) ! Send a message if (dr=1) then msgE$= " Recep.# " +format$("####",k1)+chr$(13) bt.write msgE$ print "Archos: "; msgE$ end if pause 1000 until (msgR$="fin"); bt.close pause 4000 fini: Debug.print "fin normale" Console.save Prog$+".txt" Console.save "Err_"+Prog$+".txt" goto !================================================= ReadBT: ! Read messages until the message queue is empty ! boucle pour ne pas fractionner le message A1$="" MsgR$="" dr=0 bt.status s if s= 3 do bt.read.ready rr if rr dr=1 bt.read.bytes A1$ MsgR$=MsgR$+A1$ pause 100 end if until rr=0 endif return !OnError: Debug.print "sortie sur Erreur" fin: Console.save "Err_"+Prog$+".txt" pause 2000 end