mardi 8 avril 2014

Un an déjà

  Bonjour
  Cela fait un an que "maître Klaus "
 nous a modifié la "DLL IO_Acces_Com" pour l'adapter à "Panoramic"
  cela ma permit de faire dialoguer "Panoramic" avec extérieur
  par exemple le monde de l’électronique et les cartes "Arduino"
  avec des exemples sur mon blog.
  Seul bémol cela n'a pas fait beaucoup d’émule dommage.
  voici un programme en "Panoramic"
  qui affiche la courbe de tension d'une entrée analogique
  d'une carte "Arduino Uno" et sauvegarde le graphique dans un fichier "BMP".
 Pour le bon fonctionnement du programme écrit en basic "Panoramic"
  il faut une carte "Arduino" et la "dll com série"  et brancher le tout.

  Plusieurs boutons à disposition :
 scrutation pour acquérir les données .
  On quitte la scrutation par la touche "Echap"
  Aide: un petit help.
  Raz: pour effacer le graphique.
 Save: pour sauvegarder le graphique en un fichier "BMP".
  Fin: pour quitter
 Le programme est un simple visualiseur de courbe de tension
  d'une entrée analogique

 dll : IO_Access_COM.dll.
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC  Présentation et bavardage
 http://panoramic.free-boards.net/t2936-panoramic-arduino






Code Panoramic :






error_french

 top 0,(screen_y-height(0))/2 :left 0,(screen_x-width(0))/2

alpha 1
label sp_affichage,sp_fin,sp_reception,sp_emission,sp_scrutation
label sp_help,sp_form_help,sp_fin_help,sp_raz,form_affiche
label sp_save,sp_time,sp_info,sp_line
dim i,nobj,com_ok ,a%,dat%,donner$,poubele$,scrut
dim afbar,tension(260),nbscrut,messageinfo$
dim hs,ms,ss,hds,hfs,ts,j,pom,lx
color 0,160,160,200:wait 20
 caption 0,"Courbe de tension d'une entrée analogique Arduino Uno"
' ==============
com_serie():' ==
' ==============
top 0,(screen_y-height(0))/2 :left 0,(screen_x-width(0))/2
gosub form_affiche
 save_dialog 5
nobj=10 :affichtxt(nobj,0,100,30,16," Volt ")
nobj=20: button_container(nobj,0,160,30,"Scrutation")
nobj=30: voyant_automate(nobj,0,10,30,"COM",0)
nobj=40: button_container(nobj,0,660,30,"F I N")
nobj=50: affichtxt(nobj,0,10,width(0)-250,16," PANORAMIC ")
nobj=60: button_container(nobj,0,260,30,"Aide")
nobj=70: button_container(nobj,0,360,30,"R A Z")
nobj=80: button_container(nobj,0,460,30,"SAVE")
nobj=90: affichtxt(nobj,0,10,120,12,"Début de la Scrutation  Echap pour Quitter"):hide 90
nobj=95: button_container(nobj,0,560,30,"Info")
gosub sp_form_help
on_close 0,sp_fin:on_click 21,sp_scrutation
on_click 41,sp_fin:on_click 61,sp_help
on_double_click 200,sp_fin_help:on_click 71,sp_raz
on_click 81,sp_save:on_click 96,sp_info
' ==============
end
' =====scrutation=========
sp_scrutation:
cls
 nbscrut=0
 hide 21:hide 41: hide 61 : hide 71: hide 81:hide 96
 off_close 0
 if com_ok=1
 show 90:caption 91,"début  de la scrutation   Echap pour Fin"
 else
      message "   Pas de  scrutation défaut com Série"
      show 21:show 41:show 61:show 71:show 81:show 96
      on_close 0,sp_fin
  return
 end_if
 scrut=0:afbar=0
 gosub sp_time
 hds=hs+ms+ss
 while scrut<>27
      gosub sp_emission
      nbscrut=nbscrut+1
   scrut=scancode
 end_while
 gosub sp_line
 gosub sp_time
 hfs=hs+ms+ss
 ts = hfs-hds
 hide 90
 show 21:show 41:show 61:show 71:show 81:show 96
 on_close 0,sp_fin
