IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Visual Studio Discussion :

Récupération de données sur automate et envoi dans BDD Access


Sujet :

Visual Studio

  1. #1
    Inactif  
    Inscrit en
    Avril 2013
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Avril 2013
    Messages : 23
    Points : 10
    Points
    10
    Par défaut Récupération de données sur automate et envoi dans BDD Access
    Bonjour à tous !

    Voila je souhaite mettre en place une récupération de données sur automate Modicon M221 via VB.NET
    J'ai trouvé la bibliotheque EasyModbusTCP.dll que vous trouverez ici http://easymodbustcp.net/modbusclient-methods
    Je test mon programme grâce au simulateur d'automate présent dans SoMachine BASIC dont l'adresse IP est 127.0.0.1. Pas de problème pour la connexion cette phase se déroule bien.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    Imports EasyModbus 'Import the EasyModbus Namespacing
    Public Class Form1
        Private Sub Button1_Click() Handles Button1.Click
            'This subroutine will communicate using the EasyModbusTCP to the PLC
            'This will execute when the user clicks the button or at specific intervals from the Timer1
            Dim ComError = 0 'Set communication error flag to 0
            'Specify the IP Address and Port Number that we are connecting
            Dim ModbusClient As EasyModbus.ModbusClient = New EasyModbus.ModbusClient(TextBox1.Text, 502)
            Try
                ModbusClient.Connect() 'Connect to the PLC
            Catch ex As Exception 'What to do when an error occurs
                Label10.ForeColor = Color.Red
                Label10.Text = "Communication Error!"
                ComError = 1 'Set communication error flag to 1
            End Try
            If ComError = 0 Then 'Do the following when communication is OK
                MsgBox("CONNEXION REUSSIE")
                Label10.ForeColor = Color.Black
                Label10.Text = "Logging..."
                Dim Registers As Integer() 'Where to store the information
                Registers = ModbusClient.ReadInputRegisters(0, 9) 'Read three registers starting at the first one
                Label1.Text = Registers(0) 'Value of MHR1
                Label2.Text = Registers(1) 'Value of MHR2
                Label3.Text = Registers(2) 'Value of MHR3
                Debug.Print("Registre 0 = " & Registers(0))
                Debug.Print("Registre 1 = " & Registers(1))
                Debug.Print("Registre 2 = " & Registers(2))
                ModbusClient.Disconnect() 'Disconnect from the PLC
     
                'Log values into an Access Database
                'We will use a SQL instruction to insert a record into the table
                Try
                    Dim SQL As String 'SQL Command String
                    'Dim Data1, Data2 As Integer
                    Dim objCmd As New OleDb.OleDbCommand 'Command
                    'Connection String to the Access Database
                    Dim Con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\jacja\Documents\test.accdb")
                    Debug.Print("coucou1")
                    'SQL Statement - All values must be set for the table
                    SQL = "INSERT INTO Table1 VALUES ('" & 12 & "', '" & 12 & "')" ' '" & Data1 & "', '" & Data2 & "')"
                    Con.Open() 'Open the database connection
                    Debug.Print("coucou2")
                    objCmd = New OleDb.OleDbCommand(SQL, Con) 'Set the command
                    Debug.Print("coucou3")
                    objCmd.ExecuteNonQuery() 'Execute the SQL command
                    Debug.Print("coucou4")
                    Con.Close() 'Close the database connection
                    Debug.Print("coucou5")
                Catch ex As Exception 'What to do when an error occurs
                    Label10.ForeColor = Color.Red
                    Label10.Text = "Database Error!"
                End Try
            End If
        End Sub
    Cependant, je ne sais pas comment utilisée la fonction int[] ReadInputRegisters(int startingAddress, int quantity) car celle-ci ne semble par réellement bien marcher, quand je clique sur une entrée IN du simulateur mes valeurs récupéré ne change pas... L'adresse du registre à entrer est-elle bien 0 ?

    Autre problème l'exportation des données vers access...Une erreur survient et je ne comprend pas pourquoi. Voici ci-dessous les résultats du Debug :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\Users\jacja\Google Drive\Travail\Stages\BDD\Via Visual Studio\VB Program\Modbus TCP MSAccess Logging\Modbus TCP MSAccess Logging\bin\Debug\Modbus TCP MSAccess Logging.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_fr_b77a5c561934e089\mscorlib.resources.dll'. Module was built without symbols.
    The thread 0x2090 has exited with code 0 (0x0).
    The thread 0x261c has exited with code 0 (0x0).
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\Users\jacja\Google Drive\Travail\Stages\BDD\Via Visual Studio\VB Program\Modbus TCP MSAccess Logging\Modbus TCP MSAccess Logging\bin\Debug\Modbus TCP MSAccess Logging.exe'. Symbols loaded.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'. Cannot find or open the PDB file.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\Users\jacja\Google Drive\Travail\Stages\BDD\Via Visual Studio\VB Program\Modbus TCP MSAccess Logging\Modbus TCP MSAccess Logging\bin\Debug\EasyModbus.dll'. Cannot find or open the PDB file.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    Registre 0 = 0
    Registre 1 = 2304
    Registre 2 = 0
    coucou1
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'Modbus TCP MSAccess Logging.vshost.exe' (CLR v4.0.30319: Modbus TCP MSAccess Logging.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    coucou2
    coucou3
    Exception thrown: 'System.Data.OleDb.OleDbException' in System.Data.dll
    The thread 0x3168 has exited with code 0 (0x0).
    The thread 0x1f64 has exited with code 0 (0x0).
    The thread 0x2478 has exited with code 0 (0x0).
    The program '[5760] Modbus TCP MSAccess Logging.vshost.exe: Program Trace' has exited with code 0 (0x0).
    The program '[5760] Modbus TCP MSAccess Logging.vshost.exe' has exited with code 0 (0x0).
    Voilà merci d'avance pour vos réponses, jespère que vous pourrez m'aider.

  2. #2
    Inactif  
    Inscrit en
    Avril 2013
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Avril 2013
    Messages : 23
    Points : 10
    Points
    10
    Par défaut
    Bonjour, personne ne peut m'aider ?

    Merci.

  3. #3
    Expert confirmé Avatar de ed73170
    Homme Profil pro
    Développeur indépendant
    Inscrit en
    Mai 2009
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur indépendant

    Informations forums :
    Inscription : Mai 2009
    Messages : 765
    Points : 5 522
    Points
    5 522
    Par défaut
    Bonjour,

    Pour ton erreur, c'est ta requête SQL qui n'est pas bonne (ligne 40), et forcément ça plante quand tu essayes de l'exécuter (ligne 45). Affiche la valeur de la variable SQL et tu devrais comprendre assez rapidement ce qui ne va pas.

  4. #4
    Inactif  
    Inscrit en
    Avril 2013
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Avril 2013
    Messages : 23
    Points : 10
    Points
    10
    Par défaut
    Tout d'abord merci beaucoup de t'être penché sur mon problème =)

    J'ai changé ma variable SQL (ligne 40 ) selon le shéma de fonction que j'ai trouvé pour INSERT INTO :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SQL = "INSERT INTO Table1 VALUES (' 12 ', ' 12 ')"
    Mais la même erreur apparaît.

    Je ne comprend pas ce que tu veux dire par
    Affiche la valeur de la variable SQL
    car le programme me renvoi simplement ma chaîne de caractère INSERT INTO Table1 VALUES (' 12 ', ' 12 ')

    Encore merci pour ton aide.

  5. #5
    Expert confirmé Avatar de ed73170
    Homme Profil pro
    Développeur indépendant
    Inscrit en
    Mai 2009
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur indépendant

    Informations forums :
    Inscription : Mai 2009
    Messages : 765
    Points : 5 522
    Points
    5 522
    Par défaut
    Citation Envoyé par jacknido Voir le message
    J'ai changé ma variable SQL (ligne 40 ) selon le shéma de fonction que j'ai trouvé pour INSERT INTO : SQL = "INSERT INTO Table1 VALUES (' 12 ', ' 12 ')"
    Est-ce que la structure de ta table Table1 est compatible avec ta requête ? D'après ce que je vois, elle contient 2 colonnes de type texte, ou bien les 2 premières colonnes sont de type texte.

  6. #6
    Inactif  
    Inscrit en
    Avril 2013
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Avril 2013
    Messages : 23
    Points : 10
    Points
    10
    Par défaut
    Tu as entièrement raison ! Merciiii! Le problème venait effectivement de la non correspondance entre le nombre de colonnes de ma classe et le nombre de VALUES dans SQL !

    J'ai donc procédé en rajoutant le nom des colonnes où mettre mes VALUES : INSERT INTO table (nom_colonne_1, nom_colonne_2)
    VALUES ('valeur 1', 'valeur 2')


    L'exportation vers la BDD marche donc Merci !

    Le second problème est maintenant la récupération des données sur l'automate (enfin pour l'instant sur le simulateur de l'automate)... Quelqu'un connait-il la librairie EasyModbusTCP ? Une suggestion sur le pourquoi du comment ça ne marche pas ? =S

  7. #7
    Inactif  
    Inscrit en
    Avril 2013
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Avril 2013
    Messages : 23
    Points : 10
    Points
    10
    Par défaut
    Il y a-t-il une manipulation quelconque à faire sur les automates Schneider pour autoriser la communication modbus ? Un programme à insérer dans l'automate via Somachine basic ? Un technicien schneider m'a dit qu'ils étaient configuré en serveur modbus par défaut et qu'il n'y avait rien à ecrire sur l'automate qui devait répondre à une requette mosbus d'un client, mais je commence à mettre sa parole en doute... Comment je pourrais-je lire dans les registres si l'automate n'y ecrit rien auparavant ? ...

    Car j'ai tester la communication à l'aide du logiciel AVReporter Modbus Communication qui est (censé lire les différents registres sur les appareils équipés en communication Modbus) et une erreur survient.
    Le problème ne viendrait donc peut-être pas de mon code ?

    Merci de m'aider à éclaircir la situation.

  8. #8
    Inactif  
    Inscrit en
    Avril 2013
    Messages
    23
    Détails du profil
    Informations forums :
    Inscription : Avril 2013
    Messages : 23
    Points : 10
    Points
    10
    Par défaut
    Quelqu'un peut-il m'aider ? ...

Discussions similaires

  1. Récupération de donnée sur automate M221
    Par jacknido dans le forum Automation
    Réponses: 7
    Dernier message: 16/06/2016, 14h07
  2. Réponses: 3
    Dernier message: 18/04/2011, 13h43
  3. Récupération de donnée sur support altéré
    Par Invité dans le forum Périphériques
    Réponses: 8
    Dernier message: 05/07/2006, 11h28
  4. Récupération de données sur Disque Dur
    Par assomniak dans le forum Windows XP
    Réponses: 3
    Dernier message: 17/06/2006, 15h57
  5. récupération de données sur une disquette
    Par olilacta dans le forum Ordinateurs
    Réponses: 3
    Dernier message: 21/04/2006, 13h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo