!! rev PF 09/11/2011 RFO basic version 01.35 ! ! ! organisation de stockage des objets et images: ! lumiere 1...5 img 7,8 ! chauffage 6 ...10 img 9,10 ! tradiobutton 1...15 img 1,2 ! leds 20...27 img 5,6 !! debug.on dim Bm[30] % Bitmaps dim ArrPlan[2] dim ObjFixe[2] dim Obj[40] dim ObjStatus[40] dim RT[8] % etat des retours de cde R1$="" % Retour de commande Ecr$="" % Ecriture des commande Lec1$="" % Lecture des entrees J1=0 KK=0 K1=0 Prog$="111109a" debug.print 1 NbMax=50 msg$="Usage de Socket RFO Basic" print msg$ test=1 % simulation reception sockett ip$="192.168.0.105" port=10001 print "Xport at "ip$;" Port:";format$(" #####",port) !socket.client.close ! Connect to the Xport Client ! if test=0 then socket.client.connect ip$,port print "Connected to ";ip$ ! Wait for Client to send a message ! or time out after 3 seconds debug.print 25 maxclock = clock() + 3000 ! data must be received within 2 sec do socket.client.read.ready flag if clock() > maxclock print "Read time out" end endif print "."; pause 100 until flag print " " print "flag=";flag ! Message recu socket.client.read.line recept$ else recept$="#11/11/06 12:37:45;A1=0512;A2=0768;A3=384;A4=600;L=00001010;R=00100010;&" end if % test=0 print recept$ msg$="associ� � Platine_16F877_nokia_RS_2011.asm" print msg$ debug.print 35 !gr.open alpha, red, green, blue {, ShowStatusBar} gr.open 255,0,0,0,0 % 1 => status ba en haut de l'ecran gr.orientation 0 ! Recupere les parametres de l'ecran w=largeur et h=hauteur gr.screen w,h !block = h/8 !xleft = w/4 debug.print 40 gr.bitmap.load ArrPlan[1],"Arrplan.jpg" % Image de fond d'ecran FIXE debug.print 46 gr.bitmap.load bm[1],"RadioBOff.jpg" % Radio bouton etat OFF debug.print 51 gr.bitmap.load bm[2],"RadioBOn.jpg" % Radio Bouton = ON debug.print 52 gr.bitmap.load bm[3],"LedR_off.jpg" % Led Rouge etat OFF debug.print 53 gr.bitmap.load bm[4],"LedR_on.jpg" debug.print 54 gr.bitmap.load bm[5],"LedV_off.jpg" debug.print 55 gr.bitmap.load bm[6],"LedV_on.jpg" debug.print 56 gr.bitmap.load bm[7],"Ampoule_OFF_.jpg" debug.print 57 gr.bitmap.load bm[8],"Ampoule_ON_.jpg" debug.print 60 gr.bitmap.load bm[9],"Radiat_off_H.jpg" debug.print 62 gr.bitmap.load bm[10],"Radiat_on_H.jpg" debug.print 63 gr.bitmap.draw ObjFixe[1],Arrplan[1],0,0 debug.on gr.render debug.print 65 pause 1000 ! -- debut boucle principale---------------------- j1=0 Dt=0 DO Nclock=Clock() ! normal sending from XPORT is every 2 secondes, so test with +50% if test=0 then maxclock=clock()+4000 flag=0 while (flag<1) socket.client.read.ready flag if clock() > maxclock print "Timeout sur reception trame" goto arreter endif pause 50 print "."; repeat print " " debug.print 67 socket.client.read.line recept$ else pause 1000 end if split rec_Array$[],recept$,";" array.length longueur, rec_Array$[] debug.print "longueur : ";longueur debug.print "recu :"; recept$ ! affichage Trame pour debugging gr.text.align 1 gr.text.size h/32 gr.color 255,255,255,255,1 % blanc gr.text.draw Tr,10,448,recept$ debug.print 68 for i= 1 to longueur print rec_Array$[i] next i debug.print 69 Horodat$=right$(rec_Array$[1],17) gr.color 255,255,255,255,1 % blanc gr.text.draw Ho,110,17,Horodat$ ! affichage valeur indice gr.text.align 1 gr.text.size h/32 gr.color 255,255,0,0,1 % rouge ind$=format$("#####",j1) gr.text.draw P0,45,15,ind$ debug.print 70 !gr.color alpha, red, green, blue, fill gr.color 200,160,160,50,1 ! Set the text align to Left = 1 center=2 right=3 gr.text.align 1 gr.text.size h/32 !extration valeur de Entree Analogique A1 !A1=512 ch$=mid$(rec_Array$[2],4,4) debug.print ch$ ! TExt -10 a +50C =>60degC pour 1024 points A1=val(ch$) if test=1 then A1=500+j1 V1=A1*60/1023 V1=V1-10 % offset -10degC m1$=format$(" ##.##",V1) gr.color 200,200,20,200,1 gr.text.draw P1, 260,150, m1$ !affichage valeur gr.text.align 1 debug.print 72 !extration valeur de Entree Analogique A2 ch$=mid$(rec_Array$[3],4,4) debug.print ch$ ! Tamb echelle 50 C pour 1024 pts A2=val(ch$) if test=1 then A2=480-j1; V2=A2*50/1024 m2$=format$("##.##",V2) gr.color 200,200,200,200,1 gr.text.draw P2,700,410,m2$ debug.print 74 !extration valeur de Entree Analogique A3 !A3=256 ch$=mid$(rec_Array$[4],4,4) debug.print ch$ A3=val(ch$) if test=1 then A3=384+Rnd(0)*j1/2 V3=A3*50/1024 m3$=format$("#####",V3) debug.print 75 !extration valeur de Entree Analogique A4 !A4=256 ch$=mid$(rec_Array$[5],4,4) debug.print ch$ A4=val(ch$) if test=1 then V4=A4*50/1024 m4$=format$("#####",V4) debug.print 78 ! extraction valeur des Entrees Lues "L" ! et rafraichissement etat des leds Lec1$="00000000" Lec1$=mid$(rec_Array$[6],2,8) debug.print "Lec=";Lec1$ if test=1 then L1$="01010101" for i=0 to 7 if (mid$(Lec1$,i+1,1)="1" then gr.bitmap.draw Obj[20+i],bm[6],740,60+i*40 else gr.bitmap.draw Obj[20+i],bm[5],740,60+i*40 end if next i debug.print "80 Lec1$=";Lec1$ ! Trace des Axes en Vert/Green ! 0,0 en haut a gauche gr.color 255,0,255,0,1 % vert gr.set.stroke 2 gr.line axeH, 360, 20, 616, 20 gr.line axeV, 360, 20, 360, 420 gr.set.stroke 1 debug.print 90 cx = 0.25 % (616-360)/1024 cy = j ! Trace en Rouge/Red gr.color 255,255,0,0,1 !gr.set.pixels Punct,cx,cy gr.render debug.print 110 ! extraction valeur des Retours de commande "R" ! et rafraichissement etat des leds R1$="00000000" R1$=mid$(rec_Array$[7],3,8) debug.print "R=";R1$ for i=0 to 7 if (mid$(R1$,i+1,1)="1" then RT[i+1]=1 else RT[i+1]=0 end if next i debug.print 130 ! Zone lumiere salon Ecr$="" % ecriture de 8 bits for i=0 to 4 t1=0 dy=80*i gr.bounded.touch t1, 130,45+dy,150,75+dy if t1=1 then debug.print "zone lumiere touchee ",ObjStatus[1+i] Tone 600,200 ObjStatus[i+1]=!ObjStatus[i+1] gr.bitmap.draw Obj[i+1],bm[7+ObjStatus[i+1]],120,40+dy if ObjStatus[i+1]=1 then ecr$="1"+ecr$ else ecr$="0"+ecr$ end if debug.print ecr$ end if next i ecr$="000"+ecr$ debug.print 160 !Socket.client.write.line Ecr$ debug.print "165 Socket write =";Ecr$ !zone radiateur salon for i=0 to 4 if i<> 1 then t2=0 dy=i*80 gr.bounded.touch t2, 190,45+dy,230,75+dy if t2 =1 then debug.print "zone radiateur touchee = ",ObjStatus[6+i] ObjStatus[6+i]=!ObjStatus[6+i] ! if ObjStatus[6+i]=1 then ! Ecr$=Ecr$+"1" ! else ! Ecr$=Ecr$+"0" ! end if Tone 440,200 gr.bitmap.draw Obj[6+i],bm[9+ObjStatus[6+i]],180,40+dy end if % t2=1 end if % i<>1 next i !Ecr$=Ecr$+"0000000" % sur 16 bits ! debug.print 170 !zone Radiobutton for i=0 to 4 t2=0 dy=i*80 gr.bounded.touch t2,270,45+dy,290,75+dy if t2 =1 then debug.print "zone Radiobutton touchee = ",ObjStatus[11+i] gosub RazButton ObjStatus[11+i]=!ObjStatus[11+i] Tone 440,200 gr.bitmap.draw Obj[11+i],bm[1+ObjStatus[11+i]],260,40+dy end if next i debug.print 180 gr.render !duree de la boucle Dt =Dt+clock()-Nclock if j1=NbMax-1 then gr.save Prog$+".png" pause 200 j1=j1+1 ! efface tout et recommence !gr.cls gr.hide P0 gr.hide P1 gr.hide P2 !gr.hide P3 gr.hide Ho gr.hide Tr unDim rec_Array$[] debug.print 200 until (j1>NbMax) ! --------- fin de boucle principale ----- ! popup "fin normale..",250,250,2000 gr.close socket.client.close print "deconnection" Tone 440,1000 Tone 800,1000 Tone 600,1000 pause 2500 ici: print " " print "_socket_xport-"+Prog$+".bas" !Attention ne pas utiliser PRINT tout seul print "version basic : ";VERSION$() print "Resolution Ecran " print "Larg = ";w print "Haut = ";h print "Temps ecoule (en heure)depuis le dernier demarrage: ";format$("##.###",clock()/3600000) print "Dt 1 boucle =";Dt/NbMax;" mS" !browse "http://paulfjujo.free.fr" arreter: pause 2000 Console.save Prog$+".txt" end OnError: debug.print "sortie sur Erreur" Console.save "error_"+Prog$+".txt" pause 2000 end RazButton: debug.print Subroutine !Radio Buttons off for jj=0 to 4 if jj<>1 then gr.bitmap.draw Obj[11+jj],bm[1],260,40+80*jj ObjStatus[11+jj]=0 next jj return Octet2Binaire: E1$="" k1=j1 & 255 for kk=0 to 7 if (k1 && 2^(7-kk)) >0 then E1$=E1$+"1" else E1$=E1$+"0" end if next kk debug.print "E1$=";E1$ return