FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC

Développement d'applications avec le langage Panoramic
 
AccueilAccueil  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  MembresMembres  Connexion  
Derniers sujets
» Gestion d'un système client-serveur.
Domotique avec Panoramic, Terminal RS232 Emptypar Klaus Aujourd'hui à 1:15

» item_index(résolu)
Domotique avec Panoramic, Terminal RS232 Emptypar jjn4 Mar 14 Mai 2024 - 19:38

» Bataille terrestre
Domotique avec Panoramic, Terminal RS232 Emptypar jjn4 Lun 13 Mai 2024 - 15:01

» SineCube
Domotique avec Panoramic, Terminal RS232 Emptypar Marc Sam 11 Mai 2024 - 12:38

» Editeur EliP 6 : Le Tiny éditeur avec 25 onglets de travail
Domotique avec Panoramic, Terminal RS232 Emptypar Marc Sam 11 Mai 2024 - 12:22

» Philharmusique
Domotique avec Panoramic, Terminal RS232 Emptypar jjn4 Ven 10 Mai 2024 - 13:58

» PANORAMIC V 1
Domotique avec Panoramic, Terminal RS232 Emptypar papydall Jeu 9 Mai 2024 - 3:22

» select intégrés [résolu]
Domotique avec Panoramic, Terminal RS232 Emptypar jjn4 Mer 8 Mai 2024 - 17:00

» number_mouse_up
Domotique avec Panoramic, Terminal RS232 Emptypar jjn4 Mer 8 Mai 2024 - 11:59

» Aide de PANORAMIC
Domotique avec Panoramic, Terminal RS232 Emptypar jjn4 Mer 8 Mai 2024 - 11:16

» trop de fichiers en cours
Domotique avec Panoramic, Terminal RS232 Emptypar lepetitmarocain Mer 8 Mai 2024 - 10:43

» Je teste PANORAMIC V 1 beta 1
Domotique avec Panoramic, Terminal RS232 Emptypar papydall Mer 8 Mai 2024 - 4:17

» bouton dans autre form que 0(résolu)
Domotique avec Panoramic, Terminal RS232 Emptypar leclode Lun 6 Mai 2024 - 13:59

» KGF_dll - nouvelles versions
Domotique avec Panoramic, Terminal RS232 Emptypar Klaus Lun 6 Mai 2024 - 11:41

» @Jack
Domotique avec Panoramic, Terminal RS232 Emptypar Jack Mar 30 Avr 2024 - 20:40

Navigation
 Portail
 Index
 Membres
 Profil
 FAQ
 Rechercher
Rechercher
 
 

Résultats par :
 
Rechercher Recherche avancée
Mai 2024
LunMarMerJeuVenSamDim
  12345
6789101112
13141516171819
20212223242526
2728293031  
CalendrierCalendrier
Le Deal du moment :
Bon plan achat en duo : 2ème robot cuiseur ...
Voir le deal
600 €

 

 Domotique avec Panoramic, Terminal RS232

Aller en bas 
AuteurMessage
Marc

Marc


Nombre de messages : 2397
Age : 63
Localisation : TOURS (37)
Date d'inscription : 17/03/2014

Domotique avec Panoramic, Terminal RS232 Empty
MessageSujet: Domotique avec Panoramic, Terminal RS232   Domotique avec Panoramic, Terminal RS232 EmptyJeu 10 Juin 2021 - 20:40

Bonjour à tous !

Cousin de l’interface de communication RS485/Modbus que j’ai publié >>ici<<, ce nouvel utilitaire permet de tester la communication sur un port COM série RS232.
Pour en savoir plus sur le port série, n’hésitez pas à consulter l’article réalisé par Jack : https://e-nautia.com/karma/disk?p=9756297


Domotique avec Panoramic, Terminal RS232 Rs232_10


Ce programme se compose de cinq zones :

- Port Com : pour saisir les caractéristiques techniques de la liaison à établir.

- Format : pour informer le programme si votre saisie est en ASCII ou en hexadécimal.

- Suffixe : permet d’ajouter une terminaison au message que l’on souhaite envoyer.

- La zone de saisie du message avec son bouton Envoyer.

- La zone de contrôle du trafic entrant et sortant.

Code:
' Terminal de communication RS232
' Marc - juin 2021 - https://panoramic.1fr1.net/
dim portCom%(255), baudrate%(12), nbBits%(4), parity%(3), bitstop(3)
dim indexPortCom%, indexBaudRate%, indexNbBits%, indexParity%, indexBitStop%
dim comN%(255)
dim etatPort%, debug%
dim repertoire$