return
' =====émission=====
sp_emission:
 a%= dll_call1("ComSetDataOut",101):' 101=e pour emettre
 gosub sp_reception
return
' =====réception========
sp_reception:
 if com_ok=1
    a%=DLL_CALL1("ComGetDataIn",adr(dat%))
     WHILE a%>0
         if dat%> 47 and a% <58
            donner$=donner$+chr$(dat%)
         end_if
         if chr$(dat%)="%"
             poubele$=chr$(dat%)
             gosub sp_affichage
        end_if
        a%=DLL_CALL1("ComGetDataIn",adr(dat%))
    END_WHILE
 end_if
return
' =====affichage========
sp_affichage:
 2d_pen_width 4
 afbar=afbar+1
 donner$=trim$(donner$)
 tension(afbar)=val(donner$)
 if afbar=1 then 2d_poly_from 0,pom-tension(1)
    if afbar>255
      afbar=254: cls
      2d_poly_from 0,pom-tension(254)
      for i= 2 to 255-1
          tension(i)=tension(i+1)
          2d_line (lx*i)-1,pom-tension(i-1)/2,lx*i,pom-tension(i)/2
      next i
 end_if
 if afbar=1 then 2d_poly_to 0,pom-tension(afbar)/2
 2d_poly_to lx*afbar,pom-tension(afbar)/2
 caption 11,left$(str$(5/1023*val(donner$)),4)+ "V"
 donner$=""
return
' ====Fin=========
sp_fin:
 if com_ok=1
   a%= dll_call1("ComUsePort",0)
   dll_off
 end_if
 terminate
return
' =============
sp_help:
 show 200
return
' =============
sp_fin_help:
 hide 200
return
' =============
sp_raz:
 cls
 afbar=0
 for i= 1 to 260
 tension(i)=0
 next i
return
' ===================
sp_save:
 cls: caption 11," 0 V"
 2d_pen_color 0,255,0
 2d_pen_width 2:2d_rectangle 2,2,width(501)-2,height(501)-2
 gosub sp_line
 2d_pen_solid:2d_pen_width 4:2d_pen_color 255,0,0
 for i= 2 to 255
        2d_line (lx*i)-1,pom-tension(i-1)/2,lx*i,pom-tension(i)/2
 next i
 font_size 501,14:font_bold_off  501
 print_locate 200,570:print "Panoramic  "+date$+"  "+time$
 rem sauvegarder  dans un fichier graphique (BMP)
 if message_confirmation_yes_no("Sauvegarder dans un fichier graphique BMP ?")=1
   file_save 501,file_name$(5)
 end_if

 2d_pen_color 0,0,255
return
' ===================
sp_line:

 2d_pen_width 1:2d_pen_color 0,0,255:2d_pen_dash_dot
 font_size 501,8:font_bold 501:print_target_is 501
 2d_line 5,pom,256*lx,pom:print_locate 20,pom : print "0V"
 2d_line 5,pom-102,256*lx,pom-102:print_locate 20,pom-102 : print "1V"
 2d_line 5,pom-205,256*lx,pom-205:print_locate 20,pom-205 : print "2V"
 2d_line 5,pom-307,256*lx,pom-307:print_locate 20,pom-307 : print "3V"
 2d_line 5,pom-410,256*lx,pom-410:print_locate 20,pom-410 : print "4V"
 2d_line 5,pom-512,256*lx,pom-512:print_locate 20,pom-512 : print "5V"



return
' ===================
sp_time:
hs=val(left$(time$, 2))*3600
ms=val(mid$(time$,4,2))*60
ss=val(right$(time$,2))
return
' ===================
sp_info:
messageinfo$="durée de la scrutation "+str$(ts)+ " secondes"
messageinfo$=messageinfo$+chr$(10)+chr$(13)
messageinfo$=messageinfo$+" nombre de Points  "
messageinfo$=messageinfo$+str$(nbscrut)
messageinfo$=messageinfo$+chr$(10)+chr$(13)
messageinfo$=messageinfo$+"une période  "
if ts<>0 and nbscrut<>0
 messageinfo$=messageinfo$+left$(str$(ts/nbscrut),5)+" secondes"
 end_if
