gee'K'iran
gee'K'iran

Reputation: 441

Subscribe to OPC server data_changed event from windows service

I want to read the item value from opc server by subscribing to OpcGroup_DataChanged event. I am able to do it through a windows form client. But when I am trying to do the same from windows service, the event is not firing. Can some body throw some light? Below is my implementation:

    OPCItemResult[] rslt;
        rtc = OpcGrp.AddItems(iDefs, out rslt);
        if (HRESULTS.Failed(rtc))
            return rtc;

        ItemHandles = new int[rslt.Length];
        errors = new int[iDefs.Length];
        for (int i = 0; i < iDefs.Length; ++i)
        {
            ItemHandles[i] = rslt[i].HandleServer;
            errors[i] = rslt[i].Error;
        }


        // data changed callback handler
        OpcGrp.DataChanged += new DataChangeEventHandler(OpcGrp_DataChanged);
        OpcGrp.AdviseIOPCDataCallback();
        this.EventLog.WriteEntry("No of items: "+rtc.ToString(), EventLogEntryType.Information);

The Event:

    protected void OpcGrp_DataChanged(object sender, DataChangeEventArgs e)
    {
        this.EventLog.WriteEntry("Data changed at server", EventLogEntryType.Information);

        string txt = "";
        foreach (OPCItemState rslt in e.sts)
        {
            txt += rslt.DataValue.ToString() + "\r\n";
        }
        this.EventLog.WriteEntry(txt, EventLogEntryType.Information);
    }

Upvotes: 0

Views: 1230

Answers (1)

Ken
Ken

Reputation: 457

This is probably a DCOM permissions issue. To confirm this, try running your client service in the same account that you run your windows forms application in (probably your log-in account). If that works, you'll need to setup your OPC server (or the defaults for DCOM) to allow the server to communicate with whatever account you want your client to run in.

Upvotes: 1

Related Questions