label enregistrer, choixPortCom, choixBaudrate, choixNbBits, choixParity, choixBitstop
label autoDetect, ouvrirFermerPort, envoyerTrame, reception, clearEdit21, redim0

data 110,300,600,1200,2400,4800,9600,14400,19200,38400,57600,115200
data 5,6,7,8
data 0,1,2
data 1,1.5,2


debug% = 0

initConstantes()
interfaceUtilisateur()

if debug% = 1
    form 999
    print_target_is 999
end_if

end


ouvrirFermerPort:
     if etatPort% = 1
         etatPort% = 0
         color 14,255,0,0
         serial_close 50
         active 2
         active 4
         active 6
         active 8
         active 10
         active 12
         active 13
         inactive 22
         caption 14,"Port COM" + chr$(13) + "fermé"
     else
         if serial_port_exists(portCom%(indexPortCom%)) = 0
              if message_error_ok("Le port COM" + str$(portCom%(indexPortCom%)) + " n'est pas disponible !") < 2
                  return
              end_if
         end_if
         etatPort% = 1
         if debug% = 1
             cls
             print "port COM: " + str$(portCom%(indexPortCom%))
             print "BaudRate: " + str$(baudRate%(indexBaudRate%))
             print "Nb Bits: " + str$(nbBits%(indexNbBits%))
             print "Parity: " + str$(parity%(indexParity%))
             print "Bits Stop: " + str$(bitStop(indexBitStop%))
         end_if
         inactive 2
         inactive 4
         inactive 6
         inactive 8
         inactive 10
         inactive 12
         inactive 13
         active 22
         serial_port 50,portCom%(indexPortCom%)
         serial_baudrate 50,baudRate%(indexBaudRate%)
         serial_databits 50,nbBits%(indexNbBits%)
         serial_parity 50,parity%(indexParity%)
         serial_stopbits 50,bitStop(indexBitStop%)
         color 14,0,255,0
         caption 14,"Port COM" + chr$(13) + "ouvert"
         serial_open 50
         on_receive 50,reception
     end_if
return


sub interfaceUtilisateur()
    width 0,width(0) - width_client(0) + 570
    height 0,height(0) - height_client(0) + 411
    top 0,(screen_y - height(0)) / 2
    left 0,(screen_x - width(0)) / 2
    caption 0,"PANORAMIC Terminal RS232"
    on_resize 0,redim0
    application_title "PANORAMIC Terminal RS232"
    modulePortCom()
    chargerFichierPreferences()
    moduleSaisieTrame()
    moduleAffichageVariable()
    logo()
end_sub

sub moduleSaisieTrame()
    container 20
    top 20,90
    left 20,10
    width 20,550
    height 20,310
    caption 20," Ligne de commande RS232 "
        
    edit 21
    parent 21,20
    top 21,81
    left 21,15
    width 21,455
    font_size 21,10
    font_italic 21
    font_color 21,127,127,127
    text 21,"Tapez ici votre messsage à envoyer."
    on_click 21,clearEdit21

    button 22
    parent 22,20
    top 22,80
    left 22,483
    width 22,52
    height 22,23
    caption 22,"Envoyer"
    on_click 22,envoyerTrame
    inactive 22
    
    memo 23
    parent 23,20
    top 23,130
    width 23,520
    left 23,15
    height 23,165
    bar_vertical 23
    font_size 23,10
    
    alpha 25
    parent 25,20
    top 25,116
    left 25,18
    caption 25,"Trafic port série :"
    
    container_option 26
    parent 26,20
    top 26,20
    left 26,16
    height 26,40
    width 26,150
    caption 26," Format : "

    option 27
    parent 27,26
    top 27,15
    left 27,20
    width 27,50
    caption 27,"ASCII"
    mark_on 27

    option 28
    parent 28,26
    top 28,15
    left 28,90
    width 28,50
    caption 28,"Hexa"

    container_option 29
    parent 29,20
    top 29,20
    left 29,180
    height 29,40
    width 29,290
    caption 29," Suffixe : "

    option 30
    parent 30,29
    top 30,15
    left 30,20
    width 3,50
    caption 30,"Sans"
    
    option 31
    parent 31,29
    top 31,15
    left 31,84
    caption 31,"CR"
    
    option 32
    parent 32,29
    top 32,15
    left 32,148
    width 32,50
    caption 32,"LF"
    
    option 33
    parent 33,29
    top 33,15
    left 33,211
    width 33,60
    caption 33,"CR+ LF"
    mark_on 33
end_sub


sub moduleAffichageVariable()
    panel 40
    top 40,150
    left 40,165
    width 40,260
    height 40,160

    container 45
    parent 45,40
    width 45,240
    height 45,140
    top 45,10
    left 45,10
    caption 45," Auto Detect "
    
    alpha 41
    parent 41,45
    left 41,45
    top 41,20

    alpha 42
    parent 42,45
    left 42,71
    top 42,49

    alpha 43
    parent 43,45
    left 43,40
    top 43,67
    
    alpha 44
    parent 44,45
    top 44,105
    left 44,96
    
    hide 40
end_sub


envoyerTrame:
    inactive 22
    traitementTrame()
    active 22
    set_focus 21
return


sub traitementTrame()
    dim_local crc, crc16$, i%, j%, c$, p%, pFort$, pFaible$, t$, tr$, trameOut$, trameSerie$, trameMemo$
    tr$ = text$(21)

    if checked(28) = 1 :' Choix Hexadécimal
        ' suppression des espaces dans la trame hexadécimale
        for p% = 1 to len(tr$)
            c$ = mid$(tr$,p%,1)
            if c$ <> " "
                t$ = t$ + c$
            end_if
        next p%
        ' vérification de la trame hexadécimale
        if mod(len(t$),2) = 0
            for p% = 1 to len(t$)
                c$ = mid$(t$,p%,1)
                if instr("0123456789ABCDEFabcdef",c$) = 0
                    message "Le caractère ''" + c$ + "'' : n'est pas une valeur hexadécimale !"
                    exit_sub
                end_if
            next p%
        else
            message "Le nombre de charactères doit être pair."
            exit_sub
        end_if
 
        trameSerie$ = upper$(t$)

        ' ajout suffixe
        if checked(31) = 1
            trameSerie$ = trameSerie$ + "0D"
        end_if
        if checked(32) = 1
            trameSerie$ = trameSerie$ + "0A"
        end_if    
        if checked(33) = 1
            trameSerie$ = trameSerie$ + "0D0A"
        end_if    

        ' affichage dans le memo de la trame complete envoyée
        trameMemo$ = ""
        p% = 1
        for i% = 1 to len(trameSerie$) step 2
            c$ = mid$(trameSerie$,p%,2)
            trameMemo$ = trameMemo$ + c$ + " "
            p% = p% + 2
        next i%
        item_add 23,"Emis : " + trameMemo$

        ' mise en forme pour transfert via le port COM
        trameOut$ = ""
        p% = 1
        for i% = 1 to len(trameSerie$) step 2
            c$ = mid$(trameSerie$,p%,2)
            trameOut$ = trameOut$ + chr$(hex(c$))
            p% = p% + 2
        next i%    
    else
        trameOut$ = tr$

        ' ajout suffixe
        if checked(31) = 1
            trameOut$ = trameOut$ + chr$(13)
        end_if
        if checked(32) = 1
            trameOut$ = trameOut$ + chr$(10)
        end_if    
        if checked(33) = 1
            trameOut$ = trameOut$ + chr$(13) + chr$(10)
        end_if    

        item_add 23,"Emis : " + trameOut$
    end_if
    
    if etatPort% = 1
        serial_write 50,trameOut$
    end_if
end_sub


reception:
    TrameReception()
return


sub TrameReception()
    dim_local trameRecept$, trameReceptHexa$, i%, char$, c%, h$
    
    trameRecept$ = serial_read$(50)

    if checked(28) = 1 :' format hémadécimal
        for i% = 1 to len(trameRecept$)
            char$ = mid$(trameRecept$,i%,1)
            c% = asc(char$)
            h$ = hex$(c%)
            if len(h$) = 1
                h$ = "0" + h$
            end_if
            trameReceptHexa$ = trameReceptHexa$ + h$ + " "
        next i%
        trameRecept$ = trameReceptHexa$
    end_if
    
    item_add 23,"Reçu : " + trameRecept$
end_sub


clearEdit21:
    off_click 21
    text 21,""
    font_italic_off 21
    font_color 21,0,0,0
return


