sevki / Posts

Repo of my posts
http://fistfulofbytes.com/
MIT License
2 stars 2 forks source link

OPCAutomation.dll - how to attache it to project in Visual C# #2

Closed barosz closed 10 years ago

barosz commented 10 years ago

I have got one question - how to add OPCAutomation.dll in Microsoft Visual C# ? I tried to do it by adding refenece to project but it is not working (I am receiving an error).

sevki commented 10 years ago

what error are you getting?

barosz commented 10 years ago

Microsoft Visual C# 2010 Express

A reference to 'C:\WINDOWS\system32\OPCDAAuto.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

OK

sevki commented 10 years ago

If I remember correctly that's the dll that's distributed by OPC foundation and it's definitely not the dll I'm referring to anyhow -S

On Tue, Jan 21, 2014 at 8:17 AM, barosz notifications@github.com wrote:


Microsoft Visual C# 2010 Express

A reference to 'C:\WINDOWS\system32\OPCDAAuto.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

OK


Reply to this email directly or view it on GitHub: https://github.com/sevki/Posts/issues/2#issuecomment-32824144

barosz commented 10 years ago

Yes you are correct that's dll distributed by OPC foundation. I have just thought that you use from the source you may rely (not from unknown source).

sevki commented 10 years ago

I think you have a better chance of getting something to work if you actually try to find the dll mentioned.

Haris11011 commented 4 years ago

Hi sevki, Hope u r doing well.

As I know much little about computer programming, so I am facing problem in trying to get values from local OPC server (Kepware), Em using OPCautomation.dll and your sample code as below.,

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using OPCAutomation;

namespace WindowsFormsApplication8 { public partial class Form1 : Form {

    OPCServer ObjOPCServer;
    OPCGroups ObjOPCGroups;
    OPCGroup ObjOPCGroup;
    string OPCServerName;

    public Form1()
    {
        InitializeComponent();
        try
        {
            InitializeComponent();
            OPCServerName = "kepware.KEPServerEX.V6";
            ObjOPCServer = new OPCServer();
            ObjOPCServer.Connect(OPCServerName, "");
            ObjOPCGroups = ObjOPCServer.OPCGroups;
            ObjOPCGroup = ObjOPCGroups.Add("FX.TrialG1");
            ObjOPCGroup.OPCItems.AddItem("FX.TrialG1.Encoder",1);
            ObjOPCGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(ObjOPCGroup_DataChange);

            ObjOPCGroup.UpdateRate = 10;
            ObjOPCGroup.IsActive = true;
            ObjOPCGroup.IsSubscribed = true;
        }
        catch (Exception e)
        {
            MessageBox.Show(e.ToString());
        }

    }

    private void ObjOPCGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
    {

        for (int i = 1; i <= NumItems; i++)
        {
            if ((Convert.ToInt32(ClientHandles.GetValue(i)) == 1))
            {

                textBox1.Text = ItemValues.GetValue(i).ToString();
            }
        }
    }

    private void Form1_Load(object sender, EventArgs e)
   {

   }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

}

}

After debugging and connected OPC server, C # application is running with out error but it is not getting/showing any value in text box. . However if i run application in disconnected mode of OPC server, it gives an error after application start,error showed in attached picture.

OPC off condition

Thanks, Haris