Précédent   Forum des professionnels en informatique > Systèmes > Autres systèmes > Automation
Automation Forum d'entraide sur l'automatisme, la robotique et l'informatique industrielle
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
Vieux 21/07/2009, 16h50   #1
Nouveau Membre du Club
 
Inscription : juillet 2009
Messages : 47
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 47
Points : 25
Points : 25
Par défaut connection OPC en c#

Bonjour, je suis actuellement en stage de fin d'étude, et je dois me connecter à un server OPC (utilisation .NET).
Pour cela je crée une factory ( namespace : Opc) et un server associé à cette factory ( namespace : Opc.Da).
Mais là, lors de la connexion au server, vient un problème, dont je ne vois pas l'origine.

message du trés cher Microsoft Visual C# 2005 :
Could not load file or assembly 'OpcRcw.Dx, Version=1.0.1.21, Culture=neutral, PublicKeyToken=9a40e993cbface53' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


La DLL est déjà référencée au projet.
Si quelqu'un peut m'expliquer ce que je dois faire ou me mettre sur la piste, qu'il n'hésite pas
Merci.
Bonne journée
gouroupasdebol est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/07/2009, 16h56   #2
Nouveau Membre du Club
 
Inscription : juillet 2009
Messages : 47
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 47
Points : 25
Points : 25
voici le code si ca peut aider :

Code :
1
2
3
4
5
6
Opc.URL url;
url = new Opc.URL("url de la machine");
Opc.ConnectData connectData = new Opc.ConnectData(new System.Net.NetworkCredential());
OpcCom.Factory fact = new OpcCom.Factory();
Opc.Server server = new Opc.Server(fact, null);
server.Connect();

Dernière modification par bbil ; 21/07/2009 à 21h19. Motif: balise de code
gouroupasdebol est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/07/2009, 17h00   #3
Nouveau Membre du Club
 
Inscription : juillet 2009
Messages : 47
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 47
Points : 25
Points : 25
En passant par Opc.Factory je me retrouve avec le problème :
Trying to create a proxy to an unbound type.
Celui-ci est toujours lors de la tentative de connexion.

Aprés, je configure peut-être mal la factory :
Opc.Factory fact = new Opc.Factory(typeof(Opc.Server), true);

Merci pour toute aide
gouroupasdebol est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/07/2009, 09h49   #4
Nouveau Membre du Club
 
Inscription : juillet 2009
Messages : 47
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 47
Points : 25
Points : 25
Bonjour j'ai changé completement de bibliothéque utilisation de OpcRcw.
La connection au serveur se fait bien, tout comme la création de groupe et d'item mais maintenant c'est la lecture qui pose probléme.

Code :
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Collections;
using OpcRcw.Da;
using OpcRcw.Comn;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
    class Conection
    {
        private IOPCServer opcServer			= null;
	private IOPCCommon opcCommon			= null;
  
        bool opcServer_connected = false;
        String progID = "identifiantServer";
        

        // au niveau des groupes
        IOPCGroupStateMgt opcGroupStateMgt;
        int opcServer_LocaleID;
        int groupServerHandle;
        int groupUpdateRate;

        // au niveau des items  
        IOPCItemMgt opcItem;
        OPCITEMDEF[] itemDefs;
        int numberOfItems = 0;

        // lecture
        IOPCAsyncIO2 opcRead = null;
        int[] tabPtrServer;

        // transaction
        int idTransaction = 0;


        public Conection()
        {
            if (!opcServer_connected)
            {
                Type typeOpcServer = Type.GetTypeFromProgID(progID);
                opcServer = (IOPCServer)Activator.CreateInstance(typeOpcServer);
                opcCommon = (IOPCCommon)opcServer;
                opcCommon.GetLocaleID(out opcServer_LocaleID);
                opcServer_connected = true;
                newGroup();
                newItem();

            }
        }
        
        public void newGroup()
        {
            IntPtr pTimeBias = IntPtr.Zero;
            IntPtr pDeadband = IntPtr.Zero;
            Guid id = typeof(IOPCGroupStateMgt).GUID;
            Object objGroup = null;

            opcServer.AddGroup("toto",1, 100, 1, pTimeBias, pDeadband, opcServer_LocaleID, out groupServerHandle, out groupUpdateRate, ref id, out objGroup);
            opcGroupStateMgt = (IOPCGroupStateMgt)objGroup;
        }

        public void newItem()
        {
            int i = 0;
            Guid id = Guid.Empty;
            numberOfItems = 2;
            int[] itmsClntHndl = new int[numberOfItems];
            int[] itmsSrvHndl = new int[numberOfItems];
            bool[] itmsActive = new bool[numberOfItems];
            string[] itmsID = new string[numberOfItems];
            short[] itmsType = new short[numberOfItems];
        
            
            itemDefs = new OPCITEMDEF[numberOfItems];
            IntPtr ppResults = IntPtr.Zero;
            IntPtr ppErrors = IntPtr.Zero;
        

            opcItem = (IOPCItemMgt)opcGroupStateMgt;
            tabPtrServer = new int[numberOfItems];

            while (i < numberOfItems)
            {
                itemDefs[i].bActive = 1;
                itemDefs[i].dwBlobSize = 0;
                itemDefs[i].hClient = i+1;
                itemDefs[i].pBlob = IntPtr.Zero;
                itemDefs[i].szAccessPath = "nomDelAlias";
                
                itemDefs[i].vtRequestedDataType = Convert.ToInt16(VarEnum.VT_BSTR);
                tabPtrServer[i] = itemDefs[i].hClient;
                i++;
            }
            itemDefs[0].szItemID = "identifiantDeVariable0";
            itemDefs[1].szItemID = "identifiantDeVariable1";
            
            opcItem.AddItems(numberOfItems, itemDefs, out ppResults, out ppErrors);
        }

        public String read()
        {
            String value;
            opcRead = (IOPCAsyncIO2)opcGroupStateMgt;
            int cancelId = 0;
            IntPtr error = IntPtr.Zero;
           
                opcRead.Read(numberOfItems, tabPtrServer, idTransaction++, out cancelId, out error);
            return "value";
        }
    }
}
Au niveau de opcRead.read, une erreure se lance à l'éxécution :
Exception from HRESULT: 0x80040200

Le but de cette fonction étant de récupérer les valeurs des items du server.
Comment fait on pour récuperer les valeurs avec la fonction IOPCAsyncIO2.Read.

Merci pour toute aide
gouroupasdebol est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +1. Il est actuellement 19h01.


 
 
 
 
Partenaires

Hébergement Web