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.
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 ?
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
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 :
Voilà merci d'avance pour vos réponses, jespère que vous pourrez m'aider.
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).
Partager