OPC-DA Disconnect issue|Classic OPC: DA, A&E, HDA, XML-DA, etc.|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
OPC-DA Disconnect issue
Avatar
Okur Cozer
New Member
Members
Forum Posts: 2
Member Since:
03/15/2018
sp_UserOfflineSmall Offline
1
03/15/2018 - 01:46
sp_Permalink sp_Print sp_EditHistory

When I connect to the Opc server (opc-da), a new client is created. But when I close the connection, the client number does not change. When I connect again, a new client is created.

Each new connection creates a new client. The number of clients is increasing because I can not close the clients.

How can I reduce the client when I close the connection?

Used dll:  OpcNetApi.dll, Version: 1.30.3.0

public void StopConnection()
{
      GroupRead.DataChanged -= DataChanged;
      GroupRead.Dispose();
      Server.Disconnect();
      Server.Dispose();
}

 

public Opc.Da.Server Server { get; set; } public Opc.Da.Subscription GroupRead { get; set; } public Result StartListening() { Result result = new Result(true); try { var surl = string.Format("opcda://{0}", MyOpcClientClass.ServerName); var url = new Opc.URL(surl); Server = new Opc.Da.Server(new OpcCom.Factory(), null); Server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential())); Server.ServerShutdown += ServerShutdown; var group = new Opc.Da.SubscriptionState(); group.Name = MyOpcClientClass.GroupName; group.UpdateRate = MyOpcClientClass.Period; group.Active = true; GroupRead = (Opc.Da.Subscription)Server.CreateSubscription(group); GroupRead.DataChanged += new Opc.Da.DataChangedEventHandler(DataChanged); var items = this.MyOpcClientClassFieldMappingList.Select(i => new Opc.Da.Item { ItemName = i.OpcTagName }).ToList(); GroupRead.AddItems(items.ToArray()); } catch (Exception e) { // error log } return result; } private void DataChanged(object subscriptionHandle, object requestHandle, Opc.Da.ItemValueResult[] values) { try { // do smth... } catch (Exception e) { // error log } }
Avatar
Frederick Loveless
Member
Members
Forum Posts: 20
Member Since:
10/02/2014
sp_UserOfflineSmall Offline
2
03/16/2018 - 09:05
sp_Permalink sp_Print

I would use wireshark, or rawcap for a local connection, to see what is going on between the server and the client. It sounds like the disconnect is failing or the server is not cleaning up properly.

Avatar
Okur Cozer
New Member
Members
Forum Posts: 2
Member Since:
03/15/2018
sp_UserOfflineSmall Offline
3
03/16/2018 - 12:39
sp_Permalink sp_Print sp_EditHistory

The problem with version 2.01.105.1 is fixed. I tested it with a matrikon on my local computer. It works fine.

but There is a problem in live production. I connect to the opc server and I can select the data. It works fine but I get an error The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) when I terminate the connection.

firewall off
The rpc service is running
dcom settings ok

what is the problem?

Avatar
mpoirier
New Member
Members
Forum Posts: 2
Member Since:
03/29/2018
sp_UserOfflineSmall Offline
4
03/29/2018 - 05:54
sp_Permalink sp_Print

Hi !

I am experiencing same kind of problem using OPCAuto.dll (2.0.4.60) "Matrikon OPC Automation 2.0" where when I Disconnect() the OPC instance stays alive for ~45 seconds before it disappears from the Task manager's processes' list...

This creates a problem (COM Error) if I try to Connect() before the instance is flushed from memory...

The app is C# with .NET 4.5.6 and everything else (Validate, Add, Read) is working just fine.

Is there a way from .NET to force the OPC instance to close immediately upon Disconnect() ?

Thanks !!!

Avatar
Frederick Loveless
Member
Members
Forum Posts: 20
Member Since:
10/02/2014
sp_UserOfflineSmall Offline
5
04/04/2018 - 08:38
sp_Permalink sp_Print

First you should get a new SDK. The Automation Wrapper has been deprecated and not supported for a long time. With that said once you disconnect from a server it will go through a clean up process. It will need to complete and close process threads and disconnect from devices. Also it needs to verify that the disconnecting client is the last one so that it does not pull itself out from under another client.

You should talk to the server manufacturer and find out what timing and other requirements it has when a client disconnects from it.

One last thing and if I am wrong Randy will correct me. I am fairly certain that the server is only required to shutdown after a disconnect if it was started by a client connection.

Avatar
mpoirier
New Member
Members
Forum Posts: 2
Member Since:
03/29/2018
sp_UserOfflineSmall Offline
6
04/11/2018 - 05:27
sp_Permalink sp_Print

Found the problem.

The Group's UpdateRate was set to 60 seconds (!) which caused the Disconnect to wait for the cycle end before closing.

Commented out the setting of parameter and problem solved...

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 24
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1435
Posts: 4855