messageinfo$=messageinfo$+chr$(10)+chr$(13)
messageinfo$=messageinfo$+"fréquence de la scrutation   "
if nbscrut<>0
 messageinfo$=messageinfo$+left$(str$(1/(ts/nbscrut)),5)+"   hertzs"
 end_if
message messageinfo$

return
' ===================
form_affiche:
 lx=3 :' largeur entre deux x
 panel 500:parent 500,0:top 500,80:left 500,120
 picture 501:parent 501,500 :top 501,10:left 501,10
 width 501,256*lx:height 501,600
 width 500, width(501)+20:height 500,620:color 500,0,0,0
 width 0,(width(500)+(100*2))
 height 0,(height(500)+80*2.5)
 top 0,(screen_y-height(0))/2 :left 0,(screen_x-width(0))/2
 pom =544
 2d_target_is 501
 2d_pen_width 3
 2d_pen_color 0,0,255
 2d_poly_from 0,pom
return
' =============
sub com_serie()
 dim_local rc,rrc
 ' suivent configuration
 rem DLL chargée en mémoire  suivent configuration
 dll_on "c:\dll_Panoramic\IO_Acces_COM.dll"
 rc= dll_call1("ComUsePort",8)
 if rc=1
    rrc= dll_call4("ComConfig",115200,8,1,0)
 end_if
 if rc=1 and rrc=1
    com_ok =1
 else
    rc= dll_call1("ComUsePort",0)
    dll_off
    message "Defaut_com_Serie"
 end_if
end_sub
' ====================
sub voyant_button(ntp,par,ttp,ltp,bv$,txt$,colv$,cole$,coef,fz)
 dim_local htop
 panel ntp+1 :color ntp+1,55,55,50:top ntp+1,ttp:left ntp+1,ltp
 width ntp+1,30*coef:height ntp+1,40*coef
 panel ntp+2 :parent ntp+2,ntp+1
 if cole$= "j" then color ntp+2,255,255,0
 if cole$= "r" then color ntp+2,255,0,0
 if cole$= "v" then color ntp+2,0,255,0
 if cole$= "b" then color ntp+2,0,200,255
 width ntp+2,26*coef:height ntp+2,9*coef
 left ntp+2,(width(ntp+1)-width(ntp+2))/2
 alpha ntp+3:parent ntp+3,ntp+2:full_space ntp+3
 panel ntp+4 :parent ntp+4,ntp+1:color ntp+4,206,206,206
 left ntp+4,width(ntp+1)-width(ntp+4)/2
 width ntp+4,26*coef:height ntp+4,26*coef
 left ntp+4,(width(ntp+1)-width(ntp+4))/2
 htop=(height(ntp+1)-(height(ntp+2)+height(ntp+4)))/3
 top ntp+2, htop:top ntp+4, htop+top(ntp+2)+height(ntp+2)
 if bv$="b"
    button ntp+5 :parent ntp+5,ntp+4:hint ntp+5,ntp+5
 else
    panel ntp+5 :parent ntp+5,ntp+4:hint ntp+5,ntp+5
    if colv$="r"
       color ntp+5,113,41,17:end_if
    if colv$="v"
       color ntp+5,39,99,37:end_if
    if colv$="b"
       color ntp+5,39,99,255:end_if
 end_if
 width ntp+5,22*coef:height ntp+5,22*coef
 top ntp+5,(height(ntp+4)-height(ntp+5))/2
 left ntp+5,(width(ntp+4)-width(ntp+5))/2
 font_size ntp+3,fz*coef : caption ntp+3,txt$
end_sub
' =============================
sub affichtxt(nxt,par,tpt,ltt,fsize,txt$)
 container nxt:parent nxt,par:top nxt,tpt:left nxt,ltt
 Alpha nxt+1:parent nxt+1,nxt:top nxt+1,10:left nxt+1,10
 font_bold 1:font_size 1,fsize
 width nxt+1,text_width(txt$,1)
 width nxt,width(nxt+1)+20
 font_bold nxt+1:font_size nxt+1,fsize
 caption nxt+1,txt$
 height nxt,height(nxt+1)+20
end_sub
' ============
sub button_container(nbc,par,tpc,ltc,txt$)
 container nbc:parent nbc,par:top nbc,tpc:left nbc, ltc
 caption nbc ,txt$
 button nbc+1:parent nbc+1,nbc:top nbc+1,30:left nbc+1,15
 width nbc+1,30:hint nbc+1,nbc+1
 width nbc,width(nbc+1)+30
 height nbc,height(nbc+1)+40
end_sub
' ======================
sub voyant_automate(ntp,par,ttp,ltp,txt$,etat)
 container ntp:parent ntp,par:top ntp,ttp:left ntp,ltp
 width ntp,80-20: height ntp,133-50
 font_size ntp,14:caption ntp,txt$
 alpha ntp+1:parent ntp+1,ntp:top ntp+1,48-20:left ntp+1,7
 width ntp+1,64-20: height ntp+1,44:color ntp+1,0,0,0
 progress_bar  ntp+2:parent ntp+2,ntp:top ntp+2,52-20:left ntp+2,11
 width ntp+2,56-20: height ntp+2,36:min ntp+2,0:max ntp+2,1
 hint ntp+2,ntp+2
 if etat=0
    position ntp+2,0
 else
    position ntp+2,1
 end_if
 if com_ok =1:position 32,1:end_if
end_sub
' =============
sp_form_help:
 form 200: hide 200:border_hide 200
 width 200,550:height 200,400
 top 200,(screen_y-height(200))/2 :left 200,(screen_x-width(200))/2
 memo 210:parent 210,200
 color 210,250,150,50
 font_bold 210:font_size 210,10
 full_space 210
 inactive 210
 item_add 210,""
 item_add 210,"   AIDE "
 item_add 210,""
 item_add 210,"   Avec  la DLL  '' IO_Acces_Com '' trouvée sur le site"
 item_add 210,"   ''automatepc''que Maître Klaus  nous a  brillamment  modifié"
 item_add 210,"   Pamoramic dialogue par le port série virtuel"
 item_add 210,"   avec une carte électronique   en  envoyant et recevant"
 item_add 210,"   des codes en  caractère ''ASCII''"
 item_add 210,"   voici un exemple d'un  terminal qui affiche  la courbe de tension  "
 item_add 210,"   d'une entree analogique d'une carte électronique  "
 item_add 210,"    "
 item_add 210,"    le terminal et écrit en Panoramic"
 item_add 210,"   la carte électronique programmable et une arduino uno"
 item_add 210,"   "
 item_add 210,"   ce n'est  pas un  oscilloscope"
 item_add 210,"   "
 item_add 210,"   avec Maître Google les articles sur les cartes arduinos"
 item_add 210,"   sont légions "
 item_add 210,"   "
 item_add 210,"  les boutons sont occultés pendant la scrutation"
 item_add 210,"     "
 item_add 210,"   Arrêt de la scrutation par la touche Echap "
 item_add 210," "
 item_add 210,"                                Double click pour Quitter"
return





Code Arduino:
int mesure=0;

//..................................
void setup()   { 
   Serial.begin(115200);
 }
//..................................
void loop(){
 if (Serial.available()!=0){
  module_reception();}
 }
//..................................
void emission(){
  mesure=analogRead(0);
  Serial.print(mesure,DEC);
   Serial.println("%");
  delay(10);
}
//..................................
void module_reception(){

  while (Serial.available()) {
    char readChar = (char)Serial.read();
     if (readChar == 'e'){emission();}
  }
}  
//..................................


Aucun commentaire:

Enregistrer un commentaire