sub modulePortCom()
    dim_local n%
    container 1
    top 1,10
    left 1,10
    width 1,550
    height 1,75
    caption 1," Port COM "

    button 2
    parent 2,1
    top 2,30
    left 2,10
    width 2,35
    height 2,20
    caption 2,"Auto"
    on_click 2,autoDetect

    alpha 3
    parent 3,1
    top 3,15
    left 3,58
    caption 3,"Port"
    
    combo 4
    parent 4,1
    width 4,75
    top 4,30
    left 4,55
    for n% = 1 to 255
        item_add 4,"COM" + str$(n%)
    next n%
    on_change 4,choixPortCom
    
    alpha 5
    parent 5,1
    top 5,15
    left 5,141
    caption 5,"BaudRate"
    
    combo 6
    parent 6,1
    top 6,30
    left 6,138
    width 6,75
    item_add 6,"110"
    item_add 6,"300"
    item_add 6,"600"
    item_add 6,"1200"
    item_add 6,"2400"
    item_add 6,"4800"
    item_add 6,"9600"
    item_add 6,"14400"
    item_add 6,"19200"
    item_add 6,"38400"
    item_add 6,"57600"
    item_add 6,"115200"
    on_change 6,choixBaudRate
    
    alpha 7
    parent 7,1
    top 7,15
    left 7,223
    caption 7,"Bits"
    
    combo 8
    parent 8,1
    top 8,30
    left 8,220
    width 8,40
    item_add 8,"5"
    item_add 8,"6"
    item_add 8,"7"
    item_add 8,"8"
    on_change 8,choixNbBits
    
    alpha 9
    parent 9,1
    top 9,15
    left 9,271
    caption 9,"Parité"
    
    combo 10
    parent 10,1
    top 10,30
    left 10,268
    width 10,75
    item_add 10,"Aucune"
    item_add 10,"Impaire"
    item_add 10,"Paire"
    on_change 10,choixParity
    
    alpha 11
    parent 11,1
    top 11,15
    left 11,353
    caption 11,"Stop Bits"
    
    combo 12
    parent 12,1
    top 12,30
    left 12,350
    width 12,50
    item_add 12,"1"
    item_add 12,"1.5"
    item_add 12,"2"
    on_change 12,choixBitStop
    
    button 13
    parent 13,1
    top 13,30
    left 13,410
    width 13,20
    height 13,20
    caption 13,"M"
    hint 13,"Enregistrer les paramètres"
    on_click 13,enregistrer
    
    button_picture 14
    parent 14,1
    left 14,445
    top 14,20
    width 14,90
    height 14,40
    color 14,255,0,0
    caption 14,"Port COM" + chr$(13) + "Fermé"
    on_click 14,ouvrirFermerPort
end_sub


sub chargerFichierPreferences()
    if file_exists(repertoire$ + "pmrs.cfg") = 1
        file_open_read 31,repertoire$ + "pmrs.cfg"
            IndexPortCom% = file_readln$(31)
            indexBaudrate% = file_readln$(31)
            indexNbBits% = file_readln$(31)
            indexParity% = file_readln$(31)
            indexBitStop% = file_readln$(31)
        file_close 31  
    else
        ' valeurs par défaut
        IndexPortCom% = 1   :' COM1
        indexBaudrate% = 7  :' 9600 bauds
        indexNbBits% = 4    :' 8 bits
        indexParity% = 1    :' Aucune
        indexBitstop% = 1   :' 1 bit
    end_if
    
    item_select 4,indexPortCom%
    item_select 6,indexBaudrate%
    item_select 8,indexNbBits%
    item_select 10,indexParity%
    item_select 12,indexBitStop%
end_sub


choixPortCom:
    indexPortCom% = item_index(4)
return


choixBaudrate:
    indexBaudRate% = item_index(6)
return


choixNbBits:
    indexNbBits% = item_index(8)
return


choixParity:
    indexParity% = item_index(10)
return


choixBitstop:
    indexbitStop% = item_index(12)
return


sub initConstantes()
    dim_local n%
    repertoire$ = dir_current$ + ""
    serial 50
    
    for n% = 1 to 255
        portCom%(n%) = n%
    next n%

    for n% = 1 to 12
        read baudRate%(n%)
    next n%
    
    for n% = 1 to 4
        read nbBits%(n%)
    next n%
    
    for n% = 1 to 3
        read parity%(n%)
    next n%
    
    for n% = 1 to 3
        read bitStop(n%)
    next n%        
end_sub


autoDetect:
    scanPortCom()
return


sub scanPortCom()
    dim_local key%, n%, pass%, quitter%
    inactive 0
    pass% = 1
    indexPortCom% = 0
    text 4,""

    caption 41,"Initialisation en cours..."
    left 41,64
    top 41,45

    caption 42," Patientez SVP !"
    left 42,81
    top 42,90
 
    caption 43,""
    caption 44,""
    show 40
    display

    ' cartographie des ports COM existants
    for n% = 1 to 255
        comN%(n%) = 0
        if serial_port_exists(n%) = 1
            comN%(n%) = 1
        end_if
    next n%
    
    caption 41,"Connectez votre clé USB/RS232 !"
    left 41,40
    top 41,30

    caption 42,"Recherche en cours..."
    left 42,71
    top 42,55

    caption 43,""
    left 43,40
    top 43,80
    caption 43,"Interrogation du port COM1/255"

    caption 44,"Passe " + str$(pass%) + "/5"
    top 44,105
    left 44,96
    display

    ' recherche modification d'un port com
    while pass% < 6
        for n% = 1 to 255
            caption 43,"Interrogation du port COM" + str$(n%) + "/255"
            display
            pause 20
            if serial_port_exists(n%) = 1
                if comN%(n%) = 0
                    comN%(n%) = 1
                    indexPortCom% = n%
                    text 4,"COM" + STR$(n%)
                    item_select 4,indexPortCom%
                    hide 40
                    active 0
                    exit_while
                end_if
            else
                if comN%(n%) = 1
                    comN%(n%) = 0
                end_if    
            end_if
        next n%
        pause 20
        pass% = pass% + 1
        caption 44,"Passe " + str$(pass%) + "/5"
        display
        
        ' après 5 scans sans succès, sortie du mode auto
        if pass% = 6
           hide 40
           message "Interface USB/RS232 non trouvée !"
           active 0
           exit_while
        end_if    

    end_while
end_sub

sub logo()
    picture 35
    parent 35,20
    width 35,42
    height 35,42
    top 35,21
    left 35,488
    color 35,255,255,255
    2d_target_is 35
    ' cadre
    2d_pen_color 160,160,160
    2d_rectangle 0,0,42,42    
    ' cercles rouges
    2d_pen_width 2
    2d_pen_color 255,0,0
    2d_circle 21,21,17
    2d_circle 21,21,13
    ' lettre P
    2d_pen_width 1
    2d_pen_color 35,35,145
    2d_fill_color 35,35,145
    2d_rectangle 17,15,20,28
    2d_line 15,15,26,15
    2d_line 16,16,27,16
    2d_line 23,17,28,17
    2d_line 24,18,28,18
    2d_line 24,19,28,19
    2d_line 23,20,28,20
    2d_line 20,21,27,21
    2d_line 20,22,26,22
    2d_line 16,26,21,26
    2d_line 15,27,23,27  
end_sub


redim0:
    width 0,width(0) - width_client(0) + 570
    height 0,height(0) - height_client(0) + 411
return


enregistrer:
    file_open_write 30,repertoire$ + "pmrs.cfg"
        file_writeln 30,indexPortCom%
        file_writeln 30,indexBaudrate%
        file_writeln 30,indexNbBits%
        file_writeln 30,indexParity%
        file_writeln 30,indexBitStop%
    file_close 30
return

Le code-source et le mode d'emploi sont téléchargeables depuis mon WebDAV.

N’hésitez pas à poser toute question !

Pour finir, voici une copie d’écran du programme en action.
Le port COM est configuré à 9600 bauds, 8 bits, sans parité et 1 bit de stop.
J’envoie la commande « AT+VERSION » en ASCII sans suffixe. Mon périphérique, connecté au port RS232, me renvoie « DX_smartv2.0 ».

Domotique avec Panoramic, Terminal RS232 Rs232_11


Bonne soirée à tous !

Yannick aime ce message

Revenir en haut Aller en bas
 
Domotique avec Panoramic, Terminal RS232
Revenir en haut 
Page 1 sur 1
 Sujets similaires
-
» Domotique avec Panoramic : Interface RS232 TTL
» Domotique avec Panoramic. RS485, Modbus, RTU
» Domotique avec Panoramic : transmission Bluetooth.
» Domotique avec Panoramic : Code PIN et Id du HC-06 Bluetooth
» Domotique et électronique : Panoramic et l’Arduino DUE.

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
FORUM DE DISCUSSION SUR LE LANGAGE PANORAMIC :: PANORAMIC :: Vos sources, vos utilitaires à partager-
Sauter